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

📄 teegallerypanel.pas

📁 第三方控件:PaintGrid.pas 网格型仪表控件源文件 Mymeter.pas 圆型仪表控件源文件 Project1是这两个控件的使用范例。 该
💻 PAS
📖 第 1 页 / 共 3 页
字号:
      if SeriesCount>0 then
         TSeriesAccess(Series[0]).GalleryChanged3D(Is3D);
    end;
  end;
end;

Procedure TGalleryChart.CheckShowLabels;

  Function IsMaximized:Boolean;
  var tmp : TCustomForm;
  {$IFNDEF CLX}
  var Placement : TWindowPlacement;
  {$ENDIF}
  begin
    tmp:=GetParentForm(Self);
    if Assigned(tmp) then
    begin
      {$IFDEF CLX}
      result:=tmp.WindowState=wsMaximized;
      {$ELSE}
      Placement.length := SizeOf(TWindowPlacement);
      GetWindowPlacement(tmp.Handle, {$IFNDEF LCL}{$IFNDEF CLR}@{$ENDIF}{$ENDIF}Placement);
      result:=Placement.ShowCmd=SW_SHOWMAXIMIZED;
      {$ENDIF}
    end
    else result:=False;
  end;

begin
  if TeeGalleryCheckMaximize and AxisVisible then
  begin
    LeftAxis.Labels:=IsMaximized;
    BottomAxis.Labels:=LeftAxis.Labels;
  end;
end;

{$IFNDEF LCL}

{$IFDEF CLX}
procedure TGalleryChart.MouseEnter(AControl:TControl);
{$ELSE}
procedure TGalleryChart.CMMouseEnter(var Message: TMessage);
{$ENDIF}
begin
  DrawFrame3D(False);
  inherited;
end;

{$IFDEF CLX}
procedure TGalleryChart.MouseLeave(AControl:TControl);
{$ELSE}
procedure TGalleryChart.CMMouseLeave(var Message: TMessage);
{$ENDIF}
begin
  DrawFrame3D(True);
  inherited;
end;

{$ENDIF}

procedure TGalleryChart.SetSmooth(Value:Boolean);
begin
  SetBooleanProperty(FSmooth,Value);

  if not FSmooth then
  begin
    LeftAxis.Labels:=False;
    BottomAxis.Labels:=False;
  end;
end;

Function TGalleryChart.ArrowOrigin:TPoint;
var tmpHeight : Integer;
    tmpStart  : Integer;
begin
  tmpHeight:=0;
  if Border.Visible then Inc(tmpHeight,Border.Width);
  if Shadow.Size>0 then Inc(tmpHeight,Shadow.Size);
  if Smooth then tmpHeight:=tmpHeight div 2;
  result.Y:=Height-tmpHeight;

  tmpStart:=0;
  if Border.Visible then Inc(tmpStart,Border.Width);
  if Smooth then tmpStart:=tmpStart div 2;
  result.X:=4+tmpStart;
end;

procedure TGalleryChart.DrawSubGalleryArrow;
Const tmpH=6;
      tmpW=7;
var P : TPoint;
begin
  P:=ArrowOrigin;

  with Canvas do
  begin
    Pen.Mode:=pmNotXor;

    Brush.Style:=bsSolid;
    Brush.Color:=clBlack;
    Pen.Style:=psClear;

    Polygon([TeePoint(P.X,P.Y-tmpH-2),TeePoint(P.X+tmpW,P.Y-tmpH-2),
             TeePoint(P.X+(tmpW div 2),P.Y-4)]);
    Pen.Mode:=pmCopy;
    Pen.Style:=psSolid;
  end;
end;

procedure TGalleryChart.DrawSmoothChart;
const
  ScaleFactor=4;

var tmp  : TBitmap;
    tmpR : TRect;
    Old  : Boolean;
begin
  if (Width>=ScaleFactor) and (Height>=ScaleFactor) then
  begin
    ICreatingBitmap:=True;

    LeftAxis.Labels:=True;
    BottomAxis.Labels:=True;
    with LeftAxis.LabelsFont do Size:=Size*2; //ScaleFactor;
    with BottomAxis.LabelsFont do Size:=Size*2; //ScaleFactor;

    tmpR:=Title.ShapeBounds;
    Old:=Title.Visible;
    Title.Hide;
    MarginTop:=30;

    tmp:=TeeCreateBitmap(Color,TeeRect(0,0,ScaleFactor*Width,ScaleFactor*Height),
                            {$IFDEF CLR}pfDevice{$ELSE}TeePixelFormat{$ENDIF});
    try
      Canvas.InitWindow(Canvas.ReferenceCanvas,View3DOptions,Color,View3D,BoundsRect);
      SmoothStretch(tmp,TTeeCanvas3D(Canvas).Bitmap,ssBestPerformance);
    finally
      tmp.Free;
      Title.Visible:=Old;
      Title.ShapeBounds:=tmpR;
      Title.CustomPosition:=True;
      Title.DrawTitle;
      Title.CustomPosition:=False;
      SetMargins;
      ICreatingBitmap:=False;
    end;

    with LeftAxis.LabelsFont do Size:=Size div ScaleFactor;
    with BottomAxis.LabelsFont do Size:=Size div ScaleFactor;
  end;
end;

procedure TGalleryChart.AfterDraw(Sender: TObject);
begin
  if FSmooth and (not ICreatingBitmap) then
     DrawSmoothChart;

  if not ICreatingBitmap then
    if Gradient.Visible then
       if TChartGalleryPanel(Parent).DisplaySub then
          DrawSubGalleryArrow;
end;

{ TChartGalleryPanel }
Constructor TChartGalleryPanel.Create(AOwner:TComponent);
begin
  inherited;

  FunctionsVisible:=False;
  ISelectedChart:=nil;
  SelectedSeries:=nil;
  FOnSelectedChart:=nil;
  FOnChangeChart:=nil;
  FCharts:=TChartList.Create;
  FView3D:=True;
  FDisplaySub:=True;
  FFocusRotation:=True;
  FNumRows:=3;
  FNumCols:=4;

  {$IFNDEF CLX}
  {$IFDEF D7}
  ParentBackground:=True;
  {$ENDIF}
  {$ENDIF}

  ParentColor:=True;

  FSmooth:=DefaultSmooth;
  FOldSmooth:=FSmooth;
end;

Destructor TChartGalleryPanel.Destroy;
begin
  if FSmooth<>FOldSmooth then SaveSmooth(FSmooth);
  Charts.Free;
  inherited;
end;

class Function TChartGalleryPanel.DefaultSmooth:Boolean;
begin
  result:=TeeReadBoolOption('SmoothGallery',False);
end;

class Function TChartGalleryPanel.DefaultMode:Integer;
begin
  result:=TeeReadIntegerOption('GalleryMode',0);
end;

class Procedure TChartGalleryPanel.SaveSmooth(Value:Boolean);  // 6.02
begin
  TeeSaveBoolOption('SmoothGallery',Value);
end;

class Procedure TChartGalleryPanel.SaveMode(Value:Integer);  // 6.02
begin
  TeeSaveIntegerOption('GalleryMode',Value);
end;

Procedure TChartGalleryPanel.SetNumCols(Value:Integer);
begin
  FNumCols:=Value;
  ResizeCharts;
end;

Procedure TChartGalleryPanel.SetNumRows(Value:Integer);
begin
  FNumRows:=Value;
  ResizeCharts;
end;

Procedure TChartGalleryPanel.GetChartXY(AChart:TGalleryChart; Var x,y:Integer);
var tmp : Integer;
begin
  tmp:=Charts.IndexOf(AChart);
  y:=tmp div NumCols;
  x:=tmp mod NumCols;
end;

procedure TChartGalleryPanel.ChartOnDblClick(Sender: TObject);
begin
  ISelectedChart:=TGalleryChart(Sender);
  if Assigned(FOnSelectedChart) then OnSelectedChart(Self);
end;

Procedure TChartGalleryPanel.CalcChartWidthHeight;
var tmp : Integer;
begin
  if (NumRows>0) and (NumCols>0) then
  begin
    tmp:=BevelWidth+BorderWidth;
    FRowHeight:=(Height-tmp) div NumRows;
    FColWidth:=(Width-tmp) div NumCols;
  end
  else
  begin
    FRowHeight:=0;
    FColWidth:=0;
  end;
end;

type
   TFunctionAccess=class(TTeeFunction);

Function TChartGalleryPanel.CreateChart(Const AType:TTeeSeriesType):TCustomAxisPanel;
Var tmpClass : TChartSeriesClass;

  Procedure CreateSeries;
  Var tmp : Integer;
  begin
    for tmp:=1 to Math.Max(1,AType.NumGallerySeries) do
        CreateNewSeries(nil,result,tmpClass,AType.FunctionClass);
  end;

var t              : Integer;
    tmpNum         : Integer;
    DisabledSeries : Boolean;
    tmpFunc        : TTeeFunction;
    tmpDesc        : String;

    {$IFDEF USETHEMES}
    tmpColor       : Cardinal;
    tmpPColor      : Cardinal;
    {$ENDIF}
begin
  tmpClass:=AType.SeriesClass;
  if not Assigned(tmpClass) then tmpClass:=TLineSeries;

  result:=TGalleryChart.Create(Self);

  result.Color:=Color;

  {$IFNDEF CLX}
  result.AutoRepaint:=False;
  {$ENDIF}

  Charts.Add(result);

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

    Parent:=Self;

    {$IFDEF USETHEMES}
    if ThemeServices.ThemesEnabled then
    begin
      tmpColor:=0;
      tmpPColor:=Integer(@tmpColor);
      GetThemeColor(ThemeServices.Theme[teTab],TABP_BODY,TIS_NORMAL,TMT_FILLCOLOR,tmpPColor);
      Color:=tmpPColor;
    end;
    {$ENDIF}

    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;

    Smooth:=Self.Smooth;
  end;

  if not ISubGallery then
     TGalleryChart(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;

⌨️ 快捷键说明

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