📄 teegallerypanel.pas
字号:
{*********************************************}
{ TeeChart Gallery Panel }
{ Copyright (c) 1996-2003 by David Berneda }
{*********************************************}
unit TeeGalleryPanel;
{$I TeeDefs.inc}
interface
Uses {$IFNDEF LINUX}
Windows, Messages,
{$ENDIF}
{$IFDEF CLX}
Qt, QControls, QExtCtrls, QForms, QGraphics,
{$ELSE}
Controls, ExtCtrls, Forms, Graphics,
{$ENDIF}
{$IFDEF D6}
Types,
{$ENDIF}
Classes, Chart, TeeProcs, TeEngine;
Const TeeGalleryNumRows=3;
TeeGalleryNumCols=4;
TeeCursorDisabled=crNoDrop;
var clTeeGallery:TColor=clWhite;
TeeGalleryCheckMaximize:Boolean=True; { 5.02 }
type
TGalleryChart=class(TCustomChart)
private
Procedure AfterDraw(Sender:TObject);
{$IFNDEF CLX}
procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
{$ENDIF}
protected
{$IFDEF CLX}
procedure MouseEnter(AControl:TControl); override;
procedure MouseLeave(AControl:TControl); override;
{$ENDIF}
public
Constructor Create(AOwner:TComponent); override;
Procedure CheckShowLabels;
Procedure DrawFrame3D(Erase:Boolean);
Procedure Focus(Is3D:Boolean);
Procedure SetMargins;
Procedure UnFocus(Is3D:Boolean);
end;
TChartList=class(TList)
private
Function GetChart(Index:Integer):TGalleryChart;
public
Procedure Clear; override;
property Items[Index:Integer]:TGalleryChart read GetChart; default;
end;
TChartGalleryPanel=class(TCustomPanelNoCaption)
private
FColWidth : Integer;
FDisplaySub : Boolean;
FNumRows : Integer;
FNumCols : Integer;
FRowHeight : Integer;
FView3D : Boolean;
FOnChangeChart : TNotifyEvent;
FOnSelectedChart : TNotifyEvent;
FOnSubSelected : TNotifyEvent;
tmpSub : TForm;
ISubGallery : Boolean;
ISelectedChart : TGalleryChart;
Procedure ChartEvent(Sender: TObject);
procedure ChartKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
Procedure SetNumCols(Value:Integer);
Procedure SetNumRows(Value:Integer);
Procedure SetView3D(Value:Boolean);
procedure ShowSubGallery;
procedure SubKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure SubPaintBox(Sender:TObject);
procedure SubPanelClick(Sender:TObject);
procedure SubSelected(Sender: TObject);
Function ValidSeries(Const ASeriesType:TTeeSeriesType; Const APage:String):Boolean;
{$IFNDEF CLX}
procedure WMGetDlgCode(var Message: TWMGetDlgCode); message WM_GETDLGCODE;
{$ENDIF}
protected
tmpG : TChartGalleryPanel;
tmpSeries : TChartSeries;
tmpType : TTeeSeriesType; { 5.01 }
Procedure AddSubCharts(AGallery:TChartGalleryPanel);
Procedure CalcChartWidthHeight;
procedure ChartOnDblClick(Sender: TObject);
Function CreateSubChart(Const ATitle:String):TCustomAxisPanel;
Procedure CreateSubGallery(AGallery:TChartGalleryPanel; AClass:TChartSeriesClass);
procedure FindSelectedChart;
Procedure GetChartXY(AChart:TGalleryChart; Var x,y:Integer);
procedure Resize; override;
Procedure ResizeChart(AChart:TGalleryChart; TopOffset:Integer=0);
Procedure ShowSelectedChart;
public
Charts : TChartList;
CheckSeries : Boolean;
FunctionsVisible : Boolean;
SelectedSeries : TChartSeries;
Constructor Create(AOwner:TComponent); override;
Destructor Destroy; override;
procedure SelectChart(Chart: TGalleryChart); virtual;
Function CreateChart(Const AType:TTeeSeriesType):TCustomAxisPanel;
Procedure CreateChartList(ASeriesList:Array of TChartSeriesClass); // BCB does not allow "const"
Procedure CreateGalleryPage(Const PageName:String);
property ColWidth:Integer read FColWidth;
Function GetSeriesClass( Var tmpClass:TChartSeriesClass;
Var tmpFunctionClass:TTeeFunctionClass;
Var SubIndex:Integer):Boolean;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
Procedure ResizeCharts;
property RowHeight:Integer read FRowHeight;
property SelectedChart:TGalleryChart read ISelectedChart write SelectChart;
published
property DisplaySub:Boolean read FDisplaySub write FDisplaySub default True;
property NumRows:Integer read FNumRows write SetNumRows default TeeGalleryNumRows;
property NumCols:Integer read FNumCols write SetNumCols default TeeGalleryNumCols;
property View3D:Boolean read FView3D write SetView3D default True;
{ events }
property OnSelectedChart:TNotifyEvent read FOnSelectedChart write FOnSelectedChart;
property OnChangeChart:TNotifyEvent read FOnChangeChart write FOnChangeChart;
property OnSubSelected:TNotifyEvent read FOnSubSelected write FOnSubSelected;
{ TPanel properties }
property Align;
property BevelInner;
property BevelOuter;
property BevelWidth;
property BorderWidth;
property BorderStyle;
property Color;
{$IFNDEF CLX}
property DragCursor;
{$ENDIF}
property DragMode;
property Enabled;
property ParentColor;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
property Anchors;
{$IFNDEF CLX}
property AutoSize;
{$ENDIF}
property Constraints;
{$IFNDEF CLX}
property DragKind;
property Locked;
{$ENDIF}
{ TPanel events }
property OnClick;
{$IFDEF D5}
property OnContextPopup;
{$ENDIF}
property OnDblClick;
{$IFNDEF CLX}
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnStartDrag;
{$ENDIF}
property OnEnter;
property OnExit;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnConstrainedResize;
{$IFNDEF CLX}
property OnCanResize;
property OnDockDrop;
property OnDockOver;
property OnEndDock;
property OnStartDock;
property OnUnDock;
{$ENDIF}
end;
implementation
Uses Math, SysUtils, TeeConst, TeCanvas, TeePenDlg, Series;
Const clTeeSelected = clSilver; //$0080FFFF; { <-- color use to select charts }
{ TChartList }
Procedure TChartList.Clear;
var t : Integer;
begin
for t:=0 to Count-1 do Items[t].Free;
inherited;
end;
Function TChartList.GetChart(Index:Integer):TGalleryChart;
begin
result:=TGalleryChart(List^[Index]);
end;
{ TGalleryChart }
Constructor TGalleryChart.Create(AOwner:TComponent);
begin
inherited;
Legend.Visible:=False;
LeftAxis.Labels:=False;
BottomAxis.Labels:=False;
Title.Font.Color:=clNavy;
Zoom.Animated:=True;
With View3DOptions do
begin
Orthogonal:=False;
Zoom :=90;
Perspective:=55;
Rotation :=335;
Elevation :=350;
end;
Chart3DPercent:=100;
ClipPoints:=False;
Frame.Visible:=False;
BevelWidth:=2;
BevelOuter:=bvNone;
With LeftWall do
begin
Color:=clWhite;
Size:=4;
Pen.Color:=clDkGray;
end;
With BottomWall do
begin
Color:=clWhite;
Size:=4;
Pen.Color:=clDkGray;
end;
OnAfterDraw:=AfterDraw;
end;
Procedure TGalleryChart.SetMargins;
Var tmp : Integer;
begin
if View3D then tmp:=4 else tmp:=5;
MarginTop :=tmp;
MarginBottom :=tmp;
MarginLeft :=tmp;
MarginRight :=tmp;
end;
Procedure TGalleryChart.DrawFrame3D(Erase:Boolean);
var R : TRect;
begin
if Cursor<>TeeCursorDisabled then
begin
R:=ClientRect;
if Erase then Frame3D(DelphiCanvas,R,clBtnFace,clBtnFace,1)
else Frame3D(DelphiCanvas,R,clWhite,clDkGray,1);
end;
end;
type TSeriesAccess=class(TChartSeries);
Procedure TGalleryChart.Focus(Is3D:Boolean);
begin
With Gradient do
begin
Visible:=True;
Direction:=gdFromTopLeft;
StartColor:=clTeeSelected;
EndColor:=clTeeGallery;
end;
View3DOptions.Rotation:=345;
if SeriesCount>0 then TSeriesAccess(Series[0]).GalleryChanged3D(Is3D);
With Title.Font do
begin
Style:=[fsBold];
Color:=clBlack;
{$IFDEF CLX}
Size:=GetDefaultFontSize+2;
{$ELSE}
Size:=9;
{$ENDIF}
end;
BevelOuter:=bvRaised;
if Showing then SetFocus;
end;
Procedure TGalleryChart.UnFocus(Is3D:Boolean);
begin
if Gradient.Visible then
begin
Gradient.Visible:=False;
BevelOuter:=bvNone;
With Title.Font do
begin
Style:=[];
Color:=clNavy;
Size:=GetDefaultFontSize;
end;
View3DOptions.Rotation:=335;
if SeriesCount>0 then TSeriesAccess(Series[0]).GalleryChanged3D(Is3D);
end;
end;
Procedure TGalleryChart.CheckShowLabels;
Function IsMaximized:Boolean;
{$IFNDEF CLX}
var Placement : TWindowPlacement;
{$ENDIF}
begin
{$IFDEF CLX}
result:=GetParentForm(Self).WindowState=wsMaximized;
{$ELSE}
Placement.length := SizeOf(TWindowPlacement);
GetWindowPlacement(GetParentForm(Self).Handle, @Placement);
result:=Placement.ShowCmd=SW_SHOWMAXIMIZED;
{$ENDIF}
end;
begin
if TeeGalleryCheckMaximize and AxisVisible then
begin
LeftAxis.Labels:=IsMaximized;
BottomAxis.Labels:=LeftAxis.Labels;
end;
end;
{$IFDEF CLX}
procedure TGalleryChart.MouseEnter(AControl:TControl);
{$ELSE}
procedure TGalleryChart.CMMouseEnter(var Message: TMessage);
{$ENDIF}
begin
DrawFrame3D(False);
inherited;
end;
{$IFDEF CLX}
procedure TGalleryChart.MouseLeave(AControl:TControl);
{$ELSE}
procedure TGalleryChart.CMMouseLeave(var Message: TMessage);
{$ENDIF}
begin
DrawFrame3D(True);
inherited;
end;
procedure TGalleryChart.AfterDraw(Sender: TObject);
Const tmpH=6;
tmpStart=4;
tmpW=7;
begin
if Gradient.Visible then
if TChartGalleryPanel(Parent).DisplaySub then
With Canvas do
begin
Pen.Mode:=pmNotXor;
Brush.Style:=bsSolid;
Brush.Color:=clBlack;
Pen.Style:=psClear;
Polygon([TeePoint(tmpStart,Height-tmpH-2),TeePoint(tmpStart+tmpW,Height-tmpH-2),
TeePoint(tmpStart+(tmpW div 2),Height-4)]);
Pen.Mode:=pmCopy;
Pen.Style:=psSolid;
end;
end;
{ TChartGalleryPanel }
Constructor TChartGalleryPanel.Create(AOwner:TComponent);
begin
inherited;
FunctionsVisible:=False;
ISelectedChart:=nil;
SelectedSeries:=nil;
FOnSelectedChart:=nil;
FOnChangeChart:=nil;
Charts:=TChartList.Create;
FView3D:=True;
DisplaySub:=True;
FNumRows:=3;
FNumCols:=4;
end;
Destructor TChartGalleryPanel.Destroy;
begin
Charts.Free;
inherited;
end;
Procedure TChartGalleryPanel.SetNumCols(Value:Integer);
begin
FNumCols:=Value;
ResizeCharts;
end;
Procedure TChartGalleryPanel.SetNumRows(Value:Integer);
begin
FNumRows:=Value;
ResizeCharts;
end;
Procedure TChartGalleryPanel.GetChartXY(AChart:TGalleryChart; Var x,y:Integer);
var tmp : Integer;
begin
tmp:=Charts.IndexOf(AChart);
y:=tmp div NumCols;
x:=tmp mod NumCols;
end;
procedure TChartGalleryPanel.ChartOnDblClick(Sender: TObject);
begin
ISelectedChart:=TGalleryChart(Sender);
if Assigned(FOnSelectedChart) then OnSelectedChart(Self);
end;
Procedure TChartGalleryPanel.CalcChartWidthHeight;
var tmp : Integer;
begin
if (NumRows>0) and (NumCols>0) then
begin
tmp:=BevelWidth+BorderWidth;
FRowHeight:=(Height-tmp) div NumRows;
FColWidth:=(Width-tmp) div NumCols;
end
else
begin
FRowHeight:=0;
FColWidth:=0;
end;
end;
type
TGalleryChartAccess=class(TGalleryChart);
TFunctionAccess=class(TTeeFunction);
Function TChartGalleryPanel.CreateChart(Const AType:TTeeSeriesType):TCustomAxisPanel;
Var tmpClass : TChartSeriesClass;
Procedure CreateSeries;
Var tmp : Integer;
begin
for tmp:=1 to Math.Max(1,AType.NumGallerySeries) do
CreateNewSeries(nil,result,tmpClass,AType.FunctionClass);
end;
var t : Integer;
tmpNum : Integer;
DisabledSeries : Boolean;
tmpFunc : TTeeFunction;
tmpDesc : String;
begin
tmpClass:=AType.SeriesClass;
if not Assigned(tmpClass) then tmpClass:=TLineSeries;
result:=TGalleryChart.Create(Self);
{$IFNDEF CLX}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -