📄 qiplotlayoutviewer.pas
字号:
end;
//****************************************************************************************************************************************************
function TiPlotLayoutViewer.GetMouseOverBlock(X, Y: Integer): TiPlotLayoutObject;
var
i : Integer;
iBlockObject : TiPlotLayoutObject;
begin
Result := nil;
for i := 0 to FLayoutManager.Count - 1 do
begin
iBlockObject := FLayoutManager.Items[i];
if iBlockObject is TiPlotDataViewLayout then Continue;
if PtInRect(iBlockObject.LayoutRect, Point(X,Y)) then
begin
Result := iBlockObject;
Exit;
end;
end;
end;
//****************************************************************************************************************************************************
function TiPlotLayoutViewer.GetMouseOverBlock2(X, Y: Integer): TBlockObject;
var
i : Integer;
BlockObject : TBlockObject;
Rect1 : TRect;
Rect2 : TRect;
begin
Result := nil;
for i := 0 to FBlockList.Count - 1 do
begin
BlockObject := FBlockList.Objects[i] as TBlockObject;
if BlockObject.ToolBar then
begin
if Y < (BlockObject.ARect.Top + BlockObject.ARect.Bottom) div 2 then Continue;
end
else if BlockObject.DataView then
begin
if BlockObject.Horizontal then
begin
Rect1 := Rect(BlockObject.ARect.Left, BlockObject.ARect.Bottom - FCellWidth, BlockObject.ARect.Right, BlockObject.ARect.Bottom );
Rect2 := Rect(BlockObject.ARect.Left, BlockObject.ARect.Top, BlockObject.ARect.Right, BlockObject.ARect.Top + FCellWidth);
if not (PtInRect(Rect1, Point(X, Y)) or PtInRect(Rect2, Point(X, Y))) then Continue;
end
else
begin
Rect1 := Rect(BlockObject.ARect.Left, BlockObject.ARect.Top, BlockObject.ARect.Left + FCellWidth, BlockObject.ARect.Bottom);
Rect2 := Rect(BlockObject.ARect.Right - FCellWidth, BlockObject.ARect.Top, BlockObject.ARect.Right, BlockObject.ARect.Bottom);
if not (PtInRect(Rect1, Point(X, Y)) or PtInRect(Rect2, Point(X, Y))) then Continue;
end;
end;
if PtInRect(BlockObject.ARect, Point(X,Y)) then
begin
Result := BlockObject;
Break;
end;
end;
end;
//****************************************************************************************************************************************************
procedure TiPlotLayoutViewer.iMouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
iBlockObject : TiPlotLayoutObject;
begin
iBlockObject := GetMouseOverBlock(X,Y);
if Assigned(iBlockObject) then
begin
if iBlockObject is TiPlotDataView then Exit;
if iBlockObject is TiPlotToolBar then Exit;
FSelectedBlock := iBlockObject;
FMouseDown := True;
FMouseDownX := X;
FMouseDowny := Y;
if not (ssLeft in Shift) then FInsertDirection := iidMerge;
if Assigned(FResizeBlock) then
begin
FEditMode := ilemSize;
FMouseDownStartPercent := iBlockObject.StartPercent;
FMouseDownStopPercent := iBlockObject.StopPercent;
end
else
begin
FEditMode := ilemDrag;
end;
InvalidateChange;
end;
end;
//****************************************************************************************************************************************************
procedure TiPlotLayoutViewer.iMouseMove(Shift: TShiftState; X, Y: Integer);
var
LayoutObject : TiPlotLayoutObject;
RefObject : TiPlotLayoutObject;
BlockObject : TBlockObject;
DiffPercent : Double;
CanDropOnTo : Boolean;
BlockWidth : Integer;
BlockHeight : Integer;
CanMerge : Boolean;
begin
Cursor := crDefault;
if not (ssLeft in Shift) and (FEditMode = ilemDrag) then Exit;
FOverLayoutObject := nil;
FDragOverRefBlock2 := nil;
LayoutObject := GetMouseOverBlock (X,Y);
BlockObject := GetMouseOverBlock2(X,Y);
case FEditMode of
ilemNone : begin
if Assigned(LayoutObject) then
begin
if (LayoutObject is TiPlotAxis) or (LayoutObject is TiPlotLabel) or (LayoutObject is TiPlotTable) or (LayoutObject is TiPlotLegend) then
begin
if LayoutObject.IsHorz then
begin
if (Abs(LayoutObject.LayoutRect.Left - X) < 7) then
begin
FSizingSide := ilssStart;
Cursor := crSizeWE;
FResizeBlock := LayoutObject;
end
else if (Abs(LayoutObject.LayoutRect.Right - X) < 7) then
begin
FSizingSide := ilssStop;
Cursor := crSizeWE;
FResizeBlock := LayoutObject;
end
else
begin
Cursor := crDefault;
FResizeBlock := nil;
end;
end
else
begin
if (Abs(LayoutObject.LayoutRect.Bottom - Y) < 7) then
begin
FSizingSide := ilssStart;
Cursor := crSizeNS;
FResizeBlock := LayoutObject;
end
else if (Abs(LayoutObject.LayoutRect.Top - Y) < 7) then
begin
FSizingSide := ilssStop;
Cursor := crSizeNS;
FResizeBlock := LayoutObject;
end
else
begin
Cursor := crDefault;
FResizeBlock := nil;
end;
end;
end;
end
else
begin
Cursor := crDefault;
FResizeBlock := nil;
end;
end;
ilemDrag :begin
if not FMouseDown then Exit;
if Assigned(LayoutObject) then
begin
CanDropOnTo := True;
if LayoutObject is TiPlotDataView then CanDropOnTo := False;
if FSelectedBlock.Horizontal <> LayoutObject.Horizontal then CanDropOnTo := False;
if FSelectedBlock.ZOrder <> LayoutObject.Zorder then CanDropOnTo := False;
if CanDropOnTo and (FSelectedBlock <> LayoutObject) then
begin
FOverLayoutObject := LayoutObject;
end
else FOverLayoutObject := nil;
end;
if Assigned(BlockObject) then
begin
RefObject := GetDropRefObject(FSelectedBlock, BlockObject.Horizontal, BlockObject.ZOrder);
CanDropOnTo := True;
if FSelectedBlock is TiPlotAxis then if FSelectedBlock.Horizontal <> BlockObject.Horizontal then CanDropOnTo := False;
if CanDropOnTo then
begin
BlockWidth := BlockObject.ARect.Right - BlockObject.ARect.Left;
BlockHeight := BlockObject.ARect.Bottom - BlockObject.ARect.Top;
FDragOverRefBlock2 := BlockObject;
if not Assigned(RefObject) then Exit;
CanMerge := False;
if (FSelectedBlock is TiPlotAxis) and (RefObject is TiPlotAxis) then CanMerge := True;
if (FSelectedBlock is TiPlotLabel) and (RefObject is TiPlotLabel) then CanMerge := True;
if (FSelectedBlock is TiPlotLabel) and (RefObject is TiPlotLegend) then CanMerge := True;
if (FSelectedBlock is TiPlotLegend) and (RefObject is TiPlotLabel) then CanMerge := True;
if not CanMerge then
begin
if not BlockObject.Horizontal then
begin
if X < (BlockObject.ARect.Left + BlockWidth div 2) then FInsertDirection := iidBelow
else FInsertDirection := iidAbove;
end
else
begin
if Y > (BlockObject.ARect.Top + BlockHeight div 2) then FInsertDirection := iidBelow
else FInsertDirection := iidAbove;
end;
end
else if BlockObject.ToolBar then
begin
if Y > (BlockObject.ARect.Top + BlockHeight*2 div 3) then FInsertDirection := iidBelow
else FDragOverRefBlock2 := nil;
end
else
begin
if not BlockObject.Horizontal then
begin
if X < (BlockObject.ARect.Left + BlockWidth div 3) then FInsertDirection := iidBelow
else if X < (BlockObject.ARect.Left + BlockWidth*2 div 3) then FInsertDirection := iidMerge
else FInsertDirection := iidAbove;
end
else
begin
if Y > (BlockObject.ARect.Top + BlockHeight*2 div 3) then FInsertDirection := iidBelow
else if Y > (BlockObject.ARect.Top + BlockHeight div 3) then FInsertDirection := iidMerge
else FInsertDirection := iidAbove;
end;
end;
end
else FDragOverRefBlock2 := nil;
end;
end;
ilemSize :begin
if not FMouseDown then exit;
if FResizeBlock.IsVert then DiffPercent := (FMouseDownY - Y)/FDataViewHeight*100
else DiffPercent := (X - FMouseDownX)/FDataViewWidth *100;
DiffPercent := (Round(DiffPercent/1.25))*1.25;
case FSizingSide of
ilssStart : FResizeBlock.StartPercent := FMouseDownStartPercent + DiffPercent;
ilssStop : FResizeBlock.StopPercent := FMouseDownStopPercent + DiffPercent;
end
end;
end;
InvalidateChange;
end;
//****************************************************************************************************************************************************
procedure TiPlotLayoutViewer.iMouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
i : Integer;
MergeList : TStringList;
LayoutObject : TiPlotLayoutObject;
RefObject : TiPlotLayoutObject;
StepPerecent : Double;
begin
FMouseDown := False;
case FEditMode of
ilemNone : ;
ilemDrag : if Assigned(FDragOverRefBlock2) and Assigned(FOverLayoutObject) then
begin
Flip;
end
else
begin
if Assigned(FDragOverRefBlock2) then
begin
if FSelectedBlock.Horizontal <> FDragOverRefBlock2.Horizontal then
begin
if FSelectedBlock.Horizontal then MoveHorzToVert else MoveVertToHorz;
end
else
case FInsertDirection of
iidBelow : begin
RefObject := GetDropRefObject(FSelectedBlock, FDragOverRefBlock2.Horizontal, FDragOverRefBlock2.ZOrder);
if Assigned(RefObject) then
begin
FLayoutManager.RemoveZOrder(FSelectedBlock);
FLayoutManager.InsertZOrder(FSelectedBlock, RefObject.ZOrder, iidBelow);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -