Chapter 09 - Project QDlgApply |
Project Structure
|
QDlgApply.dpr |
program QDlgApply;
uses
QForms,
Main in 'Main.pas' ,
StyleD in 'StyleD.pas' ,
ListD in 'ListD.pas' ;
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TStyleDial, StyleDial);
Application.CreateForm(TListDial, ListDial);
Application.Run;
end.
|
Main.pas |
unit Main;
interface
uses Qt, Classes, QGraphics, QForms, QControls,
StyleD, ListD, QStdCtrls, QExtCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
StyleButton: TButton;
Bevel1: TBevel;
procedure LabelDoubleClick(Sender: TObject);
procedure LabelClick(Sender: TObject);
procedure StyleButtonClick(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
procedure TForm1.LabelDoubleClick(Sender: TObject);
begin
with ListDial.Listbox1 do
begin
ItemIndex := Items.IndexOf ((Sender as TLabel).Caption);
if (ListDial.ShowModal = mrOk) and (ItemIndex >= 0) then
(Sender as TLabel).Caption := Items [ItemIndex];
end;
end;
procedure TForm1.LabelClick(Sender: TObject);
var
I: Integer;
begin
for I := 0 to ComponentCount - 1 do
if (Components[I] is TLabel) and
(Components[I].Tag = 1) then
TLabel (Components[I]).Font.Color := clBlack;
(Sender as TLabel).Font.Color := clRed;
end;
procedure TForm1.StyleButtonClick(Sender: TObject);
begin
StyleDial.Show;
end;
end.
|
StyleD.pas |
unit StyleD;
interface
uses
SysUtils, Qt, Classes, QGraphics, QForms,
QControls, QButtons, QStdCtrls;
type
TStyleDial = class(TForm)
ApplyBitBtn: TBitBtn;
CloseBitBtn: TBitBtn;
ItalicCheckBox: TCheckBox;
BoldCheckBox: TCheckBox;
UnderlineCheckBox: TCheckBox;
LabelSample: TLabel;
procedure ApplyBitBtnClick(Sender: TObject);
procedure CloseBitBtnClick(Sender: TObject);
procedure ItalicCheckBoxClick(Sender: TObject);
procedure BoldCheckBoxClick(Sender: TObject);
procedure UnderlineCheckBoxClick(Sender: TObject);
private
public
end;
var
StyleDial: TStyleDial;
implementation
uses Main;
procedure TStyleDial.ApplyBitBtnClick(Sender: TObject);
var
I: Integer;
begin
for I := 1 to 5 do
(Form1.FindComponent ('Label' + IntToStr (I)) as TLabel).
Font.Style := LabelSample.Font.Style;
end;
procedure TStyleDial.CloseBitBtnClick(Sender: TObject);
begin
Close;
end;
procedure TStyleDial.ItalicCheckBoxClick(Sender: TObject);
begin
if ItalicCheckBox.Checked then
LabelSample.Font.Style := LabelSample.Font.Style + [fsItalic]
else
LabelSample.Font.Style := LabelSample.Font.Style - [fsItalic];
end;
procedure TStyleDial.BoldCheckBoxClick(Sender: TObject);
begin
if BoldCheckBox.Checked then
LabelSample.Font.Style := LabelSample.Font.Style + [fsBold]
else
LabelSample.Font.Style := LabelSample.Font.Style - [fsBold];
end;
procedure TStyleDial.UnderlineCheckBoxClick(Sender: TObject);
begin
if UnderlineCheckBox.Checked then
LabelSample.Font.Style := LabelSample.Font.Style + [fsUnderline]
else
LabelSample.Font.Style := LabelSample.Font.Style - [fsUnderline];
end;
end.
|
ListD.pas |
unit ListD;
interface
uses Qt, Classes, QGraphics, QForms,
QControls, QButtons, QStdCtrls;
type
TListDial = class(TForm)
ListBox1: TListBox;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
private
public
end;
var
ListDial: TListDial;
implementation
end.
|
Main.xfm |
object Form1: TForm1
Left = 151
Top = 137
Width = 350
Height = 237
VertScrollBar.Range = 184
HorzScrollBar.Range = 337
ActiveControl = StyleButton
Caption = 'DlgApply (Modal & modeless dialogs)'
Color = clButton
Font.Color = clBlack
Font.Height = 11
Font.Name = 'MS Sans Serif'
Font.Pitch = fpVariable
Font.Style = []
Font.Weight = 40
ParentFont = False
PixelsPerInch = 96
TextHeight = 13
TextWidth = 6
object Bevel1: TBevel
Left = 168
Top = 57
Width = 169
Height = 97
end
object Label1: TLabel
Tag = 1
Left = 27
Top = 26
Width = 50
Height = 22
Caption = 'Name'
Font.Color = clBlack
Font.Height = 19
Font.Name = 'Arial'
Font.Pitch = fpVariable
Font.Style = []
Font.Weight = 40
ParentFont = False
OnClick = LabelClick
OnDblClick = LabelDoubleClick
end
object Label2: TLabel
Tag = 1
Left = 27
Top = 60
Width = 50
Height = 22
Caption = 'Name'
Font.Color = clBlack
Font.Height = 19
Font.Name = 'Arial'
Font.Pitch = fpVariable
Font.Style = []
Font.Weight = 40
ParentFont = False
OnClick = LabelClick
OnDblClick = LabelDoubleClick
end
object Label3: TLabel
Tag = 1
Left = 27
Top = 94
Width = 50
Height = 22
Caption = 'Name'
Font.Color = clBlack
Font.Height = 19
Font.Name = 'Arial'
Font.Pitch = fpVariable
Font.Style = []
Font.Weight = 40
ParentFont = False
OnClick = LabelClick
OnDblClick = LabelDoubleClick
end
object Label4: TLabel
Tag = 1
Left = 27
Top = 128
Width = 50
Height = 22
Caption = 'Name'
Font.Color = clBlack
Font.Height = 19
Font.Name = 'Arial'
Font.Pitch = fpVariable
Font.Style = []
Font.Weight = 40
ParentFont = False
OnClick = LabelClick
OnDblClick = LabelDoubleClick
end
object Label5: TLabel
Tag = 1
Left = 27
Top = 162
Width = 50
Height = 22
Caption = 'Name'
Font.Color = clBlack
Font.Height = 19
Font.Name = 'Arial'
Font.Pitch = fpVariable
Font.Style = []
Font.Weight = 40
ParentFont = False
OnClick = LabelClick
OnDblClick = LabelDoubleClick
end
object Label6: TLabel
Left = 176
Top = 65
Width = 153
Height = 48
Alignment = taCenter
AutoSize = False
Caption =
'Double-click on a name to change it or click on the button below' +
' to modify text style'
WordWrap = True
end
object StyleButton: TButton
Left = 220
Top = 117
Width = 65
Height = 21
Caption = '&Style...'
TabOrder = 0
OnClick = StyleButtonClick
end
end
|
StyleD.xfm |
object StyleDial: TStyleDial
Left = 333
Top = 198
ActiveControl = ApplyBitBtn
BorderStyle = bsDialog
Caption = 'Select style'
ClientHeight = 152
ClientWidth = 221
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
PixelsPerInch = 96
TextHeight = 13
object LabelSample: TLabel
Left = 4
Top = 120
Width = 209
Height = 22
Alignment = taCenter
AutoSize = False
Caption = 'Sample label'
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlack
Font.Height = -19
Font.Name = 'Arial'
Font.Style = []
ParentFont = False
end
object ApplyBitBtn: TBitBtn
Left = 128
Top = 21
Width = 75
Height = 28
Caption = '&Apply'
Default = True
ModalResult = 1
TabOrder = 0
OnClick = ApplyBitBtnClick
Glyph.Data =
end
object CloseBitBtn: TBitBtn
Left = 128
Top = 61
Width = 75
Height = 28
Cancel = True
Caption = 'Close'
ModalResult = 2
TabOrder = 1
OnClick = CloseBitBtnClick
Glyph.Data =
end
object ItalicCheckBox: TCheckBox
Left = 24
Top = 13
Width = 89
Height = 25
Caption = '&Italic'
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = [fsItalic]
ParentFont = False
TabOrder = 2
OnClick = ItalicCheckBoxClick
end
object BoldCheckBox: TCheckBox
Left = 24
Top = 45
Width = 89
Height = 25
Caption = '&Bold'
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = [fsBold]
ParentFont = False
TabOrder = 3
OnClick = BoldCheckBoxClick
end
object UnderlineCheckBox: TCheckBox
Left = 24
Top = 77
Width = 89
Height = 25
Caption = '&Underline'
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = [fsUnderline]
ParentFont = False
TabOrder = 4
OnClick = UnderlineCheckBoxClick
end
end
|
ListD.xfm |
object ListDial: TListDial
Left = 328
Top = 272
Width = 217
Height = 123
VertScrollBar.Range = 94
HorzScrollBar.Range = 211
ActiveControl = ListBox1
BorderStyle = �������
|