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
|
unit ceFontFrame;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Graphics, Forms, Controls, StdCtrls, Dialogs, Spin,
ExtCtrls;
type
{ TChartFontFrame }
TChartFontFrame = class(TFrame)
cbBold: TCheckBox;
cbFontColor: TColorButton;
cbItalic: TCheckBox;
cbUnderline: TCheckBox;
cmbFontName: TComboBox;
cmbFontSize: TComboBox;
lblOrientation: TLabel;
Panel1: TPanel;
Panel2: TPanel;
seOrientation: TSpinEdit;
procedure cbBoldChange(Sender: TObject);
procedure cbFontColorColorChanged(Sender: TObject);
procedure cbItalicChange(Sender: TObject);
procedure cbUnderlineChange(Sender: TObject);
procedure cmbFontNameChange(Sender: TObject);
procedure cmbFontSizeChange(Sender: TObject);
procedure seOrientationChange(Sender: TObject);
private
FFont: TFont;
FOnChange: TNotifyEvent;
procedure DoChanged;
public
constructor Create(AOwner: TComponent); override;
procedure GetData(AFont: TFont);
procedure Prepare(AFont: TFont; WithOrientation: boolean);
property OnChange: TNotifyEvent read FOnChange write FOnChange;
end;
implementation
{$R *.lfm}
uses
ceUtils;
const
FONT_SIZES: array[0..20] of String = (
'default', '8', '9', '10', '12', '14', '16', '18', '20', '22', '24', '28',
'32', '36', '40', '44', '48', '56', '64', '72', '80');
constructor TChartFontFrame.Create(AOwner: TComponent);
var
i: Integer;
begin
inherited;
cmbFontName.Items.Assign(Screen.Fonts);
cmbFontName.Items.Insert(0, 'default');
for i:=0 to High(FONT_SIZES) do
cmbFontSize.Items.Add(FONT_SIZES[i]);
cbFontColor.Width := cbFontColor.Height;
cmbFontName.DropdownCount := DEFAULT_DROPDOWN_COUNT;
cmbFontSize.DropdownCount := DEFAULT_DROPDOWN_COUNT;
end;
procedure TChartFontFrame.cbBoldChange(Sender: TObject);
begin
if cbBold.Checked then
FFont.Style := FFont.Style + [fsBold]
else
FFont.Style := FFont.Style - [fsBold];
DoChanged;
end;
procedure TChartFontFrame.cbFontColorColorChanged(Sender: TObject);
begin
FFont.Color := cbFontColor.ButtonColor;
DoChanged;
end;
procedure TChartFontFrame.cbItalicChange(Sender: TObject);
begin
if cbItalic.Checked then
FFont.Style := FFont.Style + [fsItalic]
else
FFont.Style := FFont.Style - [fsItalic];
DoChanged;
end;
procedure TChartFontFrame.cbUnderlineChange(Sender: TObject);
begin
if cbUnderline.Checked then
FFont.Style := FFont.Style + [fsUnderline]
else
FFont.Style := FFont.Style - [fsUnderline];
DoChanged;
end;
procedure TChartFontFrame.cmbFontNameChange(Sender: TObject);
begin
if cmbFontName.ItemIndex < 1 then
FFont.Name := 'default'
else
FFont.Name := cmbFontName.Items[cmbFontName.ItemIndex];
DoChanged;
end;
procedure TChartFontFrame.cmbFontSizeChange(Sender: TObject);
begin
if cmbFontSize.ItemIndex < 1 then
FFont.Size := 0
else
FFont.Size := StrToInt(cmbFontSize.Items[cmbFontSize.ItemIndex]);
DoChanged;
end;
procedure TChartFontFrame.seOrientationChange(Sender: TObject);
begin
FFont.Orientation := seOrientation.Value * 10;
DoChanged;
end;
procedure TChartFontFrame.DoChanged;
begin
if Assigned(FOnChange) then FOnChange(Self);
end;
procedure TChartFontFrame.GetData(AFont: TFont);
begin
if cmbFontSize.ItemIndex < 1 then
AFont.Name := cmbFontName.Items[0]
else
AFont.Name := cmbFontName.Items[cmbFontName.ItemIndex];
if cmbFontSize.ItemIndex < 1 then
AFont.Size := 0
else
AFont.Size := StrToInt(cmbFontSize.Items[cmbFontSize.ItemIndex]);
AFont.Orientation := seOrientation .Value * 10;
AFont.Color := cbFontColor.ButtonColor;
if cbBold.Checked then AFont.Style := AFont.Style + [fsBold] else AFont.Style := [];
if cbItalic.Checked then AFont.Style := AFont.Style + [fsItalic] else AFont.Style := [];
if cbUnderline.Checked then AFont.Style := AFont.Style + [fsUnderline] else AFont.Style := [];
end;
procedure TChartFontFrame.Prepare(AFont: TFont; WithOrientation: Boolean);
begin
FFont := AFont;
cmbFontName.ItemIndex := cmbFontName.Items.IndexOf(AFont.Name);
if cmbFontName.ItemIndex = -1 then cmbFontName.ItemIndex := 0;
cmbFontSize.ItemIndex := cmbFontSize.Items.IndexOf(IntToStr(AFont.Size));
if cmbFontSize.ItemIndex = -1 then cmbFontSize.ItemIndex := 0;
seOrientation.Value := AFont.Orientation div 10;
cbFontColor.ButtonColor := ColorToRGB(AFont.Color);
seOrientation.Visible := WithOrientation;
lblOrientation.Visible := WithOrientation;
cbBold.Checked := fsBold in AFont.Style;
cbItalic.Checked := fsItalic in AFont.Style;
cbUnderline.Checked := fsUnderline in AFont.Style;
end;
end.
|