forked from HemulGM/TaskBoardsFMX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskBoard.View.Column.pas
195 lines (174 loc) · 5.54 KB
/
TaskBoard.View.Column.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
unit TaskBoard.View.Column;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
FMX.Layouts, FMX.Controls.Presentation, FMX.Objects, FMX.Memo.Types,
FMX.ScrollBox, FMX.Memo;
type
TFrameColumn = class(TFrame)
VertScrollBoxItems: TVertScrollBox;
LayoutContent: TLayout;
LayoutHead: TLayout;
RectangleBG: TRectangle;
LabelTitle: TLabel;
LayoutDropCard: TLayout;
Rectangle1: TRectangle;
LayoutFooter: TLayout;
ButtonAdd: TButton;
TimerScroll: TTimer;
procedure VertScrollBoxItemsDragOver(Sender: TObject; const Data: TDragObject; const Point: TPointF; var Operation: TDragOperation);
procedure VertScrollBoxItemsDragDrop(Sender: TObject; const Data: TDragObject; const Point: TPointF);
procedure VertScrollBoxItemsCalcContentBounds(Sender: TObject; var ContentBounds: TRectF);
procedure VertScrollBoxItemsDragEnd(Sender: TObject);
procedure VertScrollBoxItemsDragLeave(Sender: TObject);
procedure FrameResize(Sender: TObject);
procedure TimerScrollTimer(Sender: TObject);
private
procedure ShowDropCard(Position: TPointF; Height: Single);
procedure HideDropCard;
procedure CheckScroll;
procedure StopScroll;
protected
procedure BeginAutoDrag; override;
public
constructor Create(AOwner: TComponent); override;
end;
implementation
uses
System.Math, TaskBoard.View.Card;
{$R *.fmx}
constructor TFrameColumn.Create(AOwner: TComponent);
begin
inherited;
VertScrollBoxItems.AniCalculations.Animation := True;
end;
procedure TFrameColumn.FrameResize(Sender: TObject);
begin
var H: Single := 0;
for var Control in VertScrollBoxItems.Content.Controls do
if Control.IsVisible then
H := Max(H, Control.Position.Y + Control.Height + Control.Margins.Bottom);
H := Max(5, H) + LayoutHead.Height + LayoutFooter.Height + LayoutContent.Padding.Bottom + LayoutContent.Padding.Top;
H := Round(Max(Min(Height, H), 100));
if LayoutContent.Height <> H then
LayoutContent.Height := H;
end;
procedure TFrameColumn.HideDropCard;
begin
StopScroll;
LayoutDropCard.Visible := False;
LayoutDropCard.Align := TAlignLayout.None;
end;
procedure TFrameColumn.BeginAutoDrag;
const
DraggingOpacity = 1;
var
B, S: TBitmap;
R: TRectF;
begin
if Root <> nil then
begin
S := MakeScreenshot;
S.Rotate(5);
try
B := nil;
try
if (S.Width > 512) or (S.Height > 512) then
begin
R := TRectF.Create(0, 0, S.Width, S.Height);
R.Fit(TRectF.Create(0, 0, 512, 512));
B := TBitmap.Create(Round(R.Width), Round(R.Height));
B.Clear(0);
if B.Canvas.BeginScene then
try
B.Canvas.DrawBitmap(S, TRectF.Create(0, 0, S.Width, S.Height), TRectF.Create(0, 0, B.Width, B.Height),
DraggingOpacity, False);
finally
B.Canvas.EndScene;
end;
end
else
begin
B := TBitmap.Create(S.Width, S.Height);
B.Clear(0);
if B.Canvas.BeginScene then
try
B.Canvas.DrawBitmap(S, TRectF.Create(0, 0, B.Width, B.Height), TRectF.Create(0, 0, B.Width, B.Height),
DraggingOpacity, False);
finally
B.Canvas.EndScene;
end;
end;
Root.BeginInternalDrag(Self, B);
finally
B.Free;
end;
finally
S.Free;
end;
end;
end;
procedure TFrameColumn.ShowDropCard(Position: TPointF; Height: Single);
begin
LayoutDropCard.Position.Y := Position.Y - Height / 2 + VertScrollBoxItems.ViewportPosition.Y;
LayoutDropCard.Height := Height;
LayoutDropCard.Align := TAlignLayout.Top;
LayoutDropCard.Visible := True;
CheckScroll;
end;
procedure TFrameColumn.VertScrollBoxItemsCalcContentBounds(Sender: TObject; var ContentBounds: TRectF);
begin
FrameResize(nil);
end;
procedure TFrameColumn.VertScrollBoxItemsDragDrop(Sender: TObject; const Data: TDragObject; const Point: TPointF);
begin
if Data.Source is TFrameCard then
begin
TFrameCard(Data.Source).Parent := VertScrollBoxItems;
TFrameCard(Data.Source).Visible := True;
TFrameCard(Data.Source).Position.Y := LayoutDropCard.Position.Y;
TFrameCard(Data.Source).ChangedParent;
end;
HideDropCard;
end;
procedure TFrameColumn.VertScrollBoxItemsDragEnd(Sender: TObject);
begin
HideDropCard;
end;
procedure TFrameColumn.VertScrollBoxItemsDragLeave(Sender: TObject);
begin
HideDropCard;
end;
procedure TFrameColumn.StopScroll;
begin
TimerScroll.Enabled := False;
end;
procedure TFrameColumn.TimerScrollTimer(Sender: TObject);
begin
var MPos := VertScrollBoxItems.AbsoluteToLocal(Application.MainForm.ScreenToClient(Screen.MousePos));
if MPos.Y > VertScrollBoxItems.Height - 40 then
begin
VertScrollBoxItems.ViewportPosition := VertScrollBoxItems.ViewportPosition + TPointF.Create(0, 5);
end
else if MPos.Y < 40 then
begin
VertScrollBoxItems.ViewportPosition := VertScrollBoxItems.ViewportPosition + TPointF.Create(0, -5);
end
else
StopScroll;
end;
procedure TFrameColumn.CheckScroll;
begin
TimerScroll.Enabled := True;
end;
procedure TFrameColumn.VertScrollBoxItemsDragOver(Sender: TObject; const Data: TDragObject; const Point: TPointF; var Operation: TDragOperation);
begin
if Data.Source is TFrameCard then
begin
Operation := TDragOperation.Move;
var Card := TFrameCard(Data.Source);
ShowDropCard(VertScrollBoxItems.AbsoluteToLocal(Application.MainForm.ScreenToClient(Screen.MousePos)), Card.Height);
end;
end;
end.