zoukankan      html  css  js  c++  java
  • 餐饮点菜控件

    unit untFoodCard;

    interface

    uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
    System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, RzPanel,
    rzcommon;

    const
    c_default_color = clSilver;
    c_default_font_color = clNavy;
    c_selected_color = clOlive;
    c_selected_font_color = clNavy;
    c_font_size = 10;

    type
    TFoodCard = class(TRzPanel)
    private
    FPrice, FQty: TLabel;
    FData: Integer;
    procedure MouseDown(Sender: TObject; Button: TMouseButton;
    Shift: TShiftState; X, Y: Integer);
    procedure MouseUp(Sender: TObject; Button: TMouseButton;
    Shift: TShiftState; X, Y: Integer);
    procedure MouseEnter(Sender: TObject);
    procedure MousseLeave(Sender: TObject);
    procedure LabelClick(Sender: TObject);
    procedure SetPrice(Value: string);
    function GetPrice: string;
    procedure SetQty(Value: string);
    function GetQty: string;
    procedure SetCardColor(Value: TColor);
    function GetCardColor: TColor;
    public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;

    procedure SetDefaultFont;
    procedure SetEnableFalse;
    published
    property Qty: string read GetQty write SetQty;
    property Price: string read GetPrice write SetPrice;
    property Data: Integer read FData write FData;
    property CardColor: TColor read GetCardColor write SetCardColor;
    end;

    procedure Register;

    implementation

    procedure Register;
    begin
    RegisterComponents('FoodCard', [TFoodCard]);
    end;

    { TFoodCard }

    constructor TFoodCard.Create(AOwner: TComponent);
    begin
    inherited;
    // panel
    Width := 83;
    Height := 68;
    BorderOuter := fsFlatRounded;
    GradientColorStyle := gcsCustom;
    GradientColorStop := c_default_color;
    GradientDirection := gdDiagonalDown;
    VisualStyle := vsGradient;
    Font.Size := c_font_size;
    Font.Color := c_default_font_color;
    OnMouseDown := MouseDown;
    OnMouseUp := MouseUp;
    OnMouseEnter := MouseEnter;
    OnMouseLeave := MousseLeave;
    DoubleBuffered := True;
    // qty
    FQty := TLabel.Create(self);
    FQty.Parent := self;
    FQty.Align := alTop;
    FQty.Font.Size := 8;
    FQty.Font.Color := clBlue;
    FQty.OnMouseDown := MouseDown;
    FQty.OnMouseUp := MouseUp;
    FQty.OnClick := LabelClick;
    // price
    FPrice := TLabel.Create(self);
    FPrice.Parent := self;
    FPrice.Align := alBottom;
    FPrice.Alignment := taRightJustify;
    FPrice.Font.Color := clBlue;
    FPrice.Font.Size := 8;
    FPrice.OnMouseDown := MouseDown;
    FPrice.OnMouseUp := MouseUp;
    FPrice.OnClick := LabelClick;
    end;

    destructor TFoodCard.Destroy;
    begin
    if Assigned(FPrice) then
    FPrice.Free;
    if Assigned(FQty) then
    FQty.Free;
    inherited;
    end;

    function TFoodCard.GetCardColor: TColor;
    begin
    Result := GradientColorStop;
    end;

    function TFoodCard.GetPrice: string;
    begin
    Result := FPrice.Caption;
    end;

    function TFoodCard.GetQty: string;
    begin
    Result := FQty.Caption;
    end;

    procedure TFoodCard.LabelClick(Sender: TObject);
    begin
    Self.Click;
    end;

    procedure TFoodCard.MouseDown(Sender: TObject; Button: TMouseButton;
    Shift: TShiftState; X, Y: Integer);
    begin
    if Button = mbLeft then begin
    BorderOuter := fsLowered;
    end;
    end;

    procedure TFoodCard.MouseEnter(Sender: TObject);
    begin
    GradientDirection := gdHorizontalCenter;
    end;

    procedure TFoodCard.MouseUp(Sender: TObject; Button: TMouseButton;
    Shift: TShiftState; X, Y: Integer);
    begin
    if Button = mbLeft then begin
    BorderOuter := fsFlatRounded;
    GradientColorStop := c_selected_color;
    Font.Color := c_selected_font_color;
    end;
    end;

    procedure TFoodCard.MousseLeave(Sender: TObject);
    begin
    GradientDirection := gdDiagonalDown;
    end;

    procedure TFoodCard.SetCardColor(Value: TColor);
    begin
    if GradientColorStop <> Value then
    GradientColorStop := Value;
    end;

    procedure TFoodCard.SetDefaultFont;
    begin
    Font.Color := clNavy;
    GradientColorStop := clSilver;
    end;

    procedure TFoodCard.SetEnableFalse;
    begin
    OnMouseDown := nil;
    OnMouseUp := nil;
    OnMouseEnter := nil;
    OnMouseLeave := nil;
    OnClick := nil;
    FQty.OnClick := nil;
    FQty.OnMouseDown := nil;
    FQty.OnMouseUp := nil;
    FPrice.OnClick := nil;
    FPrice.OnMouseDown := nil;
    FPrice.OnMouseUp := nil;
    end;

    procedure TFoodCard.SetPrice(Value: string);
    begin
    if FPrice.Caption <> Value then
    FPrice.Caption := Value;
    end;

    procedure TFoodCard.SetQty(Value: string);
    begin
    if FQty.Caption <> Value then
    FQty.Caption := Value;
    end;

    end.

  • 相关阅读:
    leetcode 第 44 场双周赛 1 1734. 解码异或后的排列 C
    leetcode 第 44 场双周赛 1 1732. 找到最高海拔 C
    2014浙江省赛 ZOJ
    2018沈阳区域赛现场赛 Gym
    山东省ACM多校联盟省赛个人训练第六场 poj 3335 D Rotating Scoreboard
    Minieye杯第十五届华中科技大学程序设计邀请赛现场同步赛 I Matrix Again
    计算机爱好者协会技术贴markdown第四期
    计算机爱好者协会技术贴markdown第三期
    摇骰子
    PAT 1003 dijkstra
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/3621302.html
Copyright © 2011-2022 走看看