📄 teetools.pas
字号:
property Pen;
property Picture:TTeePicture read FPicture write SetPicture;
property Series;
end;
// A Shape object (with Left and Top), publishing all properties.
TTeeShapePosition=class(TTeeCustomShapePosition)
published
property Bevel;
property BevelWidth;
property Brush;
property Color;
property CustomPosition;
property Font;
property Frame;
property Gradient;
property Left;
property Picture;
property Shadow;
property ShapeStyle;
property Top;
property Transparency;
property Transparent;
property Visible default True;
end;
TAnnotationTool=class;
TAnnotationPosition=(ppLeftTop,ppLeftBottom,ppRightTop,ppRightBottom,ppCenter);
TAnnotationClick=procedure( Sender:TAnnotationTool;
Button:TMouseButton;
Shift: TShiftState;
X, Y: Integer) of object;
TAnnotationCallout=class(TCallout)
private
FX : Integer;
FY : Integer;
FZ : Integer;
Function CloserPoint(const R:TRect; const P:TPoint):TPoint;
procedure SetX(const Value:Integer);
procedure SetY(const Value:Integer);
procedure SetZ(const Value:Integer);
public
constructor Create(AOwner: TChartSeries);
Procedure Assign(Source:TPersistent); override;
published
property Visible default False;
property XPosition:Integer read FX write SetX default 0;
property YPosition:Integer read FY write SetY default 0;
property ZPosition:Integer read FZ write SetZ default 0;
end;
TTextShape=class(TTeeShapePosition)
private
FAutoSize : Boolean;
FClipText : Boolean;
FCursor : TCursor;
FMargins : TMargins;
FTextAlign : TAlignment;
procedure SetAutoSize(const Value: Boolean);
procedure SetClipText(const Value: Boolean);
procedure SetMargins(const Value: TMargins);
procedure SetText(const Value: String);
procedure SetTextAlign(const Value: TAlignment);
protected
FText : String;
{$IFDEF CLR}
public
{$ENDIF}
INumLines : Integer;
procedure CalcBounds(Panel:TCustomAxisPanel);
public
Constructor Create(AOwner: TCustomTeePanel); override;
Destructor Destroy; override;
procedure Assign(Source:TPersistent); override;
procedure DrawText(Panel:TCustomAxisPanel; R:TRect; XOffset, NumLines:Integer);
published
property AutoSize:Boolean read FAutoSize write SetAutoSize default True;
property ClipText:Boolean read FClipText write SetClipText default True;
property Cursor:TCursor read FCursor write FCursor default crDefault;
property Margins:TMargins read FMargins write SetMargins;
property Text:String read FText write SetText;
property TextAlignment:TAlignment read FTextAlign
write SetTextAlign default taLeftJustify;
end;
// Annotation tool, use it to display text anywhere on the chart.
TAnnotationTool=class(TTeeCustomTool)
private
FCallout : TAnnotationCallout;
FOnAfterDraw : TNotifyEvent;
FOnBeforeDraw : TNotifyEvent;
FOnClick : TAnnotationClick;
FOnDblClick: TAnnotationClick;
FPosition : TAnnotationPosition;
FPositionUnits: TTeeUnits;
FShape : TTextShape;
function GetAutoSize:Boolean;
function GetBounds:TRect;
function GetClipText:Boolean;
function GetCursor:TCursor;
function GetHeight: Integer;
function GetLeft: Integer;
function GetTextAlign: TAlignment;
function GetTop: Integer;
function GetWidth: Integer;
function IsNotAutoSize: Boolean;
procedure Repaint;
procedure SetAutoSize(const Value: Boolean);
procedure SetBounds(const Value: TRect);
procedure SetCallout(const Value: TAnnotationCallout);
procedure SetClipText(const Value: Boolean);
procedure SetCursor(const Value:TCursor);
procedure SetHeight(const Value: Integer);
procedure SetLeft(const Value: Integer);
procedure SetPosition(const Value: TAnnotationPosition);
procedure SetPositionUnits(const Value: TTeeUnits);
procedure SetShape(const Value: TTextShape);
procedure SetTextAlign(const Value: TAlignment);
procedure SetTop(const Value: Integer);
procedure SetWidth(const Value: Integer);
protected
function GetXOffset:Integer; virtual;
Procedure ChartEvent(AEvent:TChartToolEvent); override;
Procedure ChartMouseEvent( AEvent: TChartMouseEvent;
Button:TMouseButton;
Shift: TShiftState; X, Y: Integer); override;
Procedure DrawText; overload; virtual;
class Function GetEditorClass:String; override;
Function GetText:String; virtual;
Function GetTextBounds(out NumLines,x,y:Integer):TRect; overload; virtual;
Function GetTextBounds(Panel:TCustomAxisPanel; out NumLines,x,y:Integer):TRect; overload;
Function GetTextBounds(Panel:TCustomAxisPanel; const ABounds:TRect;
out NumLines,x,y:Integer):TRect; overload;
procedure SetParentChart(const Value: TCustomAxisPanel); override;
Procedure SetText(Const Value:String);
public
Constructor Create(AOwner:TComponent); override;
Destructor Destroy; override;
procedure Assign(Source:TPersistent); override;
Function Clicked(x,y:Integer):Boolean;
class Function Description:String; override;
class Function LongDescription:String; override;
property Bounds:TRect read GetBounds write SetBounds;
published
property Active;
property AutoSize:Boolean read GetAutoSize write SetAutoSize default True;
property Callout:TAnnotationCallout read FCallout write SetCallout;
property ClipText:Boolean read GetClipText write SetClipText default True;
property Cursor:TCursor read GetCursor write SetCursor default crDefault;
property Position:TAnnotationPosition read FPosition write SetPosition
default ppLeftTop;
property PositionUnits:TTeeUnits read FPositionUnits write SetPositionUnits
default muPixels;
property Shape:TTextShape read FShape write SetShape;
property Text:String read GetText write SetText;
property TextAlignment:TAlignment read GetTextAlign
write SetTextAlign default taLeftJustify;
property Height: Integer read GetHeight write SetHeight stored IsNotAutoSize;
property Left: Integer read GetLeft write SetLeft stored False;
property Top: Integer read GetTop write SetTop stored False;
property Width: Integer read GetWidth write SetWidth stored IsNotAutoSize;
property OnAfterDraw:TNotifyEvent read FOnAfterDraw write FOnAfterDraw;
property OnBeforeDraw:TNotifyEvent read FOnBeforeDraw write FOnBeforeDraw;
property OnClick:TAnnotationClick read FOnClick write FOnClick;
property OnDblClick:TAnnotationClick read FOnDblClick write FOnDblClick;
end;
TSeriesAnimationTool=class;
TSeriesAnimationStep=procedure(Sender:TSeriesAnimationTool; Step:Integer) of object;
TSeriesAnimationLoop=(salNo, salOneWay, salCircular);
TSeriesAnimationTool=class(TTeeCustomToolSeries)
private
FBackup : TChartSeries;
FDelay : Integer;
FDrawEvery : Integer;
FLoop : TSeriesAnimationLoop;
FStartValue : Double;
FSteps : Integer;
FStartAtMin : Boolean;
{ events }
FOnStart : TNotifyEvent;
FOnStep : TSeriesAnimationStep;
FOnStop : TNotifyEvent;
{ internal }
IStopped : Boolean;
protected
class Function GetEditorClass:String; override;
public
Constructor Create(AOwner:TComponent); override;
class Function Description:String; override;
class Function LongDescription:String; override;
procedure Execute; overload; virtual;
procedure Execute(Sender:TObject); overload;
function Running:Boolean;
procedure Stop;
published
property Active;
property Delay:Integer read FDelay write FDelay default 0;
property DrawEvery:Integer read FDrawEvery write FDrawEvery default 0;
property Loop:TSeriesAnimationLoop read FLoop write FLoop default salNo;
property Series;
property StartAtMin:Boolean read FStartAtMin write FStartAtMin default True;
property StartValue:Double read FStartValue write FStartValue;
property Steps:Integer read FSteps write FSteps default 100;
{ events }
property OnStart:TNotifyEvent read FOnStart write FOnStart;
property OnStep:TSeriesAnimationStep read FOnStep write FOnStep;
property OnStop:TNotifyEvent read FOnStop write FOnStop;
end;
TRectangleTool=class(TAnnotationTool)
private
FAllowDrag : Boolean;
FAllowResize : Boolean;
FOnDragged : TNotifyEvent;
FOnDragging : TNotifyEvent;
FOnResized : TNotifyEvent;
FOnResizing : TNotifyEvent;
P : TPoint;
IDrag : Boolean;
IEdge : Integer;
function GetResizing:Boolean;
protected
Procedure ChartMouseEvent( AEvent: TChartMouseEvent;
Button:TMouseButton;
Shift: TShiftState; X, Y: Integer); override;
public
Constructor Create(AOwner:TComponent); override;
procedure Assign(Source:TPersistent); override;
Function Bitmap(ChartOnly:Boolean=False):TBitmap;
Function ClickedEdge(x,y:Integer):Integer;
class Function Description:String; override;
class Function LongDescription:String; override;
property Dragging:Boolean read IDrag;
property Resizing:Boolean read GetResizing;
published
property AllowDrag:Boolean read FAllowDrag write FAllowDrag default True;
property AllowResize:Boolean read FAllowResize write FAllowResize default True;
property AutoSize default False;
property Cursor default crHandPoint;
property PositionUnits default muPixels;
property OnDragged:TNotifyEvent read FOnDragged write FOnDragged;
property OnDragging:TNotifyEvent read FOnDragging write FOnDragging;
property OnResized:TNotifyEvent read FOnResized write FOnResized;
property OnResizing:TNotifyEvent read FOnResizing write FOnResizing;
end;
TClipSeriesTool=class(TTeeCustomToolSeries)
protected
Procedure SeriesEvent(AEvent:TChartToolEvent); override;
public
class Function Description:String; override;
class Function LongDescription:String; override;
published
property Active;
property Series;
end;
TFullScreenTool=class(TTeeCustomTool)
private
FKey : Word;
OldAlign : TAlign;
OldParent : TWinControl;
OldRChart : TRect;
IFreeForm : Boolean;
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure RemoveFullScreen;
protected
Procedure SetActive(Value:Boolean); override;
public
Constructor Create(AOwner:TComponent); override;
Destructor Destroy; override;
class Function Description:String; override;
class Function LongDescription:String; override;
published
property Active default False;
property ReleaseKey:Word read FKey write FKey default TeeKey_ESCAPE;
end;
implementation
Uses {$IFDEF CLX}
QForms,
{$ELSE}
Forms,
{$ENDIF}
Math, TeeConst, TeeProCo;
{ TCursorTool }
Constructor TCursorTool.Create(AOwner:TComponent);
begin
inherited;
FClick:=TeeClickTolerance;
FStyle:=cssBoth;
IPoint.X:=-1;
IPoint.Y:=-1;
IOldSnap:=-1;
FScopeSize:=4;
end;
procedure TCursorTool.Assign(Source:TPersistent);
begin
if Source is TCursorTool then
with TCursorTool(Source) do
begin
Self.FUseChartRect:=FUseChartRect;
Self.IXValue:=IXValue;
Self.IYValue:=IYValue;
Self.FClick:=FClick;
Self.FFollowMouse:=FFollowMouse;
Self.FHorizSize:=FHorizSize;
Self.FScopeSize:=FScopeSize;
Self.FScopeStyle:=FScopeStyle;
Self.FSnap:=FSnap;
Self.FSnapStyle:=FSnapStyle;
Self.FStyle:=FStyle;
Self.FUseSeriesZ:=FUseSeriesZ;
Self.FVertSize:=FVertSize;
end;
inherited;
end;
Procedure TCursorTool.CalcValuePositions(X,Y:Integer);
begin
if UseSeriesZ then
ParentChart.Canvas.Calculate2DPosition(x,y,Z);
Case IDragging of
ccVertical : IXValue:=GetHorizAxis.CalcPosPoint(X);
ccHorizontal: IYValue:=GetVertAxis.CalcPosPoint(Y);
else
begin
IXValue:=GetHorizAxis.CalcPosPoint(X);
IYValue:=GetVertAxis.CalcPosPoint(Y);
end;
end;
end;
Procedure TCursorTool.CalcScreenPositions;
var tmpSnap : Integer;
begin
if (IPoint.X=-1) or (IPoint.Y=-1) then
begin
With GetHorizAxis do IPoint.X:=(IStartPos+IEndPos) div 2;
With GetVertAxis do IPoint.Y:=(IStartPos+IEndPos) div 2;
CalcValuePositions(IPoint.X,IPoint.Y);
tmpSnap:=SnapToPoint;
CalcScreenPositions;
Changed(tmpSnap);
end
else
begin
IPoint.X:=GetHorizAxis.CalcPosValue(IXValue);
IPoint.Y:=GetVertAxis.CalcPosValue(IYValue);
end;
end;
Procedure TCursorTool.Changed(SnapPoint:Integer);
begin
if Assigned(FOnChange) then
FOnChange(Self,IPoint.X,IPoint.Y,IXValue,IYValue,Series,SnapPoint);
end;
class Function TCursorTool.GetEditorClass:String;
begin
result:='TCursorToolEditor';
end;
class Function TCursorTool.Description:String;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -