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

📄 teegallerypanel.pas

📁 Delphi TeeChartPro.6.01的源代码
💻 PAS
📖 第 1 页 / 共 2 页
字号:
  result.AutoRepaint:=False;
  {$ENDIF}

  Charts.Add(result);

  With TGalleryChart(result) do
  begin
    tmpDesc:=AType.Description^;
    tmpNum:=TeeNumFields(tmpDesc,#13);
    for t:=1 to tmpNum do
        Title.Text.Add(TeeExtractField(tmpDesc,t,#13));

    Parent:=Self;
    Name:=TeeGetUniqueName(Owner,TeeMsg_GalleryChartName);
    ResizeChart(TGalleryChart(result));

    CreateSeries;
    DisabledSeries:=CheckSeries and
                    Assigned(SelectedSeries) and
                    ( not Series[0].IsValidSourceOf(SelectedSeries) );

    if DisabledSeries then
    begin
      Cursor:=TeeCursorDisabled;
      OriginalCursor:=Cursor;
      OnClick:=nil;
      OnDblClick:=nil;
      Title.Font.Color:=clGray;
      LeftWall.Pen.Color:=clGray;
      BottomWall.Pen.Color:=clGray;
      LeftAxis.Axis.Width:=1;
      LeftAxis.Axis.Color:=clWhite;
      BottomAxis.Axis.Width:=1;
      BottomAxis.Axis.Color:=clWhite;
    end
    else
    begin
      Cursor:=crHandPoint;
      OriginalCursor:=Cursor;
      OnClick:=ChartEvent;
      OnDblClick:=ChartOnDblClick;
      OnEnter:=ChartEvent;
    end;

    TSeriesAccess(Series[0]).GalleryChanged3D(Self.FView3D);

    if AType.FunctionClass=nil then
       for t:=0 to SeriesCount-1 do
           TSeriesAccess(Series[t]).PrepareForGallery(not DisabledSeries)
    else
    begin
      tmpFunc:=AType.FunctionClass.Create(nil);
      try
        TFunctionAccess(tmpFunc).PrepareForGallery(result);  // 6.0
      finally
        tmpFunc.Free;
      end;
    end;

    SetMargins;
    CheckShowLabels;
  end;

  if not ISubGallery then TGalleryChartAccess(result).OnKeyDown:=ChartKeyDown;

  result.AutoRepaint:=True;
end;

procedure TChartGalleryPanel.KeyDown(var Key: Word; Shift: TShiftState);

    { returns the gallery Chart in XY position (Column / Row) }
    Function FindChartXY(x,y:Integer):TGalleryChart;
    var tmpX : Integer;
        tmpY : Integer;
        t    : Integer;
    begin
      for t:=0 to Charts.Count-1 do
      begin
        result:=Charts[t];
        GetChartXY(result,tmpX,tmpY);
        if (x=tmpx) and (y=tmpy) then Exit;
      end;
      result:=nil;
    end;

var x,y : Integer;
    tmp : TGalleryChart;
begin
  inherited;
  GetChartXY(SelectedChart,x,y);
  Case Key of
    TeeKey_Left  : if x>0 then Dec(x);
    TeeKey_Right : if x<NumCols then Inc(x);
    TeeKey_Up    : if y>0 then Dec(y);
    TeeKey_Down  : if ssAlt in Shift then
                   begin
                     if DisplaySub then ShowSubGallery
                   end
                   else if y<NumRows then Inc(y);
    TeeKey_Return: ChartOnDblClick(SelectedChart);
  end;
  tmp:=FindChartXY(x,y);
  if Assigned(tmp) and (tmp.Cursor=crHandPoint) then SelectChart(tmp);
end;

Procedure TChartGalleryPanel.ResizeChart(AChart:TGalleryChart; TopOffset:Integer=0);
var tmp    : Integer;
    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:=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
      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.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;

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

  if DisplaySub then
  begin
    P:=SelectedChart.GetCursorPos;
    if PointInRect(TeeRect(0,SelectedChart.Height-12,12,SelectedChart.Height),
        P.X,P.Y) then ShowSubGallery;
  end;
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.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^=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:=@ATitle;
  tmp:=tmpG.Charts.Count;
  result:=tmpG.CreateChart(tmpType);
  TSeriesAccess(tmpSeries).SetSubGallery(result[0],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*NumCols) then
     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;

initialization
  RegisterTeeStandardSeries;
end.

⌨️ 快捷键说明

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