forked from jaden/SnapTimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.pas
230 lines (200 loc) · 5.81 KB
/
settings.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
unit settings;
{$mode objfpc}{$H+}
interface
uses
SysUtils, LResources, Forms, Graphics, Dialogs, StdCtrls, ComCtrls, Spin;
type
{ TOptionsForm }
TOptionsForm = class(TForm)
BtnOk: TButton;
BtnCancel: TButton;
BtnDefaults: TButton;
CheckAutoRestart: TCheckBox;
CheckHideSeconds: TCheckBox;
CheckSecondsMode: TCheckBox;
CheckAutoSave: TCheckBox;
CheckAlwaysOnTop: TCheckBox;
CheckTicking: TCheckBox;
CheckLoopAudio: TCheckBox;
CheckClickTime: TCheckBox;
CheckDblClickTime: TCheckBox;
FontColor: TColorButton;
FontNameBtn: TButton;
CheckAutostart: TCheckBox;
CheckMinToTray: TCheckBox;
BgColor: TColorButton;
FontSize: TSpinEdit;
Label1: TLabel;
FontName: TStaticText;
LabelTextColor: TLabel;
LabelTextColor1: TLabel;
TimerFontBox: TGroupBox;
PositionCombo: TComboBox;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
NotifyAudio: TEdit;
NotifyAudioBtn: TButton;
NotifyAudioOn: TCheckBox;
NotifyAudioTest: TButton;
NotifyMsg: TEdit;
NotifyMsgOn: TCheckBox;
NotifyMsgTest: TButton;
NotifyRunApp: TEdit;
NotifyRunAppOn: TCheckBox;
NotifyRunBtn: TButton;
NotifyRunTest: TButton;
NotifyTrayMsg: TEdit;
NotifyTrayMsgOn: TCheckBox;
NotifyTrayMsgTest: TButton;
PageControl1: TPageControl;
GeneralTab: TTabSheet;
AlarmsTab: TTabSheet;
FontsTab: TTabSheet;
procedure ChooseFont(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: char);
procedure GetAudioFile(Sender: TObject);
procedure GetAppFile(Sender: TObject);
function GetFile(Orig: String; FilterStr: String; Dir : String): String;
procedure EnableFields(Sender: TObject);
procedure SetDefaults(Sender: TObject);
procedure TestAudio(Sender: TObject);
procedure TestMessage(Sender: TObject);
procedure TestRunApp(Sender: TObject);
procedure TestTrayMsg(Sender: TObject);
procedure UpdateFontColor(Sender: TObject);
procedure UpdateFonts(Sender: TObject);
procedure UpdateFontSize(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
OptionsForm: TOptionsForm;
f: TFont;
implementation
uses MainForm1;
{ TOptionsForm }
// TODO Move all text strings to the top
procedure TOptionsForm.GetAudioFile(Sender: TObject);
begin
NotifyAudio.Text := GetFile(NotifyAudio.Text, 'Wave files (*.wav)|*.wav', GetCurrentDir + '\sounds');
end;
procedure TOptionsForm.FormKeyPress(Sender: TObject; var Key: char);
begin
if key = #27 then Close;
end;
procedure TOptionsForm.ChooseFont(Sender: TObject);
var
dlg : TFontDialog;
begin
dlg := TFontDialog.Create(nil);
dlg.Font := f;
if dlg.Execute then
begin
f.Name := dlg.Font.Name;
f.Size := dlg.Font.Size;
// TODO Only set color if user changed it (XP dialog doesn't support custom colors)
// Works fine on Win7
//if not (f.Color = dlg.Font.Color) then f.Color:= dlg.Font.Color;
//f.Color:= dlg.Font.Color;
f.CharSet:= dlg.Font.CharSet;
f.Style:= dlg.Font.Style;
UpdateFonts(Sender);
end;
dlg.Free;
end;
procedure TOptionsForm.UpdateFonts(Sender: TObject);
begin
FontName.Caption := f.Name + ' : 1234567890';
FontName.Font.Name := f.Name;
FontName.Font.Color := f.Color;
FontName.Font.CharSet := f.CharSet;
FontName.Font.Style := f.Style;
FontName.Font.Quality:= fqAntialiased;
FontName.Font.Size := 18;
FontName.Color := BgColor.ButtonColor;
FontSize.Value := f.Size;
FontColor.ButtonColor := f.Color;
end;
procedure TOptionsForm.UpdateFontSize(Sender: TObject);
begin
f.Size := FontSize.Value;
UpdateFonts(Sender);
end;
procedure TOptionsForm.UpdateFontColor(Sender: TObject);
begin
f.Color := FontColor.ButtonColor;
UpdateFonts(Sender);
end;
procedure TOptionsForm.GetAppFile(Sender: TObject);
begin
NotifyRunApp.Text := GetFile(NotifyRunApp.Text, 'Executables (*.exe)|*.exe|All files (*.*)|*.*', GetCurrentDir);
end;
function TOptionsForm.GetFile(Orig: String; FilterStr: String; Dir : String): String;
var
dlg : TOpenDialog;
fname : String;
cwd : String;
relPath : String;
begin
dlg := TOpenDialog.Create(nil);
dlg.FileName := '';
if DirectoryExists(Dir)
then dlg.InitialDir := Dir
else dlg.InitialDir := GetCurrentDir;
dlg.Options := [ofFileMustExist];
dlg.Filter := FilterStr;
dlg.FilterIndex := 1;
if dlg.Execute then
begin
fname := dlg.FileName;
cwd := GetCurrentDir + '\';
relPath := ExtractRelativePath(cwd, ExtractFilePath(fname));
Result := '.\' + relPath + ExtractFileName(fname);
end else begin
Result := Orig;
end;
dlg.Free;
end;
procedure TOptionsForm.EnableFields(Sender: TObject);
begin
NotifyMsg.Enabled := NotifyMsgOn.Checked;
NotifyMsgTest.Enabled := NotifyMsgOn.Checked;
NotifyTrayMsg.Enabled := NotifyTrayMsgOn.Checked;
NotifyTrayMsgTest.Enabled := NotifyTrayMsgOn.Checked;
NotifyAudio.Enabled := NotifyAudioOn.Checked;
NotifyAudioBtn.Enabled := NotifyAudioOn.Checked;
NotifyAudioTest.Enabled := NotifyAudioOn.Checked;
NotifyRunApp.Enabled := NotifyRunAppOn.Checked;
NotifyRunBtn.Enabled := NotifyRunAppOn.Checked;
NotifyRunTest.Enabled := NotifyRunAppOn.Checked;
end;
procedure TOptionsForm.SetDefaults(Sender: TObject);
begin
(Self.Owner as TMainForm).SetDefaults(Self);
UpdateFonts(Sender);
end;
procedure TOptionsForm.TestAudio(Sender: TObject);
begin
with Self.Owner as TMainForm do
PlayAudio(NotifyAudio.Text, False);
end;
procedure TOptionsForm.TestMessage(Sender: TObject);
begin
with Self.Owner as TMainForm do
ShowDoneMessage(NotifyMsg.Text);
end;
procedure TOptionsForm.TestRunApp(Sender: TObject);
begin
with Self.Owner as TMainForm do
RunApp(NotifyRunApp.Text);
end;
procedure TOptionsForm.TestTrayMsg(Sender: TObject);
begin
with Self.Owner as TMainForm do
ShowTrayMessage(NotifyTrayMsg.Text);
end;
initialization
{$I settings.lrs}
end.