~ubuntu-branches/ubuntu/saucy/lazarus/saucy

« back to all changes in this revision

Viewing changes to components/tachart/demo/listbox/Unit1.pas

  • Committer: Package Import Robot
  • Author(s): Paul Gevers, Abou Al Montacir, Bart Martens, Paul Gevers
  • Date: 2013-06-08 14:12:17 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20130608141217-7k0cy9id8ifcnutc
Tags: 1.0.8+dfsg-1
[ Abou Al Montacir ]
* New upstream major release and multiple maintenace release offering many
  fixes and new features marking a new milestone for the Lazarus development
  and its stability level.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_fixes_branch
* LCL changes:
  - LCL is now a normal package.
      + Platform independent parts of the LCL are now in the package LCLBase
      + LCL is automatically recompiled when switching the target platform,
        unless pre-compiled binaries for this target are already installed.
      + No impact on existing projects.
      + Linker options needed by LCL are no more added to projects that do
        not use the LCL package.
  - Minor changes in LCL basic classes behaviour
      + TCustomForm.Create raises an exception if a form resource is not
        found.
      + TNotebook and TPage: a new implementation of these classes was added.
      + TDBNavigator: It is now possible to have focusable buttons by setting
        Options = [navFocusableButtons] and TabStop = True, useful for
        accessibility and for devices with neither mouse nor touch screen.
      + Names of TControlBorderSpacing.GetSideSpace and GetSpace were swapped
        and are now consistent. GetSideSpace = Around + GetSpace.
      + TForm.WindowState=wsFullscreen was added
      + TCanvas.TextFitInfo was added to calculate how many characters will
        fit into a specified Width. Useful for word-wrapping calculations.
      + TControl.GetColorResolvingParent and
        TControl.GetRGBColorResolvingParent were added, simplifying the work
        to obtain the final color of the control while resolving clDefault
        and the ParentColor.
      + LCLIntf.GetTextExtentExPoint now has a good default implementation
        which works in any platform not providing a specific implementation.
        However, Widgetset specific implementation is better, when available.
      + TTabControl was reorganized. Now it has the correct class hierarchy
        and inherits from TCustomTabControl as it should.
  - New unit in the LCL:
      + lazdialogs.pas: adds non-native versions of various native dialogs,
        for example TLazOpenDialog, TLazSaveDialog, TLazSelectDirectoryDialog.
        It is used by widgetsets which either do not have a native dialog, or
        do not wish to use it because it is limited. These dialogs can also be
        used by user applications directly.
      + lazdeviceapis.pas: offers an interface to more hardware devices such
        as the accelerometer, GPS, etc. See LazDeviceAPIs
      + lazcanvas.pas: provides a TFPImageCanvas descendent implementing
        drawing in a LCL-compatible way, but 100% in Pascal.
      + lazregions.pas. LazRegions is a wholly Pascal implementation of
        regions for canvas clipping, event clipping, finding in which control
        of a region tree one an event should reach, for drawing polygons, etc.
      + customdrawncontrols.pas, customdrawndrawers.pas,
        customdrawn_common.pas, customdrawn_android.pas and
        customdrawn_winxp.pas: are the Lazarus Custom Drawn Controls -controls
        which imitate the standard LCL ones, but with the difference that they
        are non-native and support skinning.
  - New APIs added to the LCL to improve support of accessibility software
    such as screen readers.
* IDE changes:
  - Many improvments.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/New_IDE_features_since#v1.0_.282012-08-29.29
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes#IDE_Changes
* Debugger / Editor changes:
  - Added pascal sources and breakpoints to the disassembler
  - Added threads dialog.
* Components changes:
  - TAChart: many fixes and new features
  - CodeTool: support Delphi style generics and new syntax extensions.
  - AggPas: removed to honor free licencing. (Closes: Bug#708695)
[Bart Martens]
* New debian/watch file fixing issues with upstream RC release.
[Abou Al Montacir]
* Avoid changing files in .pc hidden directory, these are used by quilt for
  internal purpose and could lead to surprises during build.
[Paul Gevers]
* Updated get-orig-source target and it compinion script orig-tar.sh so that they
  repack the source file, allowing bug 708695 to be fixed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
unit Unit1; 
 
2
 
 
3
{$mode objfpc}{$H+}
 
4
 
 
5
interface
 
6
 
 
7
uses
 
8
  Classes, SysUtils, TASources, TASeries, TAGraph, CheckLst, Spin,
 
9
  ExtCtrls, StdCtrls, FileUtil, Forms, Controls, Graphics, Dialogs,
 
10
  TAChartListbox, TACustomSeries, TALegend;
 
11
 
 
12
type
 
13
 
 
14
  { TForm1 }
 
15
 
 
16
  TForm1 = class(TForm)
 
17
    Bevel1: TBevel;
 
18
    BtnAddSeries: TButton;
 
19
    BtnDeleteSeries: TButton;
 
20
    BtnToggleCOS: TButton;
 
21
    BtnToggleChart: TButton;
 
22
    BtnToggleSIN: TButton;
 
23
    BtnAddPoint: TButton;
 
24
    Chart: TChart;
 
25
    CbShowCheckboxes: TCheckBox;
 
26
    CbShowSeriesIcon: TCheckBox;
 
27
    CbCheckStyle: TCheckBox;
 
28
    CbKeepSeriesOut: TCheckBox;
 
29
    ChartListbox: TChartListbox;
 
30
    CheckListBox1: TCheckListBox;
 
31
    ColorDialog: TColorDialog;
 
32
    Label1: TLabel;
 
33
    Label2: TLabel;
 
34
    ListBox1: TListBox;
 
35
    Memo: TMemo;
 
36
    SinSeries: TLineSeries;
 
37
    CosSeries: TLineSeries;
 
38
    ListboxPanel: TPanel;
 
39
    Panel1: TPanel;
 
40
    RandomChartSource: TRandomChartSource;
 
41
    EdColumns: TSpinEdit;
 
42
    Splitter: TSplitter;
 
43
    procedure BtnAddSeriesClick(Sender: TObject);
 
44
    procedure BtnDeleteSeriesClick(Sender: TObject);
 
45
    procedure BtnToggleCOSClick(Sender: TObject);
 
46
    procedure BtnToggleChartClick(Sender: TObject);
 
47
    procedure BtnToggleSINClick(Sender: TObject);
 
48
    procedure BtnAddPointClick(Sender: TObject);
 
49
    procedure CbShowCheckboxesChange(Sender: TObject);
 
50
    procedure CbShowSeriesIconChange(Sender: TObject);
 
51
    procedure CbCheckStyleChange(Sender: TObject);
 
52
    procedure CbKeepSeriesOutChange(Sender: TObject);
 
53
    procedure ChartListboxAddSeries(ASender: TChartListbox;
 
54
      ASeries: TCustomChartSeries; AItems: TChartLegendItems;
 
55
      var ASkip: Boolean);
 
56
    procedure ChartListboxPopulate(Sender: TObject);
 
57
    procedure EdColumnsChange(Sender: TObject);
 
58
    procedure FormCreate(Sender: TObject);
 
59
    procedure ChartListboxCheckboxClick(Sender: TObject; Index: Integer);
 
60
    procedure ChartListboxClick(Sender: TObject);
 
61
    procedure ChartListboxItemClick(Sender: TObject; Index: Integer);
 
62
    procedure ChartListboxSeriesIconDblClick(Sender: TObject; Index: Integer);
 
63
  private
 
64
    procedure CreateData;
 
65
  end;
 
66
 
 
67
var
 
68
  Form1: TForm1; 
 
69
 
 
70
implementation
 
71
 
 
72
{$R *.lfm}
 
73
 
 
74
uses
 
75
  TATypes;
 
76
 
 
77
{ TForm1 }
 
78
 
 
79
procedure TForm1.CreateData;
 
80
const
 
81
  n = 100;
 
82
var
 
83
  i: Integer;
 
84
  mn, mx, x: Double;
 
85
begin
 
86
  mx := 10.0;
 
87
  mn := 0.0;
 
88
  for i := 0 to n - 1 do begin
 
89
    x := mn + (mx - mn) / (n - 1) * i;
 
90
    SinSeries.AddXY(x, sin(x));
 
91
    CosSeries.AddXY(x, cos(x));
 
92
  end;
 
93
end;
 
94
 
 
95
procedure TForm1.ChartListboxCheckboxClick(Sender: TObject; Index: Integer);
 
96
begin
 
97
  Memo.Lines.Add(Format('Checkbox of item #%d (series "%s") clicked.',
 
98
    [Index, ChartListbox.Series[Index].Title]));
 
99
end;
 
100
 
 
101
procedure TForm1.ChartListboxSeriesIconDblClick(Sender: TObject; Index: Integer);
 
102
begin
 
103
  Memo.Lines.Add(Format('Icon of item #%d (series "%s") clicked.',
 
104
    [Index, ChartListbox.Series[Index].Title]));
 
105
 
 
106
  if ChartListbox.Series[Index] is TLineSeries then
 
107
    with ColorDialog do begin
 
108
      Color := TLineSeries(ChartListbox.Series[Index]).SeriesColor;
 
109
      if Execute then
 
110
        TLineSeries(ChartListbox.Series[Index]).SeriesColor := Color;
 
111
    end;
 
112
end;
 
113
 
 
114
procedure TForm1.ChartListboxItemClick(Sender: TObject; Index: Integer);
 
115
begin
 
116
  Memo.Lines.Add(Format('Title of item #%d (series "%s") clicked.',
 
117
    [Index, ChartListbox.Series[Index].Title]));
 
118
end;
 
119
 
 
120
procedure TForm1.ChartListboxPopulate(Sender: TObject);
 
121
begin
 
122
  Memo.Lines.Add('Populate');
 
123
end;
 
124
 
 
125
procedure TForm1.ChartListboxClick(Sender: TObject);
 
126
begin
 
127
  with ChartListbox do
 
128
    if ItemIndex <> -1 then
 
129
      Memo.Lines.Add(Format('Item #%d (series "%s") clicked.',
 
130
        [ItemIndex, Series[ItemIndex].Title]));
 
131
end;
 
132
 
 
133
procedure TForm1.FormCreate(Sender: TObject);
 
134
begin
 
135
  CreateData;
 
136
end;
 
137
 
 
138
procedure TForm1.BtnToggleSINClick(Sender: TObject);
 
139
begin
 
140
  SinSeries.Active := not SinSeries.Active;
 
141
end;
 
142
 
 
143
procedure TForm1.BtnAddPointClick(Sender: TObject);
 
144
begin
 
145
  SinSeries.Add(Random(5), '', clRed);
 
146
end;
 
147
 
 
148
procedure TForm1.CbShowCheckboxesChange(Sender: TObject);
 
149
begin
 
150
  with ChartListbox do
 
151
    if CbShowCheckboxes.Checked then
 
152
      Options := Options + [cloShowCheckboxes]
 
153
    else
 
154
      Options := Options - [cloShowCheckboxes];
 
155
end;
 
156
 
 
157
procedure TForm1.CbShowSeriesIconChange(Sender: TObject);
 
158
begin
 
159
  with ChartListbox do
 
160
    if CbShowSeriesIcon.Checked then
 
161
      Options := Options + [cloShowIcons]
 
162
    else
 
163
      Options := Options - [cloShowIcons];
 
164
end;
 
165
 
 
166
procedure TForm1.ChartListboxAddSeries(ASender: TChartListbox;
 
167
  ASeries: TCustomChartSeries; AItems: TChartLegendItems; var ASkip: Boolean);
 
168
begin
 
169
  ASkip := CbKeepSeriesOut.Checked and
 
170
    ((ASeries = SinSeries) or (ASeries = CosSeries));
 
171
end;
 
172
 
 
173
procedure TForm1.CbCheckStyleChange(Sender:TObject);
 
174
begin
 
175
  if CbCheckStyle.Checked then
 
176
    Chartlistbox.CheckStyle := cbsRadioButton
 
177
  else
 
178
    ChartListbox.CheckStyle := cbsCheckbox;
 
179
end;
 
180
 
 
181
procedure TForm1.CbKeepSeriesOutChange(Sender: TObject);
 
182
begin
 
183
  ChartListbox.SeriesChanged(Self);
 
184
end;
 
185
 
 
186
procedure TForm1.EdColumnsChange(Sender: TObject);
 
187
begin
 
188
  ChartListbox.Columns := EdColumns.Value;
 
189
  CheckListbox1.Columns := EdColumns.Value;
 
190
  Listbox1.Columns := EdColumns.Value;
 
191
end;
 
192
 
 
193
procedure TForm1.BtnAddSeriesClick(Sender: TObject);
 
194
var
 
195
  ser : TLineSeries;
 
196
  cs : TRandomChartSource;
 
197
begin
 
198
  cs := TRandomChartSource.Create(Chart);
 
199
  cs.RandSeed := Random(65000);
 
200
  cs.PointsNumber := Random(10) + 3;
 
201
  cs.XMax := 10;
 
202
  cs.XMin := 0;
 
203
  cs.YMax := 1;
 
204
  cs.YMin := -1;
 
205
  cs.YCount := 1;
 
206
  ser := TLineSeries.Create(Chart);
 
207
  ser.Source := cs;
 
208
  ser.SeriesColor := rgbToColor(Random(255), Random(256), Random(256));
 
209
  ser.Title := Format('Series %d', [Chart.SeriesCount + 1]);
 
210
  ser.ShowPoints := Odd(Chart.SeriesCount);
 
211
  ser.Pointer.Brush.Color := ser.SeriesColor;
 
212
  ser.Pointer.Style :=
 
213
    TSeriesPointerStyle(Random(Ord(High(TSeriesPointerStyle))));
 
214
  Chart.AddSeries(ser);
 
215
end;
 
216
 
 
217
procedure TForm1.BtnDeleteSeriesClick(Sender: TObject);
 
218
begin
 
219
  if ChartListbox.ItemIndex = -1 then
 
220
    ShowMessage('Select the series to be deleted from the listbox first.')
 
221
  else if (ChartListbox.ItemIndex < 2) and not CbKeepSeriesOut.Checked then
 
222
    ShowMessage(
 
223
      'This demo is designed to have at least the sine and cosine ' +
 
224
      'series in the chart. Deleting is not allowed.')
 
225
  else
 
226
    ChartListbox.Series[ChartListbox.ItemIndex].Free;
 
227
end;
 
228
 
 
229
procedure TForm1.BtnToggleCOSClick(Sender: TObject);
 
230
begin
 
231
  CosSeries.Active := not CosSeries.Active;
 
232
end;
 
233
 
 
234
procedure TForm1.BtnToggleChartClick(Sender: TObject);
 
235
begin
 
236
  if ChartListbox.Chart = nil then
 
237
    ChartListbox.Chart := Chart
 
238
  else
 
239
    ChartListbox.Chart := nil;
 
240
end;
 
241
 
 
242
 
 
243
end.
 
244