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.

  • 相关阅读:
    作业 20181204-1 每周例行报告
    对团队成员公开感谢
    附加作业 软件工程原则的应用实例分析
    作业 20181127-2 每周例行报告
    作业 20181120-1 每周例行报告
    作业 20181113-2 每周例行报告
    作业 20181030-4 每周例行报告
    作业 20181023-3 每周例行报告
    SDWebImage的实现原理与底层结构拆解
    计算文件或者文件夹的大小用于计算下载速度或者是显示清除缓存大小
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/3621302.html
Copyright © 2011-2022 走看看