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

📄 teecomma.pas

📁 第三方控件:PaintGrid.pas 网格型仪表控件源文件 Mymeter.pas 圆型仪表控件源文件 Project1是这两个控件的使用范例。 该
💻 PAS
📖 第 1 页 / 共 3 页
字号:

Procedure TTeeCommander.DoMouseUp;
begin
  IPieSeries:=nil;
  FDragging:=False;
  FDraggingIndex:=-1;
end;

Function TTeeCommander.GetPieSeries(x,y:Integer):TPieSeries;
var t : Integer;
    tmp : TChartSeries;
    tmpPart : TChartClickedPart;
begin
  result:=nil;

  if EnablePieExploding and (FPanel is TCustomChart) then
  With TCustomChart(FPanel) do
  begin
    CalcClickedPart(TeePoint(x,y),tmpPart);

    if (tmpPart.Part=cpSeries) and (tmpPart.ASeries is TPieSeries) then
       result:=tmpPart.ASeries as TPieSeries
    else
    for t:=0 to SeriesCount-1 do
    begin
      tmp:=Series[t];

      if (tmp is TPieSeries) and tmp.Active then
      begin
        result:=tmp as TPieSeries;
        exit;
      end;
    end;
  end;
end;

Function TTeeCommander.IsButtonDown(AButton:TSpeedButton):Boolean;
begin
  result:=Assigned(AButton) and AButton.Down;
end;

Procedure TTeeCommander.DoMouseMove(X,Y:Integer);

   Procedure Set3D;
   begin
     FPanel.View3D:=True;
     if Assigned(FButton3D) then FButton3D.Down:=True;
   end;

   Procedure DoRotate;

      Function CorrectAngle(Const AAngle:Integer):Integer;
      begin
        result:=AAngle;
        if result>360 then result:=result-360 else
        if result<0 then result:=360+result;
      end;

    Var tmpX      : Integer;
        tmpY      : Integer;
    begin
      With FPanel,View3DOptions do
      begin
        Set3D;
        Orthogonal:=False;
        tmpX:=Round(90.0*(X-FOldX)/Width);
        tmpY:=Round(90.0*(FOldY-Y)/Height);

        if Canvas.SupportsFullRotation then
        begin
          Rotation:=CorrectAngle(Rotation+tmpX);
          Elevation:=CorrectAngle(Elevation+tmpY);
        end
        else
        begin
          if Assigned(IPieSeries) then
          begin
            Rotation:=360;
            if not Canvas.SupportsFullRotation then Perspective:=0;

            if tmpX<>0 then
               With IPieSeries do RotationAngle:=CorrectAngle(RotationAngle+tmpX);
          end
          else
           Rotation:=TRotateTool.RotationChange(FPanel.Canvas.SupportsFullRotation,Rotation,tmpX);

          Elevation:=TRotateTool.ElevationChange(FPanel.Canvas.SupportsFullRotation,Elevation,tmpY);
        end;

        FOldX:=X;
        FOldY:=Y;
      end;
    end;

    Procedure DoMove;
    begin
      Set3D;

      With FPanel.View3DOptions do
      begin
        HorizOffset:=HorizOffset+(X-FOldX);
        VertOffset:=VertOffset+(Y-FOldY);
      end;

      FOldX:=X;
      FOldY:=Y;
    end;

    Procedure DoZoom;
    var tmp  : Double;
        tmp2 : Double;
    begin
      Set3D;
      With FPanel,View3DOptions do
      begin
        tmp:=(10.0*(FOldY-Y)/TeeDistance(ChartWidth,ChartHeight));

        tmp2:=(10.0*tmp*Zoom/100.0);
        if tmp>0 then
           Zoom:=Zoom+Round(Math.Max(1,tmp2))
        else
        if tmp<0 then
           Zoom:=Math.Max(1,Zoom+Round(Math.Min(-1,tmp2)));
      end;

      FOldY:=Y;
    end;

    Function CalcDistPercent(APercent,AWidth,AHeight:Integer):Integer;
    begin
      result:=Round(1.0*APercent*TeeDistance(FOldX-X,FOldY-Y)/TeeDistance(AWidth,AHeight));
    end;

    Procedure DoDepth;
    var tmp : Integer;
    begin
      if FPanel is TCustomAxisPanel then
      With TCustomAxisPanel(FPanel) do
      begin
        Set3D;
        tmp:=CalcDistPercent(200,ChartWidth,ChartHeight);
        if (tmp>=1) then
           Chart3DPercent:=Math.Min(100,tmp);
      end;
    end;

    Procedure DoNormal;
    Var tmp : Integer;
    begin
      if FDraggingIndex<>-1 then
      begin
        if Assigned(IPieSeries) then
        With IPieSeries do
        begin
          tmp:=Math.Min(100,CalcDistPercent(100,CircleWidth,CircleHeight));
          ExplodedSlice[FDraggingIndex]:=tmp;
        end;
      end;
    end;

begin
  if FDragging then
  begin
    FDragging:=False;
    if {$IFNDEF TEEOCX}(not Assigned(FButtonNormal)) or{$ENDIF} IsButtonDown(FButtonNormal) then  // 7.0
       DoNormal  { first do this !!! }
    else
    if FMouseButton=mbRight then DoMove
    else
    if IsButtonDown(FButtonRotate) then DoRotate else
    if IsButtonDown(FButtonMove)   then DoMove else
    if IsButtonDown(FButtonZoom)   then DoZoom else
    if IsButtonDown(FButtonDepth)  then DoDepth;
    if FLabelValues and (not FVertical) then ShowValues;
    FDragging:=True;
  end;
end;

Function TTeeCommander.CaptionPanel(Const ACaption:String):String;
begin
  result:=Format(ACaption,[TeePanelClass]);
end;

procedure TTeeCommander.SetLabelCaption(Const ACaption:String);
var tmp: String;
begin
  tmp:=ACaption;
  if Assigned(FOnSetLabel) then FOnSetLabel(Self,tmp); { 5.02 }

  if Assigned(FLabel) then
     if FLabelValues and (not FVertical) then
        FLabel.Caption:=tmp
     else
        FLabel.Visible:=False;
end;

procedure TTeeCommander.ButtonRotateClick(Sender: TObject);
begin
  SetLabelCaption(CaptionPanel(TeeCommanMsg_RotateLabel));
end;

procedure TTeeCommander.ButtonMoveClick(Sender: TObject);
begin
  SetLabelCaption(CaptionPanel(TeeCommanMsg_MoveLabel));
end;

procedure TTeeCommander.ButtonZoomClick(Sender: TObject);
begin
  SetLabelCaption(CaptionPanel(TeeCommanMsg_ZoomLabel));
end;

procedure TTeeCommander.ButtonDepthClick(Sender: TObject);
begin
  SetLabelCaption(CaptionPanel(TeeCommanMsg_DepthLabel));
end;

procedure TTeeCommander.ButtonEditClick(Sender: TObject);
begin
  {$IFNDEF TEEOCXNOEDITOR}
  if Assigned(FEditor) then FEditor.Execute
  else
  if Assigned(FPanel) and (FPanel is TCustomChart) then
     EditChart(nil,TCustomChart(FPanel));
  if Assigned(FOnEditedChart) then FOnEditedChart(Self,FPanel as TCustomChart);
  if Assigned(FButton3D) then FButton3D.Down:=FPanel.View3D;
  {$ENDIF}
end;

procedure TTeeCommander.ButtonPrintClick(Sender: TObject);
begin
  {$IFNDEF TEEOCXNOEDITOR}
  if Assigned(FPreviewer) then FPreviewer.Execute
  else
  if Assigned(FPanel) then ChartPreview(nil,FPanel);
  {$ENDIF}
end;

procedure TTeeCommander.Button3DClick(Sender: TObject);
begin
  if Assigned(FPanel) then
  begin
    {$IFDEF CLX}
    IChanging3D:=True;
    {$ENDIF}
    FPanel.View3D:={$IFDEF CLX}not {$ENDIF}FButton3D.Down;
    {$IFDEF CLX}
    IChanging3D:=False;
    {$ENDIF}
  end;
end;

procedure TTeeCommander.ButtonCopyClick(Sender: TObject);
begin
  if Assigned(FPanel) then FPanel.CopyToClipboardBitmap;
end;

procedure TTeeCommander.ButtonNormalClick(Sender: TObject);
begin
  if GetPieSeries(0,0)=nil then
     SetLabelCaption(CaptionPanel(TeeCommanMsg_NormalLabel))
  else
     SetLabelCaption(CaptionPanel(TeeCommanMsg_NormalPieLabel))
end;

Procedure TTeeCommander.ShowHideControls(Value:Boolean);
begin
  EnableControls(Value,[FButtonRotate,FButtonMove,FButtonZoom,FButtonNormal,
                        FButtonCopy,FButtonSave,FButtonPrint,FButton3D]);

  if Value then Value:=FPanel is TCustomAxisPanel;

  if Assigned(FButtonDepth) then FButtonDepth.Enabled:=Value;  { 5.01 }
  if Assigned(FButtonEdit) then FButtonEdit.Enabled:=Value;    { 5.01 }
  if Assigned(FButtonSave) then FButtonSave.Enabled:=Value;    { 5.01 }

  if Assigned(FButton3D) and Assigned(FPanel) then
     {$IFDEF CLX}
     if not IChanging3D then
     {$ENDIF}
        FButton3D.Down:=FPanel.View3D;
end;

procedure TTeeCommander.SetLabelValues(Value:Boolean);
begin
  if FLabelValues<>Value then
  begin
    FLabelValues:=Value;
    if Assigned(FLabel) then FLabel.Visible:=FLabelValues;
  end;
end;

// Gets current "default" button
function TTeeCommander.GetDefault:TCommanderControls; // 7.02
begin
  if Assigned(FButtonNormal) and FButtonNormal.Down then result:=tcbNormal else
  if Assigned(FButtonRotate) and FButtonRotate.Down then result:=tcbRotate else
  if Assigned(FButtonMove) and FButtonMove.Down then result:=tcbMove else
  if Assigned(FButtonZoom) and FButtonZoom.Down then result:=tcbZoom else
  if Assigned(FButtonDepth) and FButtonDepth.Down then result:=tcbDepth else
     result:=tcbNormal; // default
end;

// Sets default button down
procedure TTeeCommander.SetDefault(AButton:TCommanderControls);
begin
  case AButton of
    tcbNormal: if Assigned(FButtonNormal) then FButtonNormal.Down:=True;
    tcbRotate: if Assigned(FButtonRotate) then FButtonRotate.Down:=True;
      tcbMove: if Assigned(FButtonMove) then FButtonMove.Down:=True;
      tcbZoom: if Assigned(FButtonZoom) then FButtonZoom.Down:=True;
     tcbDepth: if Assigned(FButtonDepth) then FButtonDepth.Down:=True;
  end;
end;

Procedure TTeeCommander.ShowValues;
var tmp : String;
begin
  With FPanel.View3DOptions do
  if IsButtonDown(FButtonRotate) then
     tmp:=Format(TeeCommanMsg_Rotating,[Rotation,Elevation]) { 5.02 }
  else
  if IsButtonDown(FButtonMove) then
     tmp:=Format(TeeCommanMsg_Moving,[HorizOffset,VertOffset])
  else
  if IsButtonDown(FButtonZoom) then
     tmp:=Format(TeeCommanMsg_Zooming,[Zoom])
  else
  if IsButtonDown(FButtonDepth) then
  begin
    if FPanel is TCustomAxisPanel then
    With TCustomAxisPanel(FPanel) do
      tmp:=Format(TeeCommanMsg_Depthing,[Chart3DPercent])
  end
  else
  if IsButtonDown(FButtonNormal) and (FDraggingIndex<>-1) then
  begin
    if Assigned(IPieSeries) then
       tmp:=Format( TeeCommanMsg_PieExploding,
                    [FDraggingIndex,IPieSeries.ExplodedSlice[FDraggingIndex]])
    else
       tmp:='';
  end
  else
  if Assigned(FLabel) then tmp:='';

  SetLabelCaption(tmp);
  if Assigned(FLabel) and FLabel.Visible then FLabel.Update;
end;

procedure TTeeCommander.ButtonSaveClick(Sender: TObject);
begin
  {$IFNDEF TEEOCXNOEDITOR}
  if Assigned(FPanel) then
  if FPanel is TCustomChart then SaveChartDialog(FPanel as TCustomChart);
  {$ENDIF}
end;

{$IFNDEF TEEOCXNOEDITOR}
procedure TTeeCommander.SetEditor(const Value: TChartEditor);
begin
  {$IFDEF D5}
  if Assigned(FEditor) then
     FEditor.RemoveFreeNotification(Self);
  {$ENDIF}

  if FEditor<>Value then
  begin
    FEditor:=Value;
    if Assigned(FEditor) then
       FEditor.FreeNotification(Self);
  end;
end;

procedure TTeeCommander.SetPreviewer(const Value: TChartPreviewer);
begin
  {$IFDEF D5}
  if Assigned(FPreviewer) then
     FPreviewer.RemoveFreeNotification(Self);
  {$ENDIF}

  if FPreviewer<>Value then
  begin
    FPreviewer:=Value;
    if Assigned(FPreviewer) then
       FPreviewer.FreeNotification(Self);
  end;
end;

procedure TTeeCommander.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  inherited;
  if (Operation=opRemove) then
  begin
    if Assigned(FEditor) and (AComponent=FEditor) then
       FEditor:=nil;
    if Assigned(FPreviewer) and (AComponent=FPreviewer) then
       FPreviewer:=nil;
  end;
end;
{$ENDIF}

end.

⌨️ 快捷键说明

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