File: configdlg.pas

package info (click to toggle)
vmg 3.8.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,528 kB
  • sloc: pascal: 5,160; cpp: 605; sh: 278; lex: 105; ansic: 68; makefile: 37
file content (467 lines) | stat: -rw-r--r-- 11,073 bytes parent folder | download
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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
{
configdlg.pas

Configurations Dialog

Copyright (C) 1998 - 2010 Harri Pyy, Chris O'Donnell, Felipe Monteiro de Carvalho

This file is part of Virtual Magnifying Glass.

Virtual Magnifying Glass is free software;
you can redistribute it and/or modify it under the
terms of the GNU General Public License version 2
as published by the Free Software Foundation.

Virtual Magnifying Glass is distributed in the hope
that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU General Public License for more details.

Please note that the General Public License version 2 does not permit
incorporating Virtual Magnifying Glass into proprietary
programs.

AUTHORS: Chris O'Donnell, Felipe Monteiro de Carvalho and Harri Pyy
}
unit configdlg;

{$IFDEF FPC}
  {$MODE DELPHI}{$H+}
{$ENDIF}

interface

uses SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
 ComCtrls, ExtCtrls, StdCtrls, Buttons, appsettings, constants,
 plugininfo;

type

  { TConfigDialog }

  TConfigDialog = class(TForm)
  private
    { Private declarations }
    pgsCategories: TPageControl;
    lblDisabledHint: TLabel;
    { General tab }
    tabGeneral: TTabSheet;
    chkAutoRun: TCheckBox;
    chkShowWhenExecuted: TCheckBox;
    { Plugins tab }
    tabPlugins: TTabSheet;
    stPluginsList: TStaticText;
    lstPluginsList: TListBox;
    { HotKey tab }
    tabHotKey: TTabSheet;
    rgrpHotKeyInvoke: TRadioGroup;
    lblHotKeyKey: TLabel;
    txtHotKeyKey: TEdit;
    { Image tab }
    tabImage: TTabSheet;
    lblContrast: TLabel;
    lblContrastInfo: TLabel;
    sliderContrast: TTrackBar;
    rgrpAntialiasing: TRadioGroup;
    { Others }
    btnClose: TButton;
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  public
    { Public declarations }
    procedure UpdateInterface;
    procedure SaveConfigurations;
    constructor Create(AOwner: TComponent); override;
  end;

var
  vConfigDialog: TConfigDialog;

implementation

uses
  glass, translationsvmg, app
{$ifdef fpc}
  , LResources
{$endif}
 ;

{$ifndef fpc}
  {$R *.DFM}
{$endif}

{ TConfigDialog }

{*******************************************************************}
{@@
  Allocates and initializes the configurations dialog.

  Obs: The captions are set here too because of a
  possible Lazarus bug:

  The labels of the PageControl don't show on the first
  time the form is shown if set only on OnShow, using
  Lazarus on win32.
}
{*******************************************************************}
constructor TConfigDialog.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

  Position := poScreenCenter;
  Height := 500;
  Width := 500;

  OnShow := FormShow;
  OnClose := FormClose;

  Self.VertScrollBar.Visible := False;
  Self.HorzScrollBar.Visible := False;

  pgsCategories := TPageControl.Create(Self);
  with pgsCategories do
  begin
    Parent := Self;
    Height := 375;
    Left := 25;
    Top := 25;
    Width := 450;
    TabOrder := 0;
    Anchors := [akLeft, akRight, akTop];
  end;

  { General tab }

  tabGeneral := TTabSheet.Create(Self);
  tabGeneral.PageControl := pgsCategories;
  tabGeneral.Caption := vTranslations.lpTabGeneral;

  chkAutoRun := TCheckBox.Create(Self);
  with chkAutoRun do
  begin
    Parent := tabGeneral;
    Top := 10;
    Left := 10;
    Width := 400;
  end;

  chkShowWhenExecuted := TCheckBox.Create(Self);
  with chkShowWhenExecuted do
  begin
    Parent := tabGeneral;
    Top := 35;
    Left := 10;
    Width := 400;
  end;

  { Plugins tab }

  tabPlugins := TTabSheet.Create(Self);
  {$ifdef USE_PLUGINS}
  tabPlugins.PageControl := pgsCategories;
  {$endif}
  tabPlugins.Caption := vTranslations.lpTabPlugins;

  stPluginsList := TStaticText.Create(Self);
  with stPluginsList do
  begin
    Parent := tabPlugins;
    Top := 10;
    Left := 10;
    Width := 400;
  end;

  lstPluginsList := TListBox.Create(Self);
  with lstPluginsList do
  begin
    Parent := tabPlugins;
    Top := 35;
    Left := 10;
    Height := 200;
    Width := 400;
    MultiSelect := False;
  end;

  { HotKey tab }

  tabHotKey := TTabSheet.Create(Self);
  tabHotKey.PageControl := pgsCategories;
  tabHotKey.Caption := vTranslations.lpTabHotKey;

  lblHotKeyKey := TLabel.Create(Self);
  with lblHotKeyKey do
  begin
    Parent := tabHotKey;
    Top := 10;
    Left := 10;
    AutoSize := True;
    Caption := vTranslations.lpHotKeyKey;
  end;

  txtHotKeyKey := TEdit.Create(Self);
  with txtHotKeyKey do
  begin
    Parent := tabHotKey;
    Top := 30;
    Left := 10;
    Width := 50;
    MaxLength := 1;
  end;

  rgrpHotKeyInvoke := TRadioGroup.Create(Self);
  with rgrpHotKeyInvoke do
  begin
    Parent := tabHotKey;
    Top := 60;
    Left := 10;
    Height := 100;
    Width := 400;
    Caption := vTranslations.lpHotKeyInvoke;
    Items.Add(vTranslations.lpHotKeyDisableInvoke);
    Items.Add(vTranslations.lpHotKeyCtrlAltKey);
    Items.Add(vTranslations.lpHotKeyDisableAll);
    ItemIndex := 0;
  end;

    { Image tab }

  tabImage := TTabSheet.Create(Self);
  tabImage.PageControl := pgsCategories;
  tabImage.Caption := 'Image';

  lblContrast := TLabel.Create(Self);
  with lblContrast do
  begin
    Parent := tabImage;
    Top := 10;
    Left := 10;
    AutoSize := True;
    Caption := 'Contrast';
  end;

  sliderContrast := TTrackBar.Create(Self);
  with sliderContrast do
  begin
    Parent := tabImage;
    Top := 30;
    Left := 10;
    Width := 250;
    Frequency := 1;
    Min := 0;
    Max := 127;
  end;

  lblContrastInfo := TLabel.Create(Self);
  with lblContrastInfo do
  begin
    Parent := tabImage;
    Top := 85;
    Left := 10;
    Height := 100;
    Width := 400;
    Caption := 'Hint - You can use these keys while moving the glass' + sLineBreak
    + 'to adjust contrast: X to increase, Z to decrease, C to reset';
  end;

  rgrpAntialiasing := TRadioGroup.Create(Self);
  with rgrpAntialiasing do
  begin
    Parent := tabImage;
    Top := 175;
    Left := 10;
    Height := 100;
    Width := 400;
    Caption := 'Anti-aliasing';
    Items.Add('Simple');
    Items.Add('Extra - Higher CPU usage');
    ItemIndex := 0;
  end;

  { Others }

  lblDisabledHint := TLabel.Create(Self);
  with lblDisabledHint do
  begin
    Parent := Self;
    Left := 25;
    Top := 405;
    AutoSize := True;
    Caption := vTranslations.lpDisabledHint;
  end;

  btnClose := TButton.Create(Self);
  with btnClose do
  begin
    Parent := Self;
    Height := 33;
    Left := 150;
    Top := 433;
    Width := 200;
    ModalResult := mrOK;
    TabOrder := 0;
    Anchors := [akLeft, akRight, akTop];
  end;

  ActiveControl := btnClose;
end;

{*******************************************************************}
{@@
  Updates the dialog every time it is shown
}
{*******************************************************************}
procedure TConfigDialog.FormShow(Sender: TObject);
begin
  UpdateInterface;
end;

{*******************************************************************}
{@@
  Updates the configurations every time the dialog closes
}
{*******************************************************************}
procedure TConfigDialog.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  SaveConfigurations;
end;

{*******************************************************************}
{@@
  Call this method to update the interface according
  to the current vConfigurations state and the
  current translation
}
{*******************************************************************}
procedure TConfigDialog.UpdateInterface;
var
  SR: TSearchRec;
  i: Integer;
begin
  {*******************************************************************
  *  Updates the translations
  *******************************************************************}

  Caption := vTranslations.lpConfigDialogTitle;

  { General tab }

  tabGeneral.Caption := vTranslations.lpTabGeneral;
  chkAutoRun.Caption := vTranslations.lpAutoRun;
  chkShowWhenExecuted.Caption := vTranslations.lpShowWhenExecuted;

  { Plugins tab }

  tabPlugins.Caption := vTranslations.lpTabPlugins;
  stPluginsList.Caption := vTranslations.lpChoosePlugin;

  { HotKey tab }

  tabHotKey.Caption := vTranslations.lpTabHotKey;
  lblHotKeyKey.Caption := vTranslations.lpHotKeyKey;

  rgrpHotKeyInvoke.Caption := vTranslations.lpHotKeyInvoke;
  rgrpHotKeyInvoke.Items.Clear;
  rgrpHotKeyInvoke.Items.Add(vTranslations.lpHotKeyDisableInvoke);
  rgrpHotKeyInvoke.Items.Add(vTranslations.lpHotKeyCtrlAltKey);
  rgrpHotKeyInvoke.Items.Add(vTranslations.lpHotKeyDisableAll);

  { Others }

  lblDisabledHint.Caption := vTranslations.lpDisabledHint;

  btnClose.Caption := vTranslations.lpClose;

  {*******************************************************************
  *  Updates the configurations
  *******************************************************************}

  { General tab }

  chkAutoRun.Checked := vConfigurations.autoRun;

  chkShowWhenExecuted.Checked := vConfigurations.showWhenExecuted;

{$IFDEF Unix}
  chkAutoRun.Enabled := False;
{$ENDIF}

  { Plugins tab }

  lstPluginsList.Items.Clear;
  lstPluginsList.ItemIndex := -1;

  if FindFirst(vConfigurations.MyDirectory + ID_PLUGIN_WILDCARD, faAnyFile, SR) = 0 then
  begin
    repeat
      if (SR.Attr <> faDirectory) then
       lstPluginsList.Items.Add(SR.Name);
    until FindNext(SR) <> 0;
    
    // Must free up resources used by these successful finds
    FindClose(SR);
  end;
  
  { Tryes to select the plugin currently in use }
  for i := 0 to lstPluginsList.Count - 1 do
  begin
    if lstPluginsList.Items.Strings[i] = vConfigurations.PluginName then
     lstPluginsList.ItemIndex := i;
  end;

  { HotKey tab }

  rgrpHotKeyInvoke.ItemIndex := vConfigurations.HotKeyMode;

  txtHotKeyKey.Text := vConfigurations.HotKeyKey;

  { Image tab }
  sliderContrast.Position := vConfigurations.Contrast;
  if vConfigurations.ExtraAntiAliasing then
    rgrpAntialiasing.ItemIndex := 1
  else
    rgrpAntialiasing.ItemIndex := 0;

{$ifdef Unix}
  txtHotKeyKey.Enabled := False;
  rgrpHotKeyInvoke.Enabled := False;
{$endif}
end;

{*******************************************************************}
{@@
  Saves the dialog information to vConfigurations
}
{*******************************************************************}
procedure TConfigDialog.SaveConfigurations;
begin
  { General tab }

  vConfigurations.autoRun := chkAutoRun.Checked;
  
  vConfigurations.showWhenExecuted := chkShowWhenExecuted.Checked;

  { Plugins tab }

  if lstPluginsList.ItemIndex <> -1 then
  begin
    vConfigurations.PluginName := lstPluginsList.Items.Strings[lstPluginsList.ItemIndex];
  end;
  
  { HotKey tab }

  vConfigurations.HotKeyMode := rgrpHotKeyInvoke.ItemIndex;
  vConfigurations.HotKeyKey  := txtHotKeyKey.Text[1];

  { Image tab }
  vConfigurations.Contrast := sliderContrast.Position;

  if  rgrpAntialiasing.ItemIndex = 1 then
    vConfigurations.ExtraAntiAliasing := True
  else
    vConfigurations.ExtraAntiAliasing := False;

  vMainWindow.UpdateHotKey(Self);
end;

end.