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

📄 teegallerypanel.pas

📁 第三方控件:PaintGrid.pas 网格型仪表控件源文件 Mymeter.pas 圆型仪表控件源文件 Project1是这两个控件的使用范例。 该
💻 PAS
📖 第 1 页 / 共 3 页
字号:
    tmpCol : Integer;
    tmpRow : Integer;
    R      : TRect;
begin
  if (NumCols>0) and (NumRows>0) then
  begin
    GetChartXY(AChart,tmpCol,tmpRow);
    tmp:=BevelWidth+BorderWidth;
    With R do
    begin
      Left:=tmp+(tmpCol*ColWidth);
      Top:=tmp+(tmpRow*RowHeight)-TopOffset;
      Right:=Left+Math.Min(ColWidth,Width-tmp)-1;
      Bottom:=Top+Math.Min(RowHeight,Height-tmp)-1;
    end;
    AChart.BoundsRect:=R;
    AChart.CheckShowLabels;
  end;
end;

Procedure TChartGalleryPanel.ShowSelectedChart;
var t : Integer;
begin
  if not Assigned(SelectedChart) then
     for t:=Charts.Count-1 downto 0 do
         if Charts[t].Cursor<>TeeCursorDisabled then
            ISelectedChart:=Charts[t];

  if Assigned(SelectedChart) then
  begin
    SelectedChart.Focus(FView3D);
    if Assigned(FOnChangeChart) then OnChangeChart(Self);
  end;

  for t:=0 to Charts.Count-1 do
      if Charts[t]<>SelectedChart then Charts[t].UnFocus(FView3D);
end;

procedure TChartGalleryPanel.FindSelectedChart;
var t : Integer;
begin
  ISelectedChart:=nil;
  if Assigned(SelectedSeries) then
    for t:=0 to Charts.Count-1 do
    With Charts[t].Series[0] do
    if (ClassType=SelectedSeries.ClassType) and (FunctionType=nil) then
    begin
      ISelectedChart:=Charts[t];
      break;
    end;
end;

procedure TChartGalleryPanel.ChartKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  KeyDown(Key,Shift);
end;

procedure TChartGalleryPanel.SubKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key=TeeKey_Escape then tmpSub.ModalResult:=mrCancel
                       else tmpG.KeyDown(Key,Shift);
end;

procedure TChartGalleryPanel.SubSelected(Sender: TObject);
var t   : Integer;
    tmpClass : TChartSeriesClass;
    tmpNum   : Integer;
begin
  With SelectedChart do
  begin
    Tag:={$IFDEF CLR}Variant{$ENDIF}(tmpG.Charts.IndexOf(tmpG.SelectedChart));

    if Tag=0 then
    begin
      tmpClass:=TChartSeriesClass(Series[0].ClassType);
      tmpNum:=SeriesCount;
      FreeAllSeries;
      for t:=1 to tmpNum do CreateNewSeries(nil,SelectedChart,tmpClass);
      TSeriesAccess(Series[0]).GalleryChanged3D(tmpG.View3D);
      for t:=0 to SeriesCount-1 do
          TSeriesAccess(Series[t]).PrepareForGallery(True);
    end
    else
    for t:=0 to SeriesCount-1 do
        TSeriesAccess(Series[t]).SetSubGallery(Series[t],Tag);
  end;
  tmpSub.ModalResult:=mrOk;
end;

procedure TChartGalleryPanel.SubPaintBox(Sender:TObject);
begin
  With TPaintBox(Sender).Canvas do
  begin
    Brush.Color:=clBlack;
    Pen.Style:=psClear;
    Polygon([TeePoint(0,8),TeePoint(4,0),TeePoint(9,8)]);
  end;
end;

procedure TChartGalleryPanel.SubPanelClick(Sender:TObject);
begin
  tmpSub.ModalResult:=mrOk;
end;

Procedure TChartGalleryPanel.AddSubCharts(AGallery:TChartGalleryPanel);
begin
  tmpG:=AGallery;
  tmpType:=TTeeSeriesType.Create;
  try
    tmpType.SeriesClass:=TChartSeriesClass(tmpSeries.ClassType);
    tmpType.NumGallerySeries:=1;
    tmpType.FunctionClass:=nil;
    AGallery.Charts.Clear;
    TSeriesAccess(tmpSeries).CreateSubGallery(CreateSubChart);
  finally
    tmpType.Free;
  end;
end;

Procedure TChartGalleryPanel.CreateSubGallery(AGallery:TChartGalleryPanel; AClass:TChartSeriesClass);
var tmpN : Integer;
begin
  tmpSeries:=AClass.Create(nil);
  try
    AddSubCharts(AGallery);

    { calculate charts width and height }
    AGallery.CalcChartWidthHeight;
    tmpN:=AGallery.Charts.Count div AGallery.NumCols;
    if AGallery.Charts.Count mod AGallery.NumCols > 0 then Inc(tmpN);
    AGallery.Parent.Height:=8+AGallery.FRowHeight*tmpN;
    AGallery.NumRows:=tmpN;
  finally
    tmpSeries.Free;
  end;
end;

procedure TChartGalleryPanel.ShowSubGallery;
var tmp      : TPoint;
    tmpPos   : Integer;
    tmpPanel : TPanel;
    tmpPaint : TPaintBox;
begin
  if Assigned(tmpSub) then FreeAndNil(tmpSub);

  SelectedChart.UnFocus(FView3D);
  tmp:=ClientToScreen(TeePoint(SelectedChart.Left,SelectedChart.Top+SelectedChart.Height));

  tmpSub:=TForm.Create(Self);
  try
    With tmpSub do
    begin
      Position := poDesigned;   // 7.05 TV52010967
      BorderStyle:=TeeFormBorderStyle;
      Left:=tmp.X;
      Top:=tmp.Y;
      KeyPreview:=True;
      OnKeyDown:=SubKeyDown;
    end;

    { top panel }
    tmpPanel:=TPanel.Create(tmpSub);
    tmpPanel.Align:=alTop;
    tmpPanel.Caption:='';
    tmpPanel.Height:=12;
    tmpPanel.Parent:=tmpSub;
    tmpPanel.OnClick:=SubPanelClick;

    { paintbox to paint small arrow at top panel }
    tmpPaint:=TPaintBox.Create(tmpSub);
    tmpPaint.Parent:=tmpPanel;
    tmpPaint.BoundsRect:=TeeRect(4,2,12,10);
    tmpPaint.OnClick:=SubPanelClick;
    tmpPaint.OnPaint:=SubPaintBox;

    { gallery }
    tmpG:=TChartGalleryPanel.Create(tmpSub);
    tmpG.View3D:=View3D;
    tmpG.OnSelectedChart:=SubSelected;
    tmpG.DisplaySub:=False;
    tmpG.Smooth:=Smooth;
    tmpG.Align:=alClient;
    tmpG.Parent:=tmpSub;
    tmpG.ISubGallery:=True;

    { 5.02 Align:=alClient seems to fail if tmpSub.Parent is nil? }
    tmpG.Height:=tmpSub.Height;

    CreateSubGallery(tmpG,TChartSeriesClass(SelectedChart[0].ClassType));

    tmpG.ShowSelectedChart;

    { check if the sub-gallery is far over the right side of screen }
    tmpPos:={$IFDEF CLX}Screen.Width{$ELSE}
            {$IFNDEF D6}Screen.Width{$ELSE}Screen.WorkAreaRect.Right{$ENDIF}
            {$ENDIF};
    if tmpSub.BoundsRect.Right > tmpPos then { 5.02 }
    begin
      tmpSub.Left:=tmpPos-tmpSub.Width-2; { move it to left }
    end;

    { check if the sub-gallery is far over the bottom side of screen }
    tmpPos:={$IFDEF CLX}Screen.Height{$ELSE}
            {$IFNDEF D6}Screen.Height{$ELSE}Screen.WorkAreaRect.Bottom{$ENDIF}
            {$ENDIF};
    if tmpSub.BoundsRect.Bottom > tmpPos then { 5.02 }
    begin
      tmpSub.Top:=tmpPos-tmpSub.Height-2; { move it to top }
    end;

    if tmpSub.ShowModal=mrOk then
       if Assigned(FOnSubSelected) then FOnSubSelected(Self);
  finally
    FreeAndNil(tmpSub);
  end;

  ShowSelectedChart;
end;

procedure TChartGalleryPanel.ChartEvent(Sender: TObject);
begin
  if Sender is TGalleryChart then
     SelectChart(TGalleryChart(Sender));
end;

function TChartGalleryPanel.ClickedArrow(const P:TPoint):Boolean;
var PArrow : TPoint;
begin
  PArrow:=SelectedChart.ArrowOrigin;
  result:=PointInRect(TeeRect(PArrow.X,PArrow.Y-12,PArrow.X+12,PArrow.Y), P);
end;

function TChartGalleryPanel.GetChart(Index:Integer):TGalleryChart;
begin
  result:=Charts[Index];
end;

procedure TChartGalleryPanel.SelectChart(Chart: TGalleryChart);
begin
  if Chart<>ISelectedChart then
  begin
    ISelectedChart:=Chart;
    ShowSelectedChart;
  end;

  if DisplaySub and ClickedArrow(SelectedChart.GetCursorPos) then
       ShowSubGallery;
end;

procedure TChartGalleryPanel.SetView3D(Value:Boolean);
var t : Integer;
begin
  if Value<>FView3D then
  begin
    FView3D:=Value;
    for t:=0 to Charts.Count-1 do
    begin
      TSeriesAccess(Charts[t].Series[0]).GalleryChanged3D(FView3D);
      Charts[t].SetMargins;
    end;
  end;
end;

procedure TChartGalleryPanel.SetSmooth(Value:Boolean);
var t : Integer;
begin
  if not (csReading in ComponentState) then
  if Value<>FSmooth then
  begin
    FSmooth:=Value;
    for t:=0 to Charts.Count-1 do Charts[t].Smooth:=FSmooth;
  end;
end;

Procedure TChartGalleryPanel.CreateChartList(ASeriesList:Array of TChartSeriesClass);
var t     : Integer;
    AType : TTeeSeriesType;
begin
  Charts.Clear;

  for t:=Low(ASeriesList) to High(ASeriesList) do
  begin
    AType:=TeeSeriesTypes.Find(ASeriesList[t]);
    if Assigned(AType) then CreateChart(AType);
  end;

  FindSelectedChart;
  ShowSelectedChart;
end;

Procedure TChartGalleryPanel.ResizeCharts;
var t : Integer;
begin
  CalcChartWidthHeight;
  if Assigned(Charts) then
     for t:=0 to Charts.Count-1 do ResizeChart(Charts[t]);
end;

procedure TChartGalleryPanel.Resize;
begin
  inherited;
  ResizeCharts;
end;

Function TChartGalleryPanel.ValidSeries(Const ASeriesType:TTeeSeriesType; Const APage:String):Boolean;
begin
  result:= (ASeriesType.GalleryPage{$IFNDEF CLR}^{$ENDIF}=APage) and
           (
             (FunctionsVisible and Assigned(ASeriesType.FunctionClass)) or
             ((not FunctionsVisible) and (not Assigned(ASeriesType.FunctionClass)))

           );
end;

Function TChartGalleryPanel.CreateSubChart(Const ATitle:String):TCustomAxisPanel;
var tmp : Integer;
begin
  tmpType.Description:={$IFNDEF CLR}@{$ENDIF}ATitle;
  tmp:=tmpG.Charts.Count;
  result:=tmpG.CreateChart(tmpType);
  TSeriesAccess(tmpSeries).SetSubGallery(result[0],tmp);
  result.Tag:=tmp;
end;

Procedure TChartGalleryPanel.CreateGalleryPage(Const PageName:String);

  Function CalcCount:Integer;
  var t : Integer;
  begin
    result:=0;
    With TeeSeriesTypes do
    for t:=0 to Count-1 do
        if ValidSeries(Items[t],PageName) then Inc(result);
  end;

Var tmp      : TTeeSeriesType;
    tmpCount : Integer;
    t        : Integer;
begin
  tmpCount:=CalcCount;

  if tmpCount>((NumRows-1)*NumCols) then   //MM July 05, correct recount of rows was failing
     FNumRows:=1+((tmpCount-1) div NumCols)
  else
     FNumRows:=TeeGalleryNumRows;

  CalcChartWidthHeight;

  Charts.Clear;

  With TeeSeriesTypes do
  for t:=0 to Count-1 do
  begin
    tmp:=Items[t];
    if ValidSeries(tmp,PageName) then
       CreateChart(tmp);
  end;

  FindSelectedChart;
  ShowSelectedChart;
end;

{$IFNDEF CLX}
procedure TChartGalleryPanel.WMGetDlgCode(var Message: TWMGetDlgCode);
begin
  Message.Result := DLGC_WANTARROWS;
end;
{$ENDIF}

Function TChartGalleryPanel.GetSeriesClass( Var tmpClass:TChartSeriesClass;
                                            Var tmpFunctionClass:TTeeFunctionClass;
                                            Var SubIndex:Integer):Boolean;
begin
  result:=Assigned(SelectedChart);

  if result then
  begin
    tmpSeries:=SelectedChart.Series[0];
    tmpClass:=TChartSeriesClass(tmpSeries.ClassType);

    if Assigned(tmpSeries) and Assigned(tmpSeries.FunctionType) then
       tmpFunctionClass:=TTeeFunctionClass(tmpSeries.FunctionType.ClassType)
    else
       tmpFunctionClass:=nil;

    SubIndex:=SelectedChart.Tag;
  end;
end;

procedure TChartGalleryPanel.UseTheme(Theme: TChartThemeClass);
var t  : Integer;
    tt : Integer;
    tmp : TChartTheme;
begin
  if Assigned(Theme) then
  begin
    tmp:=Theme.Create(nil);
    try
      for t:=0 to Charts.Count-1 do
      begin
        tmp.Chart:=Charts[t];
        tmp.Apply;
        for tt:=0 to Charts[t].SeriesCount-1 do
            TSeriesAccess(Charts[t][tt]).PrepareForGallery(True);
      end;
    finally
      tmp.Free;
    end;
  end;
end;

initialization
  RegisterTeeStandardSeries;
end.

⌨️ 快捷键说明

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