-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmconvertmode.pas
185 lines (160 loc) · 4.82 KB
/
frmconvertmode.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
unit frmConvertMode;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
Spin, ComCtrls, LCLType, uCmdLineBuilder;
type
{ TConvertModeForm }
TConvertModeForm = class(TForm)
BitsRadioButtonNone: TRadioButton;
SelectPathToSaveButton: TButton;
StartConvertButton: TButton;
ChangeSizeCheckBox: TCheckBox;
ConvertToComboBox: TComboBox;
PathToSaveEdit: TEdit;
FileNameSuffixEdit: TEdit;
GroupBox1: TGroupBox;
BitsRadioButton8: TRadioButton;
BitsRadioButton16: TRadioButton;
BitsRadioButton24: TRadioButton;
BitsRadioButton32: TRadioButton;
CompressGroupBox: TGroupBox;
GroupBox3: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
RadioGroup1: TRadioGroup;
CompressSpinEdit: TSpinEdit;
WidthSpinEdit: TSpinEdit;
HeightSpinEdit: TSpinEdit;
CompressTrackBar: TTrackBar;
procedure BitsRadioButton8Change(Sender: TObject);
procedure ChangeSizeCheckBoxChange(Sender: TObject);
procedure CompressTrackBarChange(Sender: TObject);
procedure CompressSpinEditChange(Sender: TObject);
procedure ConvertToComboBoxSelect(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure HeightSpinEditChange(Sender: TObject);
procedure SelectPathToSaveButtonClick(Sender: TObject);
procedure StartConvertButtonClick(Sender: TObject);
procedure WidthSpinEditChange(Sender: TObject);
private
FCmdLineBuilder: TCmdLineBuilder;
procedure initDefaults();
function validateForm(): Boolean;
public
constructor Create(AOwner: TComponent; var ACmdLineBuilder: TCmdLineBuilder); overload;
end;
//var
//ConvertModeForm: TConvertModeForm;
implementation
{$R *.lfm}
{ TConvertModeForm }
procedure TConvertModeForm.FormCreate(Sender: TObject);
begin
initDefaults();
end;
procedure TConvertModeForm.ConvertToComboBoxSelect(Sender: TObject);
begin
with ConvertToComboBox do
begin
FCmdLineBuilder.setTargetFormat( Items[ItemIndex] );
CompressGroupBox.Enabled := (ItemIndex = 0) or (ItemIndex = 1);
if (CompressGroupBox.Enabled) then
FCmdLineBuilder.setCompressQuality(CompressSpinEdit.Value)
else
FCmdLineBuilder.setCompressQuality(-1);
end;
end;
procedure TConvertModeForm.BitsRadioButton8Change(Sender: TObject);
begin
try
FCmdLineBuilder.setBitsPerPixel(StrToInt((Sender As TRadioButton).Caption));
except
FCmdLineBuilder.setBitsPerPixel(-1);
end;
end;
procedure TConvertModeForm.ChangeSizeCheckBoxChange(Sender: TObject);
begin
if (ChangeSizeCheckBox.Checked) then
FCmdLineBuilder.setResize(WidthSpinEdit.Value, HeightSpinEdit.Value)
else
FCmdLineBuilder.setResize(-1, -1);
end;
procedure TConvertModeForm.CompressTrackBarChange(Sender: TObject);
begin
CompressSpinEdit.Value := CompressTrackBar.Position;
FCmdLineBuilder.setCompressQuality(CompressSpinEdit.Value);
end;
procedure TConvertModeForm.CompressSpinEditChange(Sender: TObject);
begin
CompressTrackBar.Position := CompressSpinEdit.Value;
FCmdLineBuilder.setCompressQuality(CompressSpinEdit.Value);
end;
procedure TConvertModeForm.HeightSpinEditChange(Sender: TObject);
begin
FCmdLineBuilder.setResize(WidthSpinEdit.Value, HeightSpinEdit.Value);
end;
procedure TConvertModeForm.SelectPathToSaveButtonClick(Sender: TObject);
begin
with TSelectDirectoryDialog.Create(self) do
begin
try
if (execute) then
begin
PathToSaveEdit.Text := FileName;
FCmdLineBuilder.setPath(FileName);
end;
finally
Free;
end;
end;
end;
procedure TConvertModeForm.StartConvertButtonClick(Sender: TObject);
begin
if validateForm() then
begin
FCmdLineBuilder.setFileSuffix(FileNameSuffixEdit.Text);
ModalResult := mrOk;
end;
end;
procedure TConvertModeForm.WidthSpinEditChange(Sender: TObject);
begin
FCmdLineBuilder.setResize(WidthSpinEdit.Value, HeightSpinEdit.Value);
end;
procedure TConvertModeForm.initDefaults();
begin
FCmdLineBuilder.setBitsPerPixel(-1);
ConvertToComboBoxSelect(ConvertToComboBox);
ChangeSizeCheckBoxChange(ChangeSizeCheckBox);
end;
function TConvertModeForm.validateForm(): Boolean;
begin
Result := false;
if (ChangeSizeCheckBox.Checked) then
begin
if (WidthSpinEdit.Value = 0) or (HeightSpinEdit.Value = 0) then
begin
Application.MessageBox('Width and Height must be more than zero.',
'Error', MB_OK + MB_ICONWARNING);
exit;
end;
end;
if (not DirectoryExists(PathToSaveEdit.Text)) then
begin
Application.MessageBox('Select directory for save converted files.',
'Error', MB_OK + MB_ICONWARNING);
exit;
end;
Result := true;
end;
constructor TConvertModeForm.Create(AOwner: TComponent;
var ACmdLineBuilder: TCmdLineBuilder);
begin
FCmdLineBuilder := ACmdLineBuilder;
inherited Create(AOwner);
end;
end.