⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 teesubchart.pas

📁 BCB第三方组件
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{**********************************************}
{   TeeChart - TSubChartTool                   }
{   Copyright (c) 2006-2007 by David Berneda   }
{**********************************************}
unit TeeSubChart;
{$I TeeDefs.inc}

interface

uses
  {$IFNDEF LINUX}
  Windows, Messages,
  {$ENDIF}
  SysUtils, Classes,
  {$IFDEF CLX}
  QGraphics, QControls, QForms, QDialogs, QComCtrls, QExtCtrls, 
  QStdCtrls, QButtons,
  {$ELSE}
  Graphics, Controls, Forms, Dialogs, ExtCtrls, ComCtrls,
  StdCtrls, Buttons,
  {$ENDIF}
  {$IFDEF D6}
  Types,
  {$ENDIF}
  TeCanvas, TeEngine, Chart, TeeTools, TeeProcs, TeeEdit;

type
  TSubChart=class(TCollectionItem)
  private
    FChart : TChart;

    ITool  : TTeeCustomTool;

    function GetBounds:TRect;
    function GetChart:TChart;
    function GetHeight: Integer;
    function GetLeft: Integer;
    function GetTop: Integer;
    function GetWidth: Integer;
    procedure ReadChart(Stream: TStream);
    procedure SetChart(const Value: TChart);
    procedure SetHeight(const Value: Integer);
    procedure SetLeft(const Value: Integer);
    procedure SetTop(const Value: Integer);
    procedure SetWidth(const Value: Integer);
    procedure WriteChart(Stream: TStream);
  protected
    procedure DefineProperties(Filer: TFiler); override;
  public
    Constructor Create(Collection:TCollection); {$IFDEF D5}overload;{$ENDIF} override;
    Destructor Destroy; override;

    procedure Assign(Source:TPersistent); override;

    property Bounds:TRect read GetBounds;
  published
    property Chart:TChart read GetChart write SetChart stored False;
    property Height:Integer read GetHeight write SetHeight;
    property Left:Integer read GetLeft write SetLeft;
    property Top:Integer read GetTop write SetTop;
    property Width:Integer read GetWidth write SetWidth;
  end;

  TChartCollection=class(TOwnedCollection)
  private
    Function Get(Index:Integer):TSubChart;
    Procedure Put(Index:Integer; Const Value:TSubChart);
  public
    function AddChart(const AName:String=''):TChart;

    property Items[Index:Integer]:TSubChart read Get write Put; default;
  end;

  TSubChartTool=class(TTeeCustomTool)
  private
    FCharts : TChartCollection;
    procedure SetCharts(const Value: TChartCollection);
  protected
    Procedure ChartEvent(AEvent:TChartToolEvent); override;
    Procedure ChartMouseEvent( AEvent: TChartMouseEvent;
                               Button:TMouseButton;
                               Shift: TShiftState; X, Y: Integer); override;

    class Function GetEditorClass:String; override;
    procedure SetParentChart(const Value: TCustomAxisPanel); override;
  public
    Constructor Create(AOwner:TComponent); override;
    Destructor Destroy; override;

    procedure Assign(Source:TPersistent); override;
    class Function Description:String; override;
    class Function LongDescription:String; override;
  published
    property Active;
    property Charts:TChartCollection read FCharts write SetCharts;
  end;

  TSubChartEditor = class(TForm)
    Panel1: TPanel;
    LBCharts: TListBox;
    PageControl1: TPageControl;
    TabPosition: TTabSheet;
    TabChart: TTabSheet;
    LLeft: TLabel;
    Edit1: TEdit;
    UDLeft: TUpDown;
    LTop: TLabel;
    Edit2: TEdit;
    UDTop: TUpDown;
    LWidth: TLabel;
    Edit3: TEdit;
    UDWidth: TUpDown;
    LHeight: TLabel;
    Edit4: TEdit;
    UDHeight: TUpDown;
    Panel2: TPanel;
    BUp: TSpeedButton;
    BDown: TSpeedButton;
    Panel3: TPanel;
    BAdd: TButton;
    BDelete: TButton;
    BRename: TButton;
    Panel4: TPanel;
    Panel5: TPanel;
    CBTransp: TCheckBox;
    procedure FormShow(Sender: TObject);
    procedure LBChartsClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure BAddClick(Sender: TObject);
    procedure BDeleteClick(Sender: TObject);
    procedure BUpClick(Sender: TObject);
    procedure BDownClick(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure Edit2Change(Sender: TObject);
    procedure Edit3Change(Sender: TObject);
    procedure Edit4Change(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure BRenameClick(Sender: TObject);
    procedure CBTranspClick(Sender: TObject);
  private
    { Private declarations }
    ChartEditor : TChartEditorPanel;
    Tool : TSubChartTool;

    function CurrentChart:TSubChart;
    function CurrentChartName:String;
    procedure EnableButtons;
    procedure SwapChart(A,B:Integer);
  public
    { Public declarations }
  end;

implementation

{$IFNDEF CLX}
{$IFNDEF LCL}
{$R *.DFM}
{$ENDIF}
{$ELSE}
{$R *.xfm}
{$ENDIF}

uses
  TeePenDlg, TeeProCo;
  
type
  TInnerChart=class(TChart)
  private
    IParent : TSubChart;
  protected
    procedure ReadState(Reader: TReader); override;

  {$IFDEF CLR}
  public
  {$ENDIF}
    
    Function GetParentComponent: TComponent; override;
    Function HasParent:Boolean; override;
    procedure SetParentComponent(AParent: TComponent); override;
  public
    Constructor Create(AOwner:TComponent); override;

    procedure Invalidate; override;
    procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
  published
    property BevelOuter default bvNone;
    property Color default clNone;
    property MarginBottom default 0;
    property MarginLeft default 0;
    property MarginRight default 0;
    property MarginTop default 0;
  end;

{ TInnerChart }

Constructor TInnerChart.Create(AOwner:TComponent);
begin
  inherited;

  Legend.Hide;
  Title.Hide;
  Foot.Hide;
  SubTitle.Hide;
  SubFoot.Hide;

  MarginLeft:=0;
  MarginTop:=0;
  MarginRight:=0;
  MarginBottom:=0;

  BevelOuter:=bvNone;
  Color:=clNone;
end;

procedure TInnerChart.Invalidate;
begin
  if Assigned(IParent) then
     IParent.ITool.Repaint;
end;

function TInnerChart.HasParent: Boolean;
begin
  result:=True;
end;

procedure TInnerChart.ReadState(Reader: TReader);
begin
  inherited;

  if Reader.Parent is TSubChartTool then
     SetParentComponent(TSubChartTool(Reader.Parent));
end;

function TInnerChart.GetParentComponent: TComponent;
begin
  result:=IParent.ITool;
end;

procedure TInnerChart.SetParentComponent(AParent: TComponent);
begin
  if Assigned(AParent) and (AParent is TSubChartTool) then
     if (not Assigned(IParent)) or
        (IParent.ITool<>AParent) or
        (Assigned(IParent) and (IParent.FChart<>Self)) then
     begin
       Self.IParent.ITool:=TSubChartTool(AParent);
       FreeAndNil(IParent.FChart);
       IParent.FChart:=Self;
     end;
end;

{ TSubChart }

Constructor TSubChartTool.Create(AOwner: TComponent);
begin
  inherited;
  FCharts:=TChartCollection.Create(Self,TSubChart);
end;

Destructor TSubChartTool.Destroy;
begin
  FCharts.Free;
  inherited;
end;

procedure TSubChartTool.Assign(Source: TPersistent);
begin
  if Source is TSubChartTool then
  with TSubChartTool(Source) do
  begin
    Self.Charts:=Charts;
  end;

  inherited;
end;

procedure TSubChartTool.ChartEvent(AEvent: TChartToolEvent);
var t : Integer;
begin
  inherited;

  if Active and (AEvent=cteAfterDraw) then
     for t:=0 to Charts.Count-1 do
     with Charts[t] do
     begin
       // NOT A GOOD IDEA: Chart.View3D:=Self.ParentChart.View3D;

       Chart.BufferedDisplay:=False;
       Chart.Draw(Self.ParentChart.Canvas.ReferenceCanvas,Bounds);
     end;
end;

type
  TChartAccess=class(TChart);

procedure TSubChartTool.ChartMouseEvent(AEvent: TChartMouseEvent;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var t : Integer;
begin
  if Active then
  begin

    for t:=0 to Charts.Count-1 do
    with Charts[t] do
    begin
      if PtInRect(Bounds,TeePoint(X,Y)) then
      begin
        Chart.Canvas.ReferenceCanvas:=Self.ParentChart.Canvas.ReferenceCanvas;

        case AEvent of
          cmeDown: TChartAccess(FChart).MouseDown(Button,Shift,X,Y);
          cmeMove: TChartAccess(FChart).MouseMove(Shift,X,Y);
            cmeUp: TChartAccess(FChart).MouseUp(Button,Shift,X,Y);
        end;

        Self.ParentChart.CancelMouse:=FChart.CancelMouse or FChart.Zoom.Active
                                      or FChart.IPanning.Active;

        if Self.ParentChart.CancelMouse then
           break;
      end;
    end;

  end
  else inherited;
end;

function TSubChart.GetChart:TChart;
begin
  if not Assigned(FChart) then
  begin
    FChart:=TInnerChart.Create(nil);
    TInnerChart(FChart).IParent:=Self;
    FChart.BoundsRect:=TeeRect(50,50,200,150);
  end;

  result:=FChart;
end;

class function TSubChartTool.Description: String;
begin
  result:=TeeMsg_SubChartTool;
end;

class function TSubChartTool.GetEditorClass: String;
begin
  result:='TSubChartEditor';
end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -