mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-14 09:19:22 +02:00
TAChart: Replace TChartListbox boolean properties with a single Options property. Update demo.
git-svn-id: trunk@31656 -
This commit is contained in:
parent
56bfdb8e1a
commit
2518e1544d
@ -202,22 +202,13 @@ object Form1: TForm1
|
|||||||
OnChange = CbCheckStyleChange
|
OnChange = CbCheckStyleChange
|
||||||
TabOrder = 6
|
TabOrder = 6
|
||||||
end
|
end
|
||||||
object CbMultiSelect: TCheckBox
|
|
||||||
Left = 8
|
|
||||||
Height = 17
|
|
||||||
Top = 344
|
|
||||||
Width = 71
|
|
||||||
Caption = 'MultiSelect'
|
|
||||||
OnChange = CbMultiSelectChange
|
|
||||||
TabOrder = 7
|
|
||||||
end
|
|
||||||
object Memo: TMemo
|
object Memo: TMemo
|
||||||
Left = 9
|
Left = 9
|
||||||
Height = 106
|
Height = 106
|
||||||
Top = 104
|
Top = 104
|
||||||
Width = 275
|
Width = 275
|
||||||
ScrollBars = ssAutoVertical
|
ScrollBars = ssAutoVertical
|
||||||
TabOrder = 8
|
TabOrder = 7
|
||||||
end
|
end
|
||||||
object Label1: TLabel
|
object Label1: TLabel
|
||||||
Left = 9
|
Left = 9
|
||||||
@ -230,17 +221,17 @@ object Form1: TForm1
|
|||||||
object EdColumns: TSpinEdit
|
object EdColumns: TSpinEdit
|
||||||
Left = 208
|
Left = 208
|
||||||
Height = 21
|
Height = 21
|
||||||
Top = 340
|
Top = 308
|
||||||
Width = 50
|
Width = 50
|
||||||
MinValue = 1
|
MinValue = 1
|
||||||
OnChange = EdColumnsChange
|
OnChange = EdColumnsChange
|
||||||
TabOrder = 9
|
TabOrder = 8
|
||||||
Value = 1
|
Value = 1
|
||||||
end
|
end
|
||||||
object Label2: TLabel
|
object Label2: TLabel
|
||||||
Left = 152
|
Left = 152
|
||||||
Height = 14
|
Height = 14
|
||||||
Top = 345
|
Top = 313
|
||||||
Width = 45
|
Width = 45
|
||||||
Caption = 'Columns:'
|
Caption = 'Columns:'
|
||||||
ParentColor = False
|
ParentColor = False
|
||||||
@ -252,7 +243,7 @@ object Form1: TForm1
|
|||||||
Width = 81
|
Width = 81
|
||||||
Caption = 'Delete series'
|
Caption = 'Delete series'
|
||||||
OnClick = BtnDeleteSeriesClick
|
OnClick = BtnDeleteSeriesClick
|
||||||
TabOrder = 10
|
TabOrder = 9
|
||||||
end
|
end
|
||||||
object CbKeepSeriesOut: TCheckBox
|
object CbKeepSeriesOut: TCheckBox
|
||||||
Left = 9
|
Left = 9
|
||||||
@ -261,7 +252,7 @@ object Form1: TForm1
|
|||||||
Width = 227
|
Width = 227
|
||||||
Caption = 'Keep sin and cos series out of ChartListBox'
|
Caption = 'Keep sin and cos series out of ChartListBox'
|
||||||
OnChange = CbKeepSeriesOutChange
|
OnChange = CbKeepSeriesOutChange
|
||||||
TabOrder = 11
|
TabOrder = 10
|
||||||
end
|
end
|
||||||
object Bevel1: TBevel
|
object Bevel1: TBevel
|
||||||
Left = 9
|
Left = 9
|
||||||
|
@ -24,7 +24,6 @@ type
|
|||||||
CbShowCheckboxes: TCheckBox;
|
CbShowCheckboxes: TCheckBox;
|
||||||
CbShowSeriesIcon: TCheckBox;
|
CbShowSeriesIcon: TCheckBox;
|
||||||
CbCheckStyle: TCheckBox;
|
CbCheckStyle: TCheckBox;
|
||||||
CbMultiSelect: TCheckBox;
|
|
||||||
CbKeepSeriesOut: TCheckBox;
|
CbKeepSeriesOut: TCheckBox;
|
||||||
ChartListbox: TChartListbox;
|
ChartListbox: TChartListbox;
|
||||||
CheckListBox1: TCheckListBox;
|
CheckListBox1: TCheckListBox;
|
||||||
@ -45,7 +44,6 @@ type
|
|||||||
procedure BtnToggleCOSClick(Sender: TObject);
|
procedure BtnToggleCOSClick(Sender: TObject);
|
||||||
procedure BtnToggleChartClick(Sender: TObject);
|
procedure BtnToggleChartClick(Sender: TObject);
|
||||||
procedure BtnToggleSINClick(Sender: TObject);
|
procedure BtnToggleSINClick(Sender: TObject);
|
||||||
procedure CbMultiSelectChange(Sender: TObject);
|
|
||||||
procedure CbShowCheckboxesChange(Sender: TObject);
|
procedure CbShowCheckboxesChange(Sender: TObject);
|
||||||
procedure CbShowSeriesIconChange(Sender: TObject);
|
procedure CbShowSeriesIconChange(Sender: TObject);
|
||||||
procedure CbCheckStyleChange(Sender: TObject);
|
procedure CbCheckStyleChange(Sender: TObject);
|
||||||
@ -138,19 +136,22 @@ begin
|
|||||||
SinSeries.Active := not SinSeries.Active;
|
SinSeries.Active := not SinSeries.Active;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TForm1.CbMultiSelectChange(Sender: TObject);
|
|
||||||
begin
|
|
||||||
ChartListbox.MultiSelect := CbMultiSelect.Checked;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TForm1.CbShowCheckboxesChange(Sender: TObject);
|
procedure TForm1.CbShowCheckboxesChange(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
ChartListbox.ShowCheckboxes := CbShowCheckboxes.Checked;
|
with ChartListbox do
|
||||||
|
if CbShowCheckboxes.Checked then
|
||||||
|
Options := Options + [cloShowCheckboxes]
|
||||||
|
else
|
||||||
|
Options := Options - [cloShowCheckboxes];
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TForm1.CbShowSeriesIconChange(Sender: TObject);
|
procedure TForm1.CbShowSeriesIconChange(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
ChartListbox.ShowSeriesIcons := CbShowSeriesIcon.Checked;
|
with ChartListbox do
|
||||||
|
if CbShowSeriesIcon.Checked then
|
||||||
|
Options := Options + [cloShowIcons]
|
||||||
|
else
|
||||||
|
Options := Options - [cloShowIcons];
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TForm1.CbCheckStyleChange(Sender:TObject);
|
procedure TForm1.CbCheckStyleChange(Sender:TObject);
|
||||||
|
@ -41,6 +41,13 @@ type
|
|||||||
|
|
||||||
TCheckBoxesStyle = (cbsCheckbox, cbsRadiobutton);
|
TCheckBoxesStyle = (cbsCheckbox, cbsRadiobutton);
|
||||||
|
|
||||||
|
TChartListOption = (cloShowCheckboxes, cloShowIcons);
|
||||||
|
TChartListOptions = set of TChartListOption;
|
||||||
|
|
||||||
|
const
|
||||||
|
SHOW_ALL = [cloShowCheckboxes, cloShowIcons];
|
||||||
|
|
||||||
|
type
|
||||||
TChartListbox = class(TCustomListbox)
|
TChartListbox = class(TCustomListbox)
|
||||||
private
|
private
|
||||||
FChart: TChart;
|
FChart: TChart;
|
||||||
@ -52,9 +59,8 @@ type
|
|||||||
FOnItemClick: TChartListboxIndexEvent;
|
FOnItemClick: TChartListboxIndexEvent;
|
||||||
FOnPopulate: TNotifyEvent;
|
FOnPopulate: TNotifyEvent;
|
||||||
FOnSeriesIconClick: TChartListboxIndexEvent;
|
FOnSeriesIconClick: TChartListboxIndexEvent;
|
||||||
|
FOptions: TChartListOptions;
|
||||||
FSeriesIconClicked: Integer;
|
FSeriesIconClicked: Integer;
|
||||||
FShowCheckboxes: Boolean;
|
|
||||||
FShowSeriesIcons: Boolean;
|
|
||||||
function GetChecked(AIndex: Integer): Boolean;
|
function GetChecked(AIndex: Integer): Boolean;
|
||||||
function GetLegendItem(AIndex: Integer): TLegendItem;
|
function GetLegendItem(AIndex: Integer): TLegendItem;
|
||||||
function GetSeries(AIndex: Integer): TCustomChartSeries;
|
function GetSeries(AIndex: Integer): TCustomChartSeries;
|
||||||
@ -64,8 +70,7 @@ type
|
|||||||
procedure SetChecked(AIndex: Integer; AValue: Boolean);
|
procedure SetChecked(AIndex: Integer; AValue: Boolean);
|
||||||
procedure SetCheckStyle(AValue: TCheckBoxesStyle);
|
procedure SetCheckStyle(AValue: TCheckBoxesStyle);
|
||||||
procedure SetOnPopulate(AValue: TNotifyEvent);
|
procedure SetOnPopulate(AValue: TNotifyEvent);
|
||||||
procedure SetShowCheckboxes(AValue: Boolean);
|
procedure SetOptions(AValue: TChartListOptions);
|
||||||
procedure SetShowSeriesIcons(AValue: Boolean);
|
|
||||||
|
|
||||||
protected
|
protected
|
||||||
procedure DblClick; override;
|
procedure DblClick; override;
|
||||||
@ -101,10 +106,8 @@ type
|
|||||||
property Chart: TChart read FChart write SetChart;
|
property Chart: TChart read FChart write SetChart;
|
||||||
property CheckStyle: TCheckBoxesStyle
|
property CheckStyle: TCheckBoxesStyle
|
||||||
read FCheckStyle write SetCheckStyle default cbsCheckbox;
|
read FCheckStyle write SetCheckStyle default cbsCheckbox;
|
||||||
property ShowCheckboxes: Boolean
|
property Options: TChartListOptions
|
||||||
read FShowCheckboxes write SetShowCheckboxes default true;
|
read FOptions write SetOptions default SHOW_ALL;
|
||||||
property ShowSeriesIcons: Boolean
|
|
||||||
read FShowSeriesIcons write SetShowSeriesIcons default true;
|
|
||||||
published
|
published
|
||||||
property OnCheckboxClick: TChartListboxIndexEvent
|
property OnCheckboxClick: TChartListboxIndexEvent
|
||||||
read FOnCheckboxClick write FOnCheckboxClick;
|
read FOnCheckboxClick write FOnCheckboxClick;
|
||||||
@ -191,8 +194,7 @@ begin
|
|||||||
inherited Create(AOwner);
|
inherited Create(AOwner);
|
||||||
Style := lbOwnerDrawFixed;
|
Style := lbOwnerDrawFixed;
|
||||||
FListener := TListener.Create(@FChart, @SeriesChanged);
|
FListener := TListener.Create(@FChart, @SeriesChanged);
|
||||||
FShowSeriesIcons := true;
|
FOptions := SHOW_ALL;
|
||||||
FShowCheckboxes := true;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TChartListbox.Destroy;
|
destructor TChartListbox.Destroy;
|
||||||
@ -213,16 +215,16 @@ begin
|
|||||||
ASeriesIconRect := Rect(-1, -1, -1, -1);
|
ASeriesIconRect := Rect(-1, -1, -1, -1);
|
||||||
w := GetSystemMetrics(SM_CYMENUCHECK);
|
w := GetSystemMetrics(SM_CYMENUCHECK);
|
||||||
x := 2;
|
x := 2;
|
||||||
if FShowCheckboxes then begin
|
if cloShowCheckboxes in Options then begin
|
||||||
ACheckboxRect := Bounds(AItemRect.Left + 1, AItemRect.Top + 1, w, w);
|
ACheckboxRect := Bounds(AItemRect.Left + 1, AItemRect.Top + 1, w, w);
|
||||||
if FShowSeriesIcons then
|
if cloShowIcons in Options then
|
||||||
x += ACheckboxRect.Right;
|
x += ACheckboxRect.Right;
|
||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
if FShowSeriesIcons then
|
if cloShowIcons in Options then
|
||||||
x += AItemRect.Left;
|
x += AItemRect.Left;
|
||||||
end;
|
end;
|
||||||
if FShowSeriesIcons then
|
if cloShowIcons in Options then
|
||||||
ASeriesIconRect := Rect(
|
ASeriesIconRect := Rect(
|
||||||
x, AItemRect.Top + 2, x + FChart.Legend.SymbolWidth, AItemRect.Bottom - 2);
|
x, AItemRect.Top + 2, x + FChart.Legend.SymbolWidth, AItemRect.Bottom - 2);
|
||||||
end;
|
end;
|
||||||
@ -297,7 +299,7 @@ begin
|
|||||||
|
|
||||||
CalcRects(ARect, rcb, ricon);
|
CalcRects(ARect, rcb, ricon);
|
||||||
|
|
||||||
if FShowCheckboxes then begin
|
if cloShowCheckboxes in Options then begin
|
||||||
ch := Checked[AIndex];
|
ch := Checked[AIndex];
|
||||||
if ThemeServices.ThemesEnabled then begin
|
if ThemeServices.ThemesEnabled then begin
|
||||||
te := ThemeServices.GetElementDetails(THEMED_FLAGS[FCheckStyle, ch]);
|
te := ThemeServices.GetElementDetails(THEMED_FLAGS[FCheckStyle, ch]);
|
||||||
@ -311,7 +313,7 @@ begin
|
|||||||
else
|
else
|
||||||
x := ARect.Left;
|
x := ARect.Left;
|
||||||
|
|
||||||
if FShowSeriesIcons then begin
|
if cloShowIcons in Options then begin
|
||||||
id := TCanvasDrawer.Create(Canvas);
|
id := TCanvasDrawer.Create(Canvas);
|
||||||
id.Pen := Chart.Legend.SymbolFrame;
|
id.Pen := Chart.Legend.SymbolFrame;
|
||||||
FLegendItems[AIndex].Draw(id, ricon);
|
FLegendItems[AIndex].Draw(id, ricon);
|
||||||
@ -380,7 +382,8 @@ end;
|
|||||||
procedure TChartListbox.KeyDown(var AKey: Word; AShift: TShiftState);
|
procedure TChartListbox.KeyDown(var AKey: Word; AShift: TShiftState);
|
||||||
{ allows checking/unchecking of items by means of pressing the space bar }
|
{ allows checking/unchecking of items by means of pressing the space bar }
|
||||||
begin
|
begin
|
||||||
if (AKey = VK_SPACE) and (AShift = []) and FShowCheckboxes then begin
|
if (AKey = VK_SPACE) and (AShift = []) and (cloShowCheckboxes in Options) then
|
||||||
|
begin
|
||||||
ClickedCheckbox(ItemIndex);
|
ClickedCheckbox(ItemIndex);
|
||||||
AKey := VK_UNKNOWN;
|
AKey := VK_UNKNOWN;
|
||||||
end
|
end
|
||||||
@ -401,7 +404,7 @@ procedure TChartListbox.MeasureItem(AIndex: Integer; var AHeight: Integer);
|
|||||||
begin
|
begin
|
||||||
Unused(AIndex);
|
Unused(AIndex);
|
||||||
AHeight := CalculateStandardItemHeight;
|
AHeight := CalculateStandardItemHeight;
|
||||||
if FShowCheckboxes then
|
if cloShowCheckboxes in Options then
|
||||||
AHeight := Max(AHeight, GetSystemMetrics(SM_CYMENUCHECK) + 2);
|
AHeight := Max(AHeight, GetSystemMetrics(SM_CYMENUCHECK) + 2);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -428,9 +431,9 @@ begin
|
|||||||
index := GetIndexAtXY(AX, AY);
|
index := GetIndexAtXY(AX, AY);
|
||||||
if index < 0 then exit;
|
if index < 0 then exit;
|
||||||
CalcRects(ItemRect(index), rcb, ricon);
|
CalcRects(ItemRect(index), rcb, ricon);
|
||||||
if FShowCheckboxes and IsPointInRect(p, rcb) then
|
if (cloShowCheckboxes in Options) and IsPointInRect(p, rcb) then
|
||||||
ClickedCheckbox(index)
|
ClickedCheckbox(index)
|
||||||
else if FShowSeriesIcons and IsPointInRect(p, ricon) then
|
else if (cloShowIcons in Options) and IsPointInRect(p, ricon) then
|
||||||
// Remember clicked index for the double click event.
|
// Remember clicked index for the double click event.
|
||||||
FSeriesIconClicked := index
|
FSeriesIconClicked := index
|
||||||
else
|
else
|
||||||
@ -553,17 +556,10 @@ begin
|
|||||||
Populate;
|
Populate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TChartListbox.SetShowCheckboxes(AValue: Boolean);
|
procedure TChartListbox.SetOptions(AValue: TChartListOptions);
|
||||||
begin
|
begin
|
||||||
if FShowCheckboxes = AValue then exit;
|
if FOptions = AValue then exit;
|
||||||
FShowCheckboxes := AValue;
|
FOptions := AValue;
|
||||||
Invalidate;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TChartListbox.SetShowSeriesIcons(AValue: Boolean);
|
|
||||||
begin
|
|
||||||
if FShowSeriesIcons = AValue then exit;
|
|
||||||
FShowSeriesIcons := AValue;
|
|
||||||
Invalidate;
|
Invalidate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user