📄 qiplotlayoutviewer.pas
字号:
{*******************************************************}
{ }
{ TiPlotLayoutViewer Component }
{ }
{ Copyright (c) 1997,2003 Iocomp Software }
{ }
{*******************************************************}
{$I iInclude.inc}
{$ifdef iVCL}unit iPlotLayoutViewer;{$endif}
{$ifdef iCLX}unit QiPlotLayoutViewer;{$endif}
interface
uses
{$I iIncludeUses.inc}
{$IFDEF iVCL} Menus, iTypes, iGPFunctions, iPlotObjects, iPlotLayoutManager, iPlotMasterManager, iPlotTranslation, iCustomComponent;{$ENDIF}
{$IFDEF iCLX}QMenus, QiTypes, QiGPFunctions, QiPlotObjects, QiPlotLayoutManager, QiPlotMasterManager, QiPlotTranslation, QiCustomComponent;{$ENDIF}
type
TiLayoutEditMode = (ilemNone, ilemDrag, ilemSize);
TiLayoutSizingSide = (ilssStart, ilssStop);
TBlockObject = class(TObject)
public
ARect : TRect;
ZOrder : Integer;
Horizontal : Boolean;
DataView : Boolean;
ToolBar : Boolean;
end;
TiPlotLayoutViewer = class(TiCustomComponent)
private
FBlockList : TStringList;
FCellWidth : Integer;
FMouseDown : Boolean;
FMouseDownX : Integer;
FMouseDownY : Integer;
FMouseDownStartPercent : Double;
FMouseDownStopPercent : Double;
FViewRect : TRect;
FDataViewRect : TRect;
FDataViewHeight : Integer;
FDataViewWidth : Integer;
FEditMode : TiLayoutEditMode;
FSizingSide : TiLayoutSizingSide;
FSelectedBlock : TiPlotLayoutObject;
FResizeBlock : TiPlotLayoutObject;
FOverLayoutObject : TiPlotLayoutObject;
FDragOverRefBlock2 : TBlockObject;
FInsertDirection : TiInsertDirection;
FLayoutManager : TiPlotLayoutManager;
FMaster : TiPlotMasterManager;
FFont : TFont;
FOnChange : TNotifyEvent;
FTranslationManager : TiPlotTranslationManager;
protected
procedure CalcRects;
procedure iPaintTo (Canvas: TCanvas); override;
procedure DrawOuterBorder(Canvas : TCanvas);
procedure Draw (Canvas : TCanvas);
procedure iMouseUp (Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure iMouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure iMouseMove( Shift: TShiftState; X, Y: Integer); override;
procedure Flip;
procedure MoveZ;
procedure MoveHorzToVert;
procedure MoveVertToHorz;
procedure TriggerChange;
function GetDropRefObject(Source: TiPlotLayoutObject; Horizontal: Boolean; ZOrder: Integer): TiPlotLayoutObject;
public
function GetMouseOverBlock (X, Y: Integer): TiPlotLayoutObject;
function GetMouseOverBlock2(X, Y: Integer): TBlockObject;
constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
property LayoutManager : TiPlotLayoutManager read FLayoutManager write FLayoutManager;
property Master : TiPlotMasterManager read FMaster write FMaster;
property TranslationManager : TiPlotTranslationManager read FTranslationManager write FTranslationManager;
property SelectedObject : TiPlotLayoutObject read FSelectedBlock;
published
property OnChange : TNotifyEvent read FOnChange write FOnChange;
end;
implementation
uses
{$ifdef iVCL} iPlotToolBar, iPlotLegend, iPlotAxis, iPlotLabel, iPlotTable, iPlotChannel, iPlotDataView;{$endif}
{$ifdef iCLX}QiPlotToolBar, QiPlotLegend, QiPlotAxis, QiPlotLabel, QiPlotTable, QiPlotChannel, QiPlotDataView;{$endif}
type
TiPlotLayoutAccess = class(TiPlotLayoutObject ) end;
//****************************************************************************************************************************************************
constructor TiPlotLayoutViewer.Create(AOwner : TComponent);
begin
inherited;
FFont := TFont.Create;
FFont.Name := 'Arial';
FFont.Size := 10;
FBlockList := TStringList.Create;
end;
//****************************************************************************************************************************************************
destructor TiPlotLayoutViewer.Destroy;
begin
FFont.Free;
while FBlockList.Count <> 0 do
begin
FBlockList.Objects[0].Free;
FBlockList.Delete(0);
end;
FBlockList.Free;
inherited;
end;
//****************************************************************************************************************************************************
procedure TiPlotLayoutViewer.iPaintTo(Canvas: TCanvas);
begin
CalcRects;
DrawOuterBorder(Canvas);
if Assigned(FLayoutManager) then Draw(Canvas);
end;
//****************************************************************************************************************************************************
procedure TiPlotLayoutViewer.DrawOuterBorder(Canvas: TCanvas);
begin
with Canvas do
begin
Brush.Style := bsSolid;
Brush.Color := clBlue;
Pen.Color := clBlue;
FillRect(ClipRect);
Brush.Color := clWhite;
Pen.Color := clWhite;
FillRect(FViewRect);
end;
end;
//****************************************************************************************************************************************************
procedure TiPlotLayoutViewer.Draw(Canvas: TCanvas);
var
x : Integer;
iBlockObject : TiPlotLayoutObject;
ATextString : String;
DrawRect : TRect;
ARect : TRect;
AWidth : Integer;
AHeight : Integer;
begin
with Canvas do
begin
Pen.Color := clBlack;
Pen.Style := psClear;
Font.Assign(FFont);
for x := 0 to FLayoutManager.Count - 1 do
begin
iBlockObject := FLayoutManager.Items[x];
if iBlockObject is TiPlotDataViewVert then Continue;
if iBlockObject is TiPlotDataView then Continue;
if iBlockObject = FSelectedBlock then Brush.Color := clYellow
else Brush.Color := clSilver;
DrawRect := iBlockObject.LayoutRect;
if iBlockObject.Visible then
Brush.Style := bsSolid
else Brush.Style := bsDiagCross;
{$ifdef iVCL}Rectangle(DrawRect.Left, DrawRect.Top, DrawRect.Right, DrawRect.Bottom); {$endif}
{$ifdef iCLX}Rectangle(DrawRect.Left, DrawRect.Top, DrawRect.Right-1, DrawRect.Bottom-1);{$endif}
Brush.Style := bsClear;
if Assigned(TranslationManager) then ATextString := TranslationManager.FindReplacement(iBlockObject.Name)
else ATextString := iBlockObject.Name;
//ATextString := ATextString + '-' + IntToStr(iBlockObject.ZOrder);
if iBlockObject.Horizontal then
iDrawRotatedText(Canvas, ATextString, DrawRect, ira000)
//iDrawText(Canvas, ATextString, DrawRect, [itfVCenter, itfHCenter, itfNoClip, itfSingleLine])
else iDrawRotatedText(Canvas, ATextString, DrawRect, ira090);
end;
Brush.Style := bsSolid;
Brush.Color := clYellow;
Pen.Style := psSolid;
Pen.Width := 1;
Pen.Color := clBlack;
AWidth := Round(FCellWidth);
AHeight := Round(FCellWidth);
if Assigned(FOverLayoutObject) then
begin
Brush.Style := bsClear;
Pen.Style := psSolid;
Pen.Width := 2;
Rectangle(FOverLayoutObject.LayoutRect.Left, FOverLayoutObject.LayoutRect.Top, FOverLayoutObject.LayoutRect.Right, FOverLayoutObject.LayoutRect.Bottom);
end
else if Assigned(FDragOverRefBlock2) then
begin
ARect := FDragOverRefBlock2.ARect;
if FDragOverRefBlock2.Horizontal then
case FInsertDirection of
iidMerge : OffsetRect(ARect, 0, 0 );
iidBelow : OffsetRect(ARect, 0, AHeight div 2 );
iidAbove : OffsetRect(ARect, 0, -AHeight div 2 + 1);
end
else
case FInsertDirection of
iidMerge : OffsetRect(ARect, 0 , 0);
iidBelow : OffsetRect(ARect, -AWidth div 2 , 0);
iidAbove : OffsetRect(ARect, AWidth div 2 + 1, 0);
end;
if FDragOverRefBlock2.DataView then
begin
if FDragOverRefBlock2.Horizontal then
begin
case FInsertDirection of
iidBelow : ARect.Top := ARect.Bottom - Round(FCellWidth);
iidAbove : ARect.Bottom := ARect.Top + Round(FCellWidth);
end;
ARect.Left := FViewRect.Left;
ARect.Right := FViewRect.Right;
end
else
case FInsertDirection of
iidBelow : ARect.Right := ARect.Left + Round(FCellWidth);
iidAbove : ARect.Left := ARect.Right - Round(FCellWidth);
end;
end;
Brush.Style := bsClear;
Pen.Style := psSolid;
Pen.Width := 2;
Rectangle(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom);
end;
end;
end;
//****************************************************************************************************************************************************
function TiPlotLayoutViewer.GetDropRefObject(Source: TiPlotLayoutObject; Horizontal: Boolean; ZOrder: 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 = Source then Continue;
if iBlockObject is TiPlotDataView then Continue;
if iBlockObject.ZOrder <> ZOrder then Continue;
if iBlockObject.Horizontal <> Horizontal then Continue;
if Horizontal then
begin
if iBlockObject is TiPlotDataViewVert then Continue
end
else
begin
if iBlockObject is TiPlotDataViewHorz then Continue;
end;
Result := iBlockObject;
Break;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -