Advertisement
jpfassis

Accordion001 Delphi

Jul 7th, 2022
1,594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 4.31 KB | None | 0 0
  1. unit View.Components.Accordion001;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows,
  7.   Winapi.Messages,
  8.   System.SysUtils,
  9.   System.Variants,
  10.   System.Classes,
  11.   Vcl.Graphics,
  12.   Vcl.Controls,
  13.   Vcl.Forms,
  14.   Vcl.Dialogs,
  15.   Vcl.ExtCtrls,
  16.   Vcl.StdCtrls,
  17.   View.Components.Interfaces,
  18.   View.Components.Attributes.Interfaces,
  19.   View.Components.Attributes,
  20.   View.Styles.States,
  21.   View.Services.Utils,
  22.   UButtonColor;
  23.  
  24. type
  25.   TComponentAccordion001 = class(TForm, iComponents<TComponentAccordion001>)
  26.     Panel1: TPanel;
  27.     Panel2: TPanel;
  28.     Label1: TLabel;
  29.     Image1: TImage;
  30.     Panel3: TPanel;
  31.     Panel4: TPanel;
  32.     ColorButton1: TColorButton;
  33.     procedure FormCreate(Sender: TObject);
  34.     procedure ColorButton1MouseEnter(Sender: TObject);
  35.     procedure ColorButton1MouseLeave(Sender: TObject);
  36.     procedure ColorButton1Click(Sender: TObject);
  37.   private
  38.     { Private declarations }
  39.     FAttributes : iComponentAttributes<TComponentAccordion001>;
  40.     FAlign : TAlign;
  41.     FBackGround : TColor;
  42.     FButtonHeight : Integer;
  43.     FContainer : TWinControl;
  44.     FCountSubMenu : Integer;
  45.     FDestBackGround : TColor;
  46.     FFontSize : Integer;
  47.     FFontColor : TColor;
  48.     FImage : String;
  49.     FOnClick : TProc<TObject>;
  50.     FTitle : String;
  51.   public
  52.     { Public declarations }
  53.     function Component : TWinControl;
  54.     function Attributes : iComponentAttributes<TComponentAccordion001>;
  55.     function LoadAttributes (aValue : String) : TComponentAccordion001;
  56.     function Container (aValue : TWinControl) : iComponents<TComponentAccordion001>;
  57.     function AddSubMenu(aValue : TWinControl) : TComponentAccordion001;
  58.     function This : TComponentAccordion001;
  59.   end;
  60.  
  61. var
  62.   ComponentAccordion001: TComponentAccordion001;
  63.  
  64. implementation
  65.  
  66. {$R *.dfm}
  67.  
  68. { TComponentAccordion001 }
  69.  
  70. function TComponentAccordion001.AddSubMenu(
  71.   aValue: TWinControl): TComponentAccordion001;
  72. begin
  73.   Result := Self;
  74.   aValue.Parent:=Panel3;
  75.   Inc(FCountSubMenu);
  76.   TServiceUtils.ResourceImage('ico_keydown', Image1);
  77. end;
  78.  
  79. function TComponentAccordion001.Attributes: iComponentAttributes<TComponentAccordion001>;
  80. begin
  81.   Result := FAttributes;
  82. end;
  83.  
  84. procedure TComponentAccordion001.ColorButton1Click(Sender: TObject);
  85. begin
  86.   if Assigned(FOnclick) then
  87.     FOnClick(Sender);
  88.  
  89.   Panel1.Height:=FButtonHeight;
  90.  
  91.   if FCountSubMenu > 0 then
  92.   begin
  93.     if not Panel3.Visible then
  94.       Panel1.Height := FButtonHeight + (FCountSubMenu * FButtonHeight);
  95.  
  96.     Panel3.Visible := not Panel3.Visible;
  97.  
  98.     TServiceUtils.ResourceImage('ico_keydown', Image1);
  99.  
  100.     if Panel3.Visible then
  101.       TServiceUtils.ResourceImage('ico_keyup', Image1);
  102.   end;
  103. end;
  104.  
  105. procedure TComponentAccordion001.ColorButton1MouseEnter(Sender: TObject);
  106. begin
  107.   Panel1.Color := FAttributes.DestBackGround;
  108.   Image1.Visible:=True;
  109. end;
  110.  
  111. procedure TComponentAccordion001.ColorButton1MouseLeave(Sender: TObject);
  112. begin
  113.   Panel1.Color := FAttributes.BackGround;
  114.   if FCountSubMenu <=0 then
  115.     Image1.Visible:=False;
  116. end;
  117.  
  118. function TComponentAccordion001.Component: TWinControl;
  119. begin
  120.   Result := Panel1;
  121.   if Assigned(FContainer) then Panel1.Parent:=FContainer;
  122.  
  123.   Panel3.Visible:=False;
  124.   Panel1.Height := FButtonHeight;
  125.   Panel1.Align := FAttributes.Align;
  126.   Panel1.Color := FAttributes.BackGround;
  127.   Label1.Font.Color:=FAttributes.FontColor;
  128.   Label1.Caption:=FAttributes.Title;
  129.   Image1.Visible:=False;
  130.   Image1.Visible:=not (FCountSubMenu = 0);
  131.  
  132.   TServiceUtils.ResourceImage(FAttributes.Image, Image1);
  133. end;
  134.  
  135. function TComponentAccordion001.Container(
  136.   aValue: TWinControl): iComponents<TComponentAccordion001>;
  137. begin
  138.   Result := Self;
  139.   FContainer := aValue;
  140. end;
  141.  
  142. procedure TComponentAccordion001.FormCreate(Sender: TObject);
  143. begin
  144.   FAttributes := TComponentAttributes<TComponentAccordion001>.New(Self);
  145.   FButtonHeight := 60;
  146.   FCountSubMenu := 0;
  147. end;
  148.  
  149. function TComponentAccordion001.LoadAttributes(
  150.   aValue: String): TComponentAccordion001;
  151. var
  152.   FLoadAttributes : iComponentAttributes<TComponentAccordion001>;
  153. begin
  154.  
  155.  Result := Self;
  156.  FLoadAttributes := (StylesStates.GetStyle(aValue) as iComponentAttributes<TComponentAccordion001>);
  157.  
  158.  FAttributes := FLoadAttributes.Clone;
  159.  FAttributes.Parent(Self);
  160.  
  161. end;
  162.  
  163. function TComponentAccordion001.This: TComponentAccordion001;
  164. begin
  165.   Result := Self;
  166. end;
  167.  
  168. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement