• 餐饮点菜控件


    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.

  • 相关阅读:
    NFC性价比高频读卡器首选方案:FM17550
    关于ESP8266和ESP8285的对比
    有没有比NRF51822更好的智能穿戴蓝牙方案
    zigbee CC2530首选方案模组:TZU06A1
    PAN3501兼容AS3933-BTST
    NRF51822和NRF52832的主要区别
    集成模拟温度传感器低成本2.4G CC2500RGPR 中文手册
    USB2.0主机控制器 UPD720114 简单详解
    存储器HK1225-7EQ 使用说明书资料
    爬虫 + 数据
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/3621302.html
Copyright © 2020-2023  润新知