餐饮点菜控件
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.
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/p/3621302.html