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

📄 qiplotlayoutviewer.pas

📁 iocopm3.04源码,一套很好的工控开发工具
💻 PAS
📖 第 1 页 / 共 3 页
字号:
                                          end;

                                        FSelectedBlock.StartPercent := 0;
                                        FSelectedBlock.StopPercent  := 100;
                                      end;
                           iidMerge : begin
                                        MergeList := TStringList.Create;
                                        try
                                          for i := 0 to FLayoutManager.Count - 1 do
                                            begin
                                              LayoutObject := FLayoutManager.Items[i];
                                              if LayoutObject is TiPlotDataView then Continue;
                                              if LayoutObject = FSelectedBlock then Continue;
                                              if (LayoutObject.Horizontal = FDragOverRefBlock2.Horizontal) and (LayoutObject.ZOrder = FDragOverRefBlock2.ZOrder) then
                                                MergeList.AddObject('', FLayoutManager.Items[I]);
                                            end;

                                          RefObject := GetDropRefObject(FSelectedBlock, FDragOverRefBlock2.Horizontal, FDragOverRefBlock2.ZOrder);
                                          MergeList.AddObject('', FSelectedBlock);
                                          StepPerecent := 100/MergeList.Count;
                                          for i := 0 to MergeList.Count-1 do
                                            begin
                                              LayoutObject := MergeList.Objects[i] as TiPlotLayoutObject;
                                              LayoutObject.StopPercent  := i * StepPerecent + StepPerecent;
                                              LayoutObject.StartPercent := i * StepPerecent;
                                            end;
                                          if Assigned(RefObject) then
                                            begin
                                              FLayoutManager.RemoveZOrder(FSelectedBlock);
                                              FLayoutManager.InsertZOrder(FSelectedBlock, RefObject.ZOrder, iidMerge)
                                            end;
                                        finally
                                          MergeList.Free;
                                        end;
                                        TriggerChange;
                                      end;
                           iidAbove : begin
                                        RefObject := GetDropRefObject(FSelectedBlock, FDragOverRefBlock2.Horizontal, FDragOverRefBlock2.ZOrder);
                                        if Assigned(RefObject) then
                                          begin
                                            FLayoutManager.RemoveZOrder(FSelectedBlock);
                                            FLayoutManager.InsertZOrder(FSelectedBlock, RefObject.ZOrder, iidAbove);
                                          end;

                                        FSelectedBlock.StartPercent := 0;
                                        FSelectedBlock.StopPercent  := 100;
                                      end;
                         end;
                 end;
               end;
    ilemSize : if Assigned(FResizeBlock) then TriggerChange;
  end;

  FEditMode := ilemNone;
  Cursor := crDefault;

  FOverLayoutObject  := nil;
  FDragOverRefBlock2 := nil;
  FSelectedBlock     := nil;
  FResizeBlock       := nil;

  InvalidateChange;
end;
//****************************************************************************************************************************************************
procedure TiPlotLayoutViewer.Flip;
var
  OldStart  : Double;
  OldStop   : Double;
begin
  OldStart := FOverLayoutObject.StartPercent;
  OldStop  := FOverLayoutObject.StopPercent;

  TiPlotLayoutAccess(FOverLayoutObject).SetStartStopPercent(FSelectedBlock.StartPercent, FSelectedBlock.StopPercent);
  TiPlotLayoutAccess(FSelectedBlock ).SetStartStopPercent (OldStart, OldStop);
  TriggerChange;
end;
//****************************************************************************************************************************************************
procedure TiPlotLayoutViewer.MoveZ;
var
  ShouldMove : Boolean;
  x          : Integer;
begin
  if FSelectedBlock.ZOrder = FOverLayoutObject.ZOrder then
    begin
      ShouldMove := False;
      for x := 0 to FLayoutManager.Count-1 do
        if (FLayoutManager.Items[x].Horizontal =  FSelectedBlock.Horizontal) and
           (FLayoutManager.Items[x]            <> FSelectedBlock           ) and
           (FLayoutManager.Items[x].ZOrder     =  FSelectedBlock.ZOrder    ) then ShouldMove := True;
      if not ShouldMove then exit;
    end;
  FLayoutManager.RemoveZOrder(FSelectedBlock);
  FLayoutManager.InsertZOrder(FSelectedBlock, FOverLayoutObject.ZOrder, FInsertDirection);
  TriggerChange;
end;
//****************************************************************************************************************************************************
procedure TiPlotLayoutViewer.MoveHorzToVert;
var
  RefObject : TiPlotLayoutObject;
begin
  RefObject := GetDropRefObject(FSelectedBlock, FDragOverRefBlock2.Horizontal, FDragOverRefBlock2.ZOrder);
  FLayoutManager.RemoveZOrder(FSelectedBlock);
  FSelectedBlock.Horizontal := False;
  FLayoutManager.InsertZOrder(FSelectedBlock, RefObject.ZOrder, FInsertDirection);
  TriggerChange;
end;
//****************************************************************************************************************************************************
procedure TiPlotLayoutViewer.MoveVertToHorz;
var
  RefObject : TiPlotLayoutObject;
begin
  RefObject := GetDropRefObject(FSelectedBlock, FDragOverRefBlock2.Horizontal, FDragOverRefBlock2.ZOrder);
  FLayoutManager.RemoveZOrder(FSelectedBlock);
  FSelectedBlock.Horizontal := True;
  FLayoutManager.InsertZOrder(FSelectedBlock, RefObject.ZOrder, FInsertDirection);
  TriggerChange;
end;
//****************************************************************************************************************************************************
procedure TiPlotLayoutViewer.CalcRects;
var
  x            : Integer;
  iBlockObject : TiPlotLayoutObject;
  BlockStart   : Integer;
  BlockStop    : Integer;
  BlockTop     : Integer;
  BlockBottom  : Integer;
  BlockLeft    : Integer;
  BlockRight   : Integer;
  BlockObject  : TBlockObject;
  CurrentZ     : Integer;
begin
  CurrentZ         := 0;
  FViewRect.Left   := 5;
  FViewRect.Top    := 5;
  FViewRect.Right  := Width  - 5;
  FViewRect.Bottom := Height - 5;

  if not Assigned(FLayoutManager) then Exit;

  Canvas.Font.Assign(FFont);
  FCellWidth           := Round(1.10*Canvas.TextHeight('ABC'));
  FDataViewRect.Left   := FViewRect.Left   + Round(FLayoutManager.LeftUniqueCount   * FCellWidth);
  FDataViewRect.Right  := FViewRect.Right  - Round(FLayoutManager.RightUniqueCount  * FCellWidth);
  FDataViewRect.Top    := FViewRect.Top    + Round(FLayoutManager.TopUniqueCount    * FCellWidth);
  FDataViewRect.Bottom := FViewRect.Bottom - Round(FLayoutManager.BottomUniqueCount * FCellWidth);

  FDataViewWidth  := FDataViewRect.Right  - FDataViewRect.Left;
  FDataViewHeight := FDataViewRect.Bottom - FDataViewRect.Top;
  //---------------------------------------------------------------------------------------------------------
  if not Assigned(FDragOverRefBlock2) then
    begin
      while FBlockList.Count <> 0 do
        begin
          FBlockList.Objects[0].Free;
          FBlockList.Delete(0);
        end;

      for x := 0 to FLayoutManager.LeftUniqueCount - 1 do
        begin
          BlockObject            := TBlockObject.Create;
          BlockObject.ZOrder     := CurrentZ;
          BlockObject.Horizontal := False;

          BlockObject.ARect := iRect(FViewRect.Left + Round( x   *FCellWidth), FDataViewRect.Top,
                                     FViewRect.Left + Round((x+1)*FCellWidth), FDataViewRect.Bottom);
          FBlockList.AddObject('', BlockObject);
          Inc(CurrentZ);
        end;

      BlockObject            := TBlockObject.Create;
      BlockObject.DataView   := True;
      BlockObject.ZOrder     := CurrentZ;
      BlockObject.Horizontal := False;
      BlockObject.ARect      := FDataViewRect;
      FBlockList.AddObject('', BlockObject);
      Inc(CurrentZ);

      for x := 0 to FLayoutManager.RightUniqueCount - 1 do
        begin
          BlockObject            := TBlockObject.Create;
          BlockObject.ZOrder     := CurrentZ;
          BlockObject.Horizontal := False;

          BlockObject.ARect := iRect(FDataViewRect.Right + Round( x   *FCellWidth), FDataViewRect.Top,
                                     FDataViewRect.Right + Round((x+1)*FCellWidth), FDataViewRect.Bottom);
          FBlockList.AddObject('', BlockObject);
          Inc(CurrentZ);
        end;
      //---------------------------------------------------------------------------------------------------------
      CurrentZ := FLayoutManager.TopUniqueCount + FLayoutManager.BottomUniqueCount;

      for x := 0 to FLayoutManager.TopUniqueCount - 1 do
        begin
          BlockObject            := TBlockObject.Create;
          if x = 0 then BlockObject.ToolBar := True;
          BlockObject.ZOrder     := CurrentZ;
          BlockObject.Horizontal := True;
          BlockObject.ARect := iRect(FViewRect.Left,  FViewRect.Top + Round( x   *FCellWidth),
                                     FViewRect.Right, FViewRect.Top + Round((x+1)*FCellWidth));
          FBlockList.AddObject('', BlockObject);
          Dec(CurrentZ);
        end;

      BlockObject            := TBlockObject.Create;
      BlockObject.DataView   := True;
      BlockObject.ZOrder     := CurrentZ;
      BlockObject.Horizontal := True;
      BlockObject.ARect      := FDataViewRect;
      FBlockList.AddObject('', BlockObject);  
      Dec(CurrentZ);

      for x := 0 to FLayoutManager.BottomUniqueCount - 1 do
        begin
          BlockObject            := TBlockObject.Create;
          BlockObject.ZOrder     := CurrentZ;
          BlockObject.Horizontal := True;
          BlockObject.ARect := iRect(FViewRect.Left,  FDataViewRect.Bottom + Round( x   *FCellWidth),
                                     FViewRect.Right, FDataViewRect.Bottom + Round((x+1)*FCellWidth));
          FBlockList.AddObject('', BlockObject);
          Dec(CurrentZ);
        end;
    end;
  //---------------------------------------------------------------------------------------------------------
  for x := 0 to FLayoutManager.Count-1 do
    begin
      iBlockObject := FLayoutManager.Items[x];

      if (iBlockObject is TiPlotDataViewLayout) or (iBlockObject is TiPlotDataView) then
        begin
          TiPlotLayoutAccess(iBlockObject).SetLayoutRect(Rect(FDataViewRect.Left, FDataViewRect.Top, FDataViewRect.Right, FDataViewRect.Bottom));
        end
      else
        begin
          if iBlockObject.IsHorz then
            begin
              if iBlockObject.ZOrder > FLayoutManager.DataViewHorz.ZOrder then
                begin
                  BlockStart := FDataViewRect.Top - Round((iBlockObject.ZOrder - FLayoutManager.DataViewHorz.ZOrder  ) * FCellWidth);
                  BlockStop  := FDataViewRect.Top - Round((iBlockObject.ZOrder - FLayoutManager.DataViewHorz.ZOrder-1) * FCellWidth);
                end
              else
                begin
                  BlockStart := FDataViewRect.Bottom + Round((FLayoutManager.DataViewHorz.ZOrder - iBlockObject.ZOrder-1) * FCellWidth);
                  BlockStop  := FDataViewRect.Bottom + Round((FLayoutManager.DataViewHorz.ZOrder - iBlockObject.ZOrder  ) * FCellWidth);
                end;

              if (iBlockObject is TiPlotAxis) then
                begin
                  BlockLeft  := Round(FDataViewRect.Left + iBlockObject.StartPercent * (FDataViewWidth)/100);
                  BlockRight := Round(FDataViewRect.Left + iBlockObject.StopPercent  * (FDataViewWidth)/100);
                end
              else
                begin
                  BlockLeft  := FViewRect.Left + Round(iBlockObject.StartPercent * (FViewRect.Right - FViewRect.Left)/100);
                  BlockRight := FViewRect.Left + Round(iBlockObject.StopPercent  * (FViewRect.Right - FViewRect.Left)/100);
                end;

              TiPlotLayoutAccess(iBlockObject).SetLayoutRect(Rect(BlockLeft, BlockStart, BlockRight, BlockStop));
            end
          else
            begin
              if iBlockObject.ZOrder > FLayoutManager.DataViewVert.ZOrder then
                begin
                  BlockStart := FDataViewRect.Right + Round((iBlockObject.ZOrder - FLayoutManager.DataViewVert.ZOrder-1) * FCellWidth);
                  BlockStop  := FDataViewRect.Right + Round((iBlockObject.ZOrder - FLayoutManager.DataViewVert.ZOrder  ) * FCellWidth);
                end
              else
                begin
                  BlockStart := FDataViewRect.Left - Round((FLayoutManager.DataViewVert.ZOrder - iBlockObject.ZOrder  ) * FCellWidth);
                  BlockStop  := FDataViewRect.Left - Round((FLayoutManager.DataViewVert.ZOrder - iBlockObject.ZOrder-1) * FCellWidth);
                end;

              BlockTop    := FDataViewRect.Bottom - Round(iBlockObject.StopPercent  * (FDataViewHeight)/100);
              BlockBottom := FDataViewRect.Bottom - Round(iBlockObject.StartPercent * (FDataViewHeight)/100);

              TiPlotLayoutAccess(iBlockObject).SetLayoutRect(Rect(BlockStart, BlockTop, BlockStop, BlockBottom));
            end;
        end;
    end;
end;
//****************************************************************************************************************************************************
procedure TiPlotLayoutViewer.TriggerChange;
begin
  if Assigned(FOnChange) then FOnChange(Self);
end;
//****************************************************************************************************************************************************
end.

⌨️ 快捷键说明

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