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

📄 teeselectortool.pas

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

  Procedure CalcClickedAnnotation;
  var t : Integer;
  begin { return which Annotation is under the mouse cursor }
    With ParentChart do
    for t:=0 to Tools.Count-1 do
    if Tools[t] is TAnnotationTool then
       if TAnnotationTool(Tools[t]).Clicked(X,Y) then
       begin
         Self.FAnnotation:=TAnnotationTool(Tools[t]);
         Self.FShape:=Self.FAnnotation.Shape;
         break;
       end;
  end;

begin
  inherited;
  if not (ssDouble in Shift) then
  Case AEvent of
    cmeDown: if Button=mbLeft then
             begin
               { check if XY is over the right-bottom corner }
               if AllowResizeChart and ClickedCorner(X,Y) then
               begin
                 IResizingChart:=True;
                 IResized:=False;
               end
               else
               begin
                 IResizingChart:=False;

                 EmptySelection;

                 { check if mouse XY is over an annotation }
                 CalcClickedAnnotation;

                 if not Assigned(FShape) then
                 begin
                   { calc clicked chart part }
                   TCustomChart(ParentChart).CalcClickedPart(TeePoint(X,Y),Part);

                   { if clicked part is a legend or a title ... }
                   if Part.Part=cpLegend then
                      FShape:=TCustomChart(ParentChart).Legend
                   else
                   if Part.Part=cpTitle then
                      FShape:=TCustomChart(ParentChart).Title
                   else
                   if Part.Part=cpSubTitle then
                      FShape:=TCustomChart(ParentChart).SubTitle
                   else
                   if Part.Part=cpFoot then
                      FShape:=TCustomChart(ParentChart).Foot
                   else
                   if Part.Part=cpSubFoot then
                      FShape:=TCustomChart(ParentChart).SubFoot
                   else
                   if Part.Part=cpChartRect then
                      { select back wall }
                      FWall:=TCustomChart(ParentChart).BackWall;
                 end;

                 { call OnSelected event }
                 DoSelected;

                 // ParentChart.CancelMouse:=True; <-- check Legend checkboxes !

                 { start dragging if selection is a Shape or Annotation }
                 IDragging:=AllowDrag and Assigned(FShape);
                 if IDragging then
                 begin
                   IDif.X:=FShape.Left-X;
                   IDif.Y:=FShape.Top-Y;
                   IDragged:=False;
                 end;
               end;
             end;

    cmeMove: if IDragging and Assigned(FShape) then
             begin
               { check X position change }
               if FShape.Left<>(X+IDif.X) then
               begin
                 if IDragged or (Abs(FShape.Left-(X+IDif.X))>2) then
                 begin
                   FShape.Left:=X+IDif.X;
                   IDragged:=True;
                 end;
               end;

               { check Y position change }
               if FShape.Top<>(Y+IDif.Y) then
               begin
                 if IDragged or (Abs(FShape.Top-(Y+IDif.Y))>2) then
                 begin
                   FShape.Top :=Y+IDif.Y;
                   IDragged:=True;
                 end;
               end;

               { call OnDragging event }
               if Assigned(FOnDragging) then FOnDragging(Self);

             end
             else
             if IResizingChart then
             begin
               with ParentChart do if Align<>alNone then Align:=alNone;

               with ParentChart do
               begin
                 if Width<>X then Width:=X;
                 if Height<>Y then Height:=Y;
               end;

               IResized:=True;
               { call OnResizing event }
               if Assigned(FOnResizing) then
                  FOnResizing(Self);
             end;

      cmeUp: begin
               { finish dragging / resizing }
               if IDragged and Assigned(FOnDragged) then
                  FOnDragged(Self);
               if IResized and Assigned(FOnResized) then
                  FOnResized(Self);
               StopDragging;
             end;
  end;
end;

Procedure TSelectorTool.DoSelected;
begin
  Repaint;
  if Assigned(OnSelected) then OnSelected(Self);
end;

class function TSelectorTool.Description: String;
begin
  result:=TeeMsg_SelectorTool;
end;

class function TSelectorTool.GetEditorClass: String;
begin
  result:='TSelectorToolEditor';
end;

procedure TSelectorTool.SetHandleSize(const Value: Integer);
begin
  if FHandleSize<>Value then
  begin
    FHandleSize:=Value;
    Repaint;
  end;
end;

procedure TSelectorTool.SetAnnotation(const Value: TAnnotationTool);
begin
  if (Part.Part<>cpNone) or (FAnnotation<>Value) then
  begin
    EmptySelection;
    FAnnotation:=Value;
    if Assigned(FAnnotation) then
       FShape:=FAnnotation.Shape
    else
       FShape:=nil;
    Part.Part:=cpNone;
    DoSelected;
  end;
end;

function TSelectorTool.SelectedTitle: TChartTitle;
begin
  with TCustomChart(ParentChart) do
  Case Part.Part of
    cpTitle    : result:=Title;
    cpFoot     : result:=Foot;
    cpSubTitle : result:=SubTitle;
    cpSubFoot  : result:=SubFoot;
  else
    result:=nil;
  end;
end;

Procedure TSelectorTool.ClearSelection;
begin { remove selection }
  if (Part.Part<>cpNone) or
     (Assigned(FAnnotation) or Assigned(FShape) or Assigned(FWall)) then
  begin
    EmptySelection;
    DoSelected;
  end;
end;

Procedure TSelectorTool.EmptySelection;
begin
  Part.Part:=cpNone;
  Part.ASeries:=nil;
  Part.AAxis:=nil;
  FAnnotation:=nil;
  FShape:=nil;
  FWall:=nil;
end;

procedure TSelectorTool.StopDragging;
begin
  IDragging:=False;
  IDragged:=False;
  IResizingChart:=False;
  IResized:=False;
end;

procedure TSelectorTool.SetWall(const Value: TChartWall);
begin
  if (Part.Part<>cpNone) or (FWall<>Value) then
  begin
    EmptySelection;
    Part.Part:=cpNone;
    FWall:=Value;
    if Assigned(FWall) and (FWall=TCustomChart(ParentChart).BackWall) then
       Part.Part:=cpChartRect;
    DoSelected;
  end;
end;

function TSelectorTool.GetSeries: TChartSeries;
begin
  result:=Part.ASeries;
end;

procedure TSelectorTool.SetSeries(const Value: TChartSeries);
begin
  if (Part.Part<>cpSeries) or (Part.ASeries<>Value) then
  begin
    EmptySelection;
    { select Series }
    Part.Part:=cpSeries;
    Part.ASeries:=Value;

    ParentChart:=Value.ParentChart; // 7.05

    Part.PointIndex:=-1;
    DoSelected;
  end;
end;

{ SelectorToolEditor }
procedure TSelectorToolEditor.FormShow(Sender: TObject);
begin
  Selector:=TSelectorTool(Tag);

  if Assigned(Selector) then
  with Selector do
  begin
    ButtonPen1.LinkPen(Pen);
    ButtonColor1.LinkProperty(Brush,'Color');
    UDSize.Position:=HandleSize;
    CBAllowDrag.Checked:=AllowDrag;
    CBResizeChart.Checked:=AllowResizeChart;
  end;
end;

procedure TSelectorToolEditor.Edit1Change(Sender: TObject);
begin
  if Showing and Assigned(Selector) then
     Selector.HandleSize:=UDSize.Position;
end;

procedure TSelectorToolEditor.CBAllowDragClick(Sender: TObject);
begin
  Selector.AllowDrag:=CBAllowDrag.Checked;
end;

procedure TSelectorToolEditor.CBResizeChartClick(Sender: TObject);
begin
  Selector.AllowResizeChart:=CBResizeChart.Checked;
end;

initialization
  RegisterClass(TSelectorToolEditor);
  RegisterTeeTools([TSelectorTool]);
finalization
  UnRegisterTeeTools([TSelectorTool]);
end.

⌨️ 快捷键说明

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