forked from HuichanKIM/Ollama-Delphi-GUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Unit_About.pas
363 lines (322 loc) · 12.1 KB
/
Unit_About.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
unit Unit_About;
interface
uses
System.SysUtils,
System.Variants,
System.Classes,
Winapi.Windows,
Winapi.Messages,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls,
Vcl.ExtCtrls,
Vcl.Imaging.pngimage,
Vcl.ComCtrls,
Vcl.Buttons;
type
TForm_About = class(TForm)
Panel1: TPanel;
Button_OK: TButton;
Panel3: TPanel;
Label_Title: TLabel;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
Label_Development: TLabel;
ListView_Shortcuts: TListView;
TabSheet3: TTabSheet;
Label_SystemInfo: TLabel;
Label_GitHub: TLabel;
Label1: TLabel;
TabSheet_Style: TTabSheet;
Label2: TLabel;
ComboBox_VclStyles: TComboBox;
GroupBox2: TGroupBox;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Shape_Header: TShape;
Shape_Body: TShape;
Shape_Footer: TShape;
SpeedButton_Header: TSpeedButton;
SpeedButton_Body: TSpeedButton;
SpeedButton_Footer: TSpeedButton;
Label8: TLabel;
Shape_Selection: TShape;
SpeedButton_Selection: TSpeedButton;
Label_Header: TLabel;
Label_Body: TLabel;
Label_Footer: TLabel;
Label9: TLabel;
SpeedButton_DefaultColor: TSpeedButton;
SpeedButton_CancelColors: TSpeedButton;
SpeedButton_ApplyColors: TSpeedButton;
SpeedButton_ApplySkin: TSpeedButton;
Panel2: TPanel;
Image1: TImage;
GroupBox1: TGroupBox;
Label3: TLabel;
Label_OllamaWeb: TLabel;
Label7: TLabel;
Label_OllamaGitHub: TLabel;
GroupBox3: TGroupBox;
CheckBox_BeepSound: TCheckBox;
ColorDialog_Colors: TColorDialog;
CheckBox_SaveOnCLose: TCheckBox;
CheckBox_NoCheckAlive: TCheckBox;
Label10: TLabel;
Label11: TLabel;
ComboBox_MRUROOT_Max: TComboBox;
ComboBox_MRUCHILD_Max: TComboBox;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure Label_SystemInfoClick(Sender: TObject);
procedure Label_GitHubClick(Sender: TObject);
procedure SpeedButton_HeaderClick(Sender: TObject);
procedure SpeedButton_DefaultColorClick(Sender: TObject);
procedure SpeedButton_ApplySkinClick(Sender: TObject);
procedure SpeedButton_CancelColorsClick(Sender: TObject);
procedure SpeedButton_ApplyColorsClick(Sender: TObject);
procedure CheckBox_BeepSoundClick(Sender: TObject);
procedure CheckBox_SaveOnCLoseClick(Sender: TObject);
procedure CheckBox_NoCheckAliveClick(Sender: TObject);
procedure ComboBox_MRUCHILD_MaxChange(Sender: TObject);
procedure ComboBox_MRUROOT_MaxChange(Sender: TObject);
private
FShow_Flag: Integer;
FUpdateLockFlag: Boolean;
procedure Update_Shortcuts;
procedure StylesList_Refresh;
public
property Show_Flag: Integer read FShow_Flag write FShow_Flag;
end;
function Get_HelpShortcuts(): string;
implementation
uses
System.UITypes,
Vcl.Themes,
Vcl.Styles,
Vcl.StyleAPI,
Winapi.ShellAPI,
Unit_Main,
Unit_Common,
Unit_DMServer;
{$R *.dfm}
const
C_Shortcut_Keys: array [0..26] of string = ('F1','F2','F3','F4','F5',
'F6','F7','F8','F9','F10',
'Alt+A','Alt+B','Alt+C','Alt+D','Alt+E',
'Alt+G','Alt+H','Alt+L','Alt+P','Alt+Q','Alt+S',
'Alt+T','Alt+V','Alt+W',
'Ctrl+A','Ctrl+R','Ctrl+Z');
C_Shortcut_Desc: array [0..26] of string = ('Show Request Dialog','Send Request','Goto Welcome.','Goto Chatting Room','Translation of Prompt',
'Translation of Message','(Reserved)','(Reserved)','(Reserved)','Clear Chattings',
'Ollama Alive ?','Scroll to Bottom','Copy the Message.','Delete the Message.','Skin / Colors',
'Load Image (llava)','Help - ShortCuts','Show Logs.','Show/Hide Option Panel','TTS Control View','Save All Messages to Text File',
'Scroll to Top','TextToSpeech on Message','Show About',
'Abort Connection.','Default / Refresh','Close / Exit.');
// CodeInsight Bug ? - When use ''' (multi line string), raise error with "International UTF8-Char" ...
C_DevelopInfo: string =
'Development Tool (GUI)'+#13#10+
'Embarcadero Delphi 12.1 ( Object Pascal )'+#13#10#13#10+
' 3rd party Reference Library (* open source)'+#13#10+
' - Virtual-TreeView by JAM-Software (*)'+#13#10+
' - SVGIconImageList v 4.1.4 by Ethea S.r.l. (*)'+#13#10+
' - FastMM4-AVX by Maxim Masiutin (*)'+#13#10+
' - Embeded Lib. : SKIA 2D Graphics'+ #13#10+
' - SpeechLibrary by MS SAPI'+#13#10+#13#10+
'Support Multilingual Translation / Voice'+#13#10#13#10+
GC_CopyRights;
{ ... }
function Get_HelpShortcuts(): string;
begin
var _list := TStringList.Create;
try
_list.Add('* Shortcuts -------------------------' + #13#10);
for var _i := 0 to Length(C_Shortcut_Keys) - 1 do
with _list do
begin
Add(C_Shortcut_Keys[_i] + ' - ' + C_Shortcut_Desc[_i]);
end;
Result := _list.Text;
finally
_list.free;
end;
end;
{ TForm_About. }
procedure TForm_About.CheckBox_BeepSoundClick(Sender: TObject);
begin
if not FUpdateLockFlag then
Form_RestOllama.DoneSoundFlag := CheckBox_BeepSound.Checked;
end;
procedure TForm_About.CheckBox_NoCheckAliveClick(Sender: TObject);
begin
if not FUpdateLockFlag then
GV_CheckingAliveStart := not CheckBox_NoCheckAlive.Checked;
end;
procedure TForm_About.CheckBox_SaveOnCLoseClick(Sender: TObject);
begin
if not FUpdateLockFlag then
Form_RestOllama.SaveLogsOnCLoseFlag := CheckBox_SaveOnCLose.Checked;
end;
const
C_MRUMAX: array [0..8] of Integer = (10,15,20,25,30,35,40,45,50);
procedure TForm_About.ComboBox_MRUROOT_MaxChange(Sender: TObject);
begin
if not FUpdateLockFlag then
if ComboBox_MRUROOT_Max.ItemIndex >= 0 then
MRU_MAX_ROOT := C_MRUMAX[ComboBox_MRUROOT_Max.ItemIndex];
end;
procedure TForm_About.ComboBox_MRUCHILD_MaxChange(Sender: TObject);
begin
if not FUpdateLockFlag then
if ComboBox_MRUCHILD_Max.ItemIndex >= 0 then
MRU_MAX_CHILD := C_MRUMAX[ComboBox_MRUCHILD_Max.ItemIndex];
end;
procedure TForm_About.FormCreate(Sender: TObject);
begin
FShow_Flag := 0;
StylesList_Refresh;
Label_Title.Caption := GC_MainCaption1;
if TStyleManager.IsCustomStyleActive then
begin
ListView_Shortcuts.StyleElements := [seBorder];
ListView_Shortcuts.Color := StyleServices.GetStyleColor(scWindow);
end;
FUpdateLockFlag := False;
Label_Development.Caption := C_DevelopInfo;
Label_SystemInfo.Caption := Get_SystemInfo();
if DM_ACTIVATECODE = 1 then
begin
Label_SystemInfo.Caption := Label_SystemInfo.Caption+GC_CRLF+GC_CRLF+
' Local IP : '+ DM_LocalIP +GC_CRLF+
' Public IP : '+ DM_PublicIP +GC_CRLF+
' Port : '+IntToStr(DM_Port);
end;
Update_Shortcuts();
end;
procedure TForm_About.FormShow(Sender: TObject);
const
c_Caption: array [0..3] of string = ('About','','','Skin / Colors / Options');
begin
Self.Caption := c_Caption[FShow_Flag];
var _color0, _color1, _color2, _color3: TColor;
_color0 := Form_RestOllama.Frame_ChattingBox.Get_CustomColor(_color1, _color2, _color3);
Shape_Selection.Brush.Color := _color0;
Shape_Header.Brush.Color := _color1;
Shape_Body.Brush.Color := _color2;
Shape_Footer.Brush.Color := _color3;
Label_Header.Font.Color := _color1;
Label_Body.Font.Color := _color2;
Label_Footer.Font.Color := _color3;
FUpdateLockFlag := True;
ComboBox_MRUROOT_Max.ItemIndex := (MRU_MAX_ROOT div 5) -2;
ComboBox_MRUCHILD_Max.ItemIndex := (MRU_MAX_CHILD div 5) -2;
CheckBox_NoCheckAlive.Checked := not GV_CheckingAliveStart;
CheckBox_BeepSound.Checked := Form_RestOllama.DoneSoundFlag;
CheckBox_SaveOnCLose.Checked := Form_RestOllama.SaveLogsOnCLoseFlag;
FUpdateLockFlag := False;
TabSheet_Style.TabVisible := FShow_Flag = GC_AboutSkinFlag; // Cannot Focus Error - When Change Style Event / Bug ?
PageControl1.ActivePageIndex := FShow_Flag; // 0 or 3
end;
procedure TForm_About.Update_Shortcuts();
begin
ListView_Shortcuts.items.Clear;
for var _i := 0 to Length(C_Shortcut_Keys)-1 do
with ListView_Shortcuts.Items.Add do
begin
Caption := C_Shortcut_Keys[_i];
SubItems.Add(C_Shortcut_Desc[_i]);
end;
end;
procedure TForm_About.FormKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #27 then
begin
Key := #0;
ModalResult := mrCancel;
end;
end;
procedure TForm_About.Label_GitHubClick(Sender: TObject);
var
_LabelSender: TLabel absolute Sender;
begin
var _addr := _LabelSender.Caption;
ShellExecute(0, PChar('Open'), PChar(_addr), nil, nil, SW_SHOW);
end;
procedure TForm_About.Label_SystemInfoClick(Sender: TObject);
begin
Label_SystemInfo.Caption := Get_SystemInfo();
end;
{ Vcl Styles ... }
procedure TForm_About.StylesList_Refresh;
begin
ComboBox_VclStyles.Items.Clear;
for var _stylename in TStyleManager.StyleNames do
begin
if not SameText('Windows', _stylename) then
ComboBox_VclStyles.Items.Add(_stylename);
end;
var _default := TStyleManager.ActiveStyle.Name;
var _index := ComboBox_VclStyles.Items.IndexOf(_default);
if _index >= 0 then
ComboBox_VclStyles.ItemIndex := _index;
end;
procedure TForm_About.SpeedButton_ApplyColorsClick(Sender: TObject);
begin
Form_RestOllama.Frame_ChattingBox.Do_SetCustomColor(1,
Shape_Selection.Brush.Color,
Shape_Header.Brush.Color,
Shape_Body.Brush.Color,
Shape_Footer.Brush.Color);
SpeedButton_CancelColors.Enabled := True;
end;
procedure TForm_About.SpeedButton_ApplySkinClick(Sender: TObject);
begin
var _style := ComboBox_VclStyles.Items[ComboBox_VclStyles.ItemIndex];
if not SameText(_style, TStyleManager.ActiveStyle.Name) then
begin
TStyleManager.TrySetStyle(_style);
Application.ProcessMessages;
Form_RestOllama.Do_ChangeStyleCustom(1);
end;
if Button_OK.CanFocus then
Button_OK.Setfocus;
end;
procedure TForm_About.SpeedButton_CancelColorsClick(Sender: TObject);
begin
Form_RestOllama.Frame_ChattingBox.Do_SetCustomColor(2,
GV_ReservedColor[0],
GV_ReservedColor[1],
GV_ReservedColor[2],
GV_ReservedColor[3]);
Shape_Selection.Brush.Color := GV_ReservedColor[0];
Shape_Header.Brush.Color := GV_ReservedColor[1]; Label_Header.Font.Color := GV_ReservedColor[1];
Shape_Body.Brush.Color := GV_ReservedColor[2]; Label_Body.Font.Color := GV_ReservedColor[2];
Shape_Footer.Brush.Color := GV_ReservedColor[3]; Label_Footer.Font.Color := GV_ReservedColor[3];
end;
procedure TForm_About.SpeedButton_DefaultColorClick(Sender: TObject);
begin
Shape_Selection.Brush.Color := GC_SkinSelColor;
Shape_Header.Brush.Color := GC_SkinHeadColor; Label_Header.Font.Color := GC_SkinHeadColor;
Shape_Body.Brush.Color := GC_SkinBodyColor; Label_Body.Font.Color := GC_SkinBodyColor;
Shape_Footer.Brush.Color := GC_SkinFootColor; Label_Footer.Font.Color := GC_SkinFootColor;
end;
procedure TForm_About.SpeedButton_HeaderClick(Sender: TObject);
begin
with ColorDialog_Colors do
begin
Color := GV_ReservedColor[TSpeedButton(Sender).Tag];
if Execute() then
case TSpeedButton(Sender).Tag of
0: begin Shape_Selection.Brush.Color := Color; end;
1: begin Shape_Header.Brush.Color := Color; Label_Header.Font.Color := Color; end;
2: begin Shape_Body.Brush.Color := Color; Label_Body.Font.Color := Color; end;
3: begin Shape_Footer.Brush.Color := Color; Label_Footer.Font.Color := Color; end;
end;
end;
end;
end.