📄 teesubchart.pas
字号:
class function TSubChartTool.LongDescription: String;
begin
result:=TeeMsg_SubChartDesc;
end;
procedure TSubChartEditor.FormShow(Sender: TObject);
var t : Integer;
begin
Tool:=TSubChartTool(Tag);
LBCharts.Items.Clear;
if Assigned(Tool) then
begin
for t:=0 to Tool.Charts.Count-1 do
if Tool.Charts[t].Chart.Name='' then
LBCharts.Items.Add('Chart'+IntToStr(t+1))
else
LBCharts.Items.Add(Tool.Charts[t].Chart.Name);
end;
if LBCharts.Items.Count>0 then
LBCharts.ItemIndex:=0;
LBChartsClick(Self);
end;
procedure TSubChartTool.SetCharts(const Value: TChartCollection);
begin
FCharts.Assign(Value);
end;
procedure TSubChartTool.SetParentChart(const Value: TCustomAxisPanel);
begin
inherited;
Repaint;
end;
function TSubChart.GetBounds: TRect;
begin
result:=Chart.BoundsRect;
end;
procedure TSubChart.SetChart(const Value: TChart);
begin
Chart.Assign(Value);
end;
{$IFNDEF CLR}
type
TOwnedCollectionAccess=class(TOwnedCollection);
{$ENDIF}
{ TSubChart }
Constructor TSubChart.Create(Collection: TCollection);
begin
inherited;
if Assigned(Collection) then
{$IFDEF CLR}
ITool:=TSubChartTool(Collection.Owner);
{$ELSE}
ITool:=TSubChartTool(TOwnedCollectionAccess(Collection).GetOwner);
{$ENDIF}
if (not Assigned(ITool)) or
(not (csLoading in ITool.ComponentState)) then
GetChart;
end;
Destructor TSubChart.Destroy;
begin
FreeAndNil(FChart);
inherited;
end;
procedure TSubChart.Assign(Source: TPersistent);
begin
if Source is TSubChart then
Chart.Assign(TSubChart(Source).Chart);
inherited;
end;
procedure TSubChartEditor.LBChartsClick(Sender: TObject);
begin
// First thing to do is to enable pagecontrol tabs, etc.
EnableButtons;
// Then recreate editor panel
FreeAndNil(ChartEditor);
if LBCharts.ItemIndex<>-1 then
begin
ChartEditor:=TChartEditorPanel.Create(Self);
ChartEditor.Editor.Tree.Hide;
ChartEditor.Align:=alClient;
ChartEditor.Parent:=TabChart;
ChartEditor.Chart:=CurrentChart.Chart;
with CurrentChart.Chart do
begin
UDLeft.Position:=Left;
UDTop.Position:=Top;
UDWidth.Position:=Width;
UDHeight.Position:=Height;
CBTransp.Checked:=Color=clNone;
end;
if Showing then
PageControl1Change(Self);
end;
end;
function TSubChart.GetHeight: Integer;
begin
result:=Chart.Height;
end;
function TSubChart.GetLeft: Integer;
begin
result:=Chart.Left;
end;
function TSubChart.GetTop: Integer;
begin
result:=Chart.Top;
end;
function TSubChart.GetWidth: Integer;
begin
result:=Chart.Width;
end;
procedure TSubChart.SetHeight(const Value: Integer);
begin
Chart.Height:=Value;
end;
procedure TSubChart.SetLeft(const Value: Integer);
begin
Chart.Left:=Value;
end;
procedure TSubChart.SetTop(const Value: Integer);
begin
Chart.Top:=Value;
end;
procedure TSubChart.SetWidth(const Value: Integer);
begin
Chart.Width:=Value;
end;
procedure TSubChart.ReadChart(Stream: TStream);
begin
FreeAndNil(FChart);
GetChart;
FChart:=Stream.ReadComponent(FChart) as TInnerChart;
TInnerChart(FChart).IParent:=Self;
end;
procedure TSubChart.WriteChart(Stream: TStream);
begin
Stream.WriteComponent(Chart);
end;
procedure TSubChart.DefineProperties(Filer: TFiler);
begin
inherited;
Filer.DefineBinaryProperty('InnerChart',ReadChart,WriteChart,True);
end;
{ TChartCollection }
function TChartCollection.AddChart(const AName: String=''): TChart;
begin
result:=(Add as TSubChart).Chart;
result.Name:=AName;
end;
function TChartCollection.Get(Index: Integer): TSubChart;
begin
result:=TSubChart(inherited Items[Index]);
end;
procedure TChartCollection.Put(Index: Integer; const Value: TSubChart);
begin
inherited Items[Index]:=Value;
end;
procedure TSubChartEditor.FormCreate(Sender: TObject);
begin
TeeLoadArrowBitmaps(BUp.Glyph,BDown.Glyph);
end;
procedure TSubChartEditor.BAddClick(Sender: TObject);
var tmp : String;
begin
tmp:='Chart'+IntToStr(Tool.Charts.Count+1);
if InputQuery('New Chart','Chart Name:',tmp) then
begin
(Tool.Charts.Add as TSubChart).Chart.Name:=tmp;
LBCharts.Items.Add(tmp);
LBCharts.ItemIndex:=LBCharts.Items.Count-1;
LBChartsClick(Self);
end;
end;
procedure TSubChartEditor.EnableButtons;
begin
PageControl1.Enabled:=LBCharts.Items.Count>0;
TabPosition.TabVisible:=PageControl1.Enabled;
TabChart.TabVisible:=PageControl1.Enabled;
EnableControls(PageControl1.Enabled,
[UDLeft,UDTop,UDWidth,UDHeight,
LLeft,LTop,LWidth,LHeight]);
BUp.Enabled:=LBCharts.ItemIndex>0;
BDown.Enabled:=LBCharts.ItemIndex<LBCharts.Items.Count-1;
BDelete.Enabled:=LBCharts.ItemIndex<>-1;
BRename.Enabled:=BDelete.Enabled;
end;
function TSubChartEditor.CurrentChart:TSubChart;
begin
result:=Tool.Charts[LBCharts.ItemIndex];
end;
function TSubChartEditor.CurrentChartName:String;
begin
result:=CurrentChart.Chart.Name;
if result='' then
result:='Chart'+IntToStr(LBCharts.ItemIndex+1);
end;
procedure TSubChartEditor.BDeleteClick(Sender: TObject);
begin
if TeeYesNoDelete(CurrentChartName) then
begin
CurrentChart.Free;
LBCharts.Items.Delete(LBCharts.ItemIndex);
LBChartsClick(Self);
end;
end;
procedure TSubChartEditor.SwapChart(A,B:Integer);
var tmp : TSubChart;
begin
LBCharts.Items.Exchange(A,B);
tmp:=Tool.Charts[B];
Tool.Charts[A].Index:=B;
tmp.Index:=A;
EnableButtons;
end;
procedure TSubChartEditor.BUpClick(Sender: TObject);
begin
with LBCharts do
if ItemIndex>0 then
SwapChart(ItemIndex,ItemIndex-1);
end;
procedure TSubChartEditor.BDownClick(Sender: TObject);
begin
with LBCharts do
if (ItemIndex<>-1) and (ItemIndex<Items.Count-1) then
SwapChart(ItemIndex,ItemIndex+1);
end;
procedure TSubChartEditor.Edit1Change(Sender: TObject);
begin
if Showing then
CurrentChart.Chart.Left:=UDLeft.Position;
end;
procedure TSubChartEditor.Edit2Change(Sender: TObject);
begin
if Showing then
CurrentChart.Chart.Top:=UDTop.Position;
end;
procedure TSubChartEditor.Edit3Change(Sender: TObject);
begin
if Showing then
CurrentChart.Chart.Width:=UDWidth.Position;
end;
procedure TSubChartEditor.Edit4Change(Sender: TObject);
begin
if Showing then
CurrentChart.Chart.Height:=UDHeight.Position;
end;
procedure TInnerChart.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
begin
inherited;
Invalidate;
end;
procedure TSubChartEditor.PageControl1Change(Sender: TObject);
begin
if PageControl1.ActivePage=TabChart then
if TabChart.Controls[0] is TChartEditorPanel then
begin
TabChart.Controls[0].Show;
TChartEditorPanel(TabChart.Controls[0]).Editor.Show;
end;
end;
procedure TSubChartEditor.BRenameClick(Sender: TObject);
var tmp : String;
begin
tmp:=CurrentChartName;
if InputQuery('Rename Chart','New name',tmp) then
begin
CurrentChart.Chart.Name:=tmp;
LBCharts.Items[LBCharts.ItemIndex]:=tmp;
end;
end;
procedure TSubChartEditor.CBTranspClick(Sender: TObject);
begin
if CBTransp.Checked then
begin
CurrentChart.Chart.Color:=clNone;
CurrentChart.Chart.Gradient.Visible:=False;
end
else
CurrentChart.Chart.Color:=clBtnFace;
end;
initialization
RegisterClass(TInnerChart);
RegisterClass(TSubChartEditor);
RegisterTeeTools([TSubChartTool]);
finalization
UnRegisterTeeTools([TSubChartTool]);
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -