📄 teepreviewpanel.pas
字号:
if ((FPanels.Count=0) or (Panel<>Value)) and (Value<>Self) then
begin
if Assigned(Value) then
begin
if FPanels.IndexOf(Value)=-1 then
begin
FPanels.Add(Value);
Value.FreeNotification(Self); { 5.01 }
end;
end
else FPanels.Delete(0);
if Assigned(Panel) then FAsBitmap:=Panel.Canvas.SupportsFullRotation;
Invalidate;
end;
End;
Function TTeePreviewPanel.CalcImagePrintMargins(APanel:TCustomTeePanel):TRect;
var PaperWidth : Integer;
PaperHeight : Integer;
begin
RectSize(PaperRect,PaperWidth,PaperHeight);
if Assigned(APanel) then
begin
With APanel do
if PrintProportional and (Printer.Printers.Count>0) then
PrintMargins:=CalcProportionalMargins;
result:=APanel.PrintMargins
end
else result:=TeeRect(15,15,15,15);
With result do
begin
Left :=PaperRect.Left +MulDiv(Left ,PaperWidth,100);
Right :=PaperRect.Right -MulDiv(Right ,PaperWidth,100);
Top :=PaperRect.Top +MulDiv(Top ,PaperHeight,100);
Bottom:=PaperRect.Bottom-MulDiv(Bottom,PaperHeight,100);
end;
end;
Procedure TTeePreviewPanel.CheckPrinterOrientation;
begin
if Printer.Printers.Count>0 then
Case FOrientation of
ppoDefault: ;
ppoPortrait: Printer.Orientation:=poPortrait;
else
Printer.Orientation:=poLandscape;
end;
end;
Procedure TTeePreviewPanel.InternalDraw(Const UserRectangle:TRect);
Procedure CalcPaperRectangles;
Const Margin=5;
Var R : TRect;
tmpWidth : Integer;
tmpHeight : Integer;
PrinterWidth : Integer;
PrinterHeight : Integer;
begin
CheckPrinterOrientation;
if Printer.Printers.Count>0 then
begin
try
PrinterWidth :=Printer.PageWidth;
PrinterHeight:=Printer.PageHeight;
except
on EPrinter do
begin
PrinterWidth:=Screen.Width;
PrinterHeight:=Screen.Height;
end;
end;
end
else
begin
PrinterWidth:=Screen.Width;
PrinterHeight:=Screen.Height;
end;
R:=TeeRect(0,0,PrinterWidth,PrinterHeight);
if (ClientWidth*PrinterHeight)>(ClientHeight*PrinterWidth) then
Begin
tmpHeight:=ClientHeight-Round(ClientHeight/Margin);
PaperRect.Top:=Round(ClientHeight/(2*Margin));
PaperRect.Bottom:=PaperRect.Top+tmpHeight;
if PrinterHeight>0 then
tmpWidth:=MulDiv(tmpHeight,PrinterWidth,PrinterHeight)
else
tmpWidth:=ClientWidth;
PaperRect.Left:=(ClientWidth-tmpWidth) div 2;
PaperRect.Right:=PaperRect.Left+tmpWidth;
end
else
Begin
tmpWidth:=ClientWidth-Round(ClientWidth/Margin);
PaperRect.Left:=Round(ClientWidth/(2*Margin));
PaperRect.Right:=PaperRect.Left+tmpWidth;
if PrinterWidth>0 then
tmpHeight:=MulDiv(tmpWidth,PrinterHeight,PrinterWidth)
else
tmpHeight:=ClientHeight;
PaperRect.Top:=(ClientHeight-tmpHeight) div 2;
PaperRect.Bottom:=PaperRect.Top+tmpHeight;
end;
end;
var t : Integer;
begin
PanelPaint(UserRectangle);
RecalcWidthHeight;
InternalCanvas.Projection(100,ChartBounds,ChartRect);
Canvas.ResetState;
CalcPaperRectangles;
DrawPaper;
ImageRect:=CalcImagePrintMargins(Panel);
for t:=0 to Panels.Count-1 do DrawPanelImage(Panels[t]);
DrawMargins(ImageRect);
Canvas.ResetState;
if Assigned(FOnAfterDraw) then FOnAfterDraw(Self);
end;
Procedure TTeePreviewPanel.DrawMargins(Const R:TRect);
Begin
if Margins.Visible then
With Canvas do
Begin
AssignVisiblePen(Margins);
Pen.Mode:=pmNotXor;
Brush.Style:=bsClear;
Brush.Color:=FPaperColor;
BackMode:=cbmTransparent;
With R do
Begin
DoVertLine(Left-1,PaperRect.Top+1,PaperRect.Bottom);
DoVertLine(Right,PaperRect.Top+1,PaperRect.Bottom);
DoHorizLine(PaperRect.Left+1,PaperRect.Right,Top-1);
DoHorizLine(PaperRect.Left+1,PaperRect.Right,Bottom);
end;
BackMode:=cbmOpaque;
Pen.Mode:=pmCopy;
end;
end;
Procedure TTeePreviewPanel.DrawPanelImage(APanel:TCustomTeePanel);
Var PanelRect : TRect;
{$IFNDEF CLX}
Procedure DrawAsMetafile;
var tmpR : TRect;
tmpMeta : TMetafile;
WinWidth : Integer;
WinHeight : Integer;
tmpW : Integer;
tmpH : Integer;
begin
tmpR:=PanelRect;
APanel.CalcMetaBounds(tmpR,APanel.GetRectangle,WinWidth,WinHeight,tmpW,tmpH);
tmpMeta:=APanel.TeeCreateMetafile(True,TeeRect(0,0,WinWidth,WinHeight));
try
Canvas.StretchDraw(PanelRect,tmpMeta);
finally
tmpMeta.Free;
end;
end;
{$ENDIF}
Begin
PanelRect:=CalcImagePrintMargins(APanel);
APanel.Printing:=True;
if APanel.CanClip then Canvas.ClipRectangle(PanelRect)
else Canvas.ClipRectangle(PaperRect);
if FShowImage then
{$IFDEF CLX}
SendAsBitmap(APanel,Canvas.ReferenceCanvas,PanelRect);
{$ELSE}
if AsBitmap then
SendAsBitmap(APanel,Canvas.ReferenceCanvas,PanelRect)
else
DrawAsMetafile;
{$ENDIF}
Canvas.UnClipRectangle;
APanel.Printing:=False;
end;
procedure TTeePreviewPanel.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited;
if (Operation=opRemove) and Assigned(Panel) and (AComponent=Panel) then
Panel:=nil;
end;
Function TTeePreviewPanel.WhereIsCursor(x,y:Integer):TeePreviewZones;
Const MinPixels=5;
var xLeft : Integer;
xRight : Integer;
yTop : Integer;
yBottom : Integer;
Begin
With ImageRect do
begin
xLeft :=Abs(x-Left);
XRight :=Abs(x-Right);
yTop :=Abs(y-Top);
yBottom:=Abs(y-Bottom);
if (xLeft<MinPixels) and (yTop<MinPixels) then result:=teePrev_LeftTop else
if (xLeft<MinPixels) and (yBottom<MinPixels) then result:=teePrev_LeftBottom else
if (xRight<MinPixels) and (yTop<MinPixels) then result:=teePrev_RightTop else
if (xRight<MinPixels) and (yBottom<MinPixels) then result:=teePrev_RightBottom else
if xLeft<MinPixels then result:=teePrev_Left else
if xRight<MinPixels then result:=teePrev_Right else
if yTop<MinPixels then result:=teePrev_Top else
if yBottom<MinPixels then result:=teePrev_Bottom else
if PointInRect(ImageRect,x,y) then
begin
if FAllowMove then
begin
result:=teePrev_Image;
exit;
end else result:=teePrev_None;
end
else result:=teePrev_None;
if (result<>teePrev_None) and (not FAllowResize) then result:=teePrev_None;
end;
End;
Procedure TTeePreviewPanel.MouseMove(Shift: TShiftState; X, Y: Integer);
var tmpR : TRect;
PaperWidth : Integer;
PaperHeight : Integer;
begin
inherited;
if PointInRect(PaperRect,x,y) then
Begin
if IDragged=teePrev_None then
begin
Cursor:=TeePreviewCursors[Ord(WhereIsCursor(x,y))];
Exit;
end
else
begin
if not FDragImage then DrawMargins(ImageRect);
Case IDragged of
{ sides }
teePrev_Left : if (x>=PaperRect.Left) and (x<ImageRect.Right) then ImageRect.Left:=x;
teePrev_Top : if (y>=PaperRect.Top) and (y<ImageRect.Bottom) then ImageRect.Top:=y;
teePrev_Right : if (x<=PaperRect.Right) and (x>ImageRect.Left) then ImageRect.Right:=x;
teePrev_Bottom : if (y<=PaperRect.Bottom) and (y>ImageRect.Top) then ImageRect.Bottom:=y;
teePrev_Image : Begin
tmpR.Left :=Math.Max(PaperRect.Left,OldRect.Left+(x-OldX));
tmpR.Top :=Math.Max(PaperRect.Top,OldRect.Top+(y-OldY));
tmpR.Right :=Math.Min(PaperRect.Right,tmpR.Left+(OldRect.Right-OldRect.Left));
tmpR.Bottom:=Math.Min(PaperRect.Bottom,tmpR.Top+(OldRect.Bottom-OldRect.Top));
if PointInRect(PaperRect,tmpR.Left,tmpR.Top) and
PointInRect(PaperRect,tmpR.Right,tmpR.Bottom) then
ImageRect:=tmpR;
End;
{ corners }
teePrev_LeftTop : if (x>=PaperRect.Left) and (x<ImageRect.Right) and
(y>=PaperRect.Top) and (y<ImageRect.Bottom) then
Begin
ImageRect.Left:=x;
ImageRect.Top:=y;
end;
teePrev_LeftBottom : if (x>=PaperRect.Left) and (x<ImageRect.Right) and
(y<=PaperRect.Bottom) and (y>ImageRect.Top) then
Begin
ImageRect.Left:=x;
ImageRect.Bottom:=y;
end;
teePrev_RightTop : if (x<=PaperRect.Right) and (x>ImageRect.Left) and
(y>=PaperRect.Top) and (y<ImageRect.Bottom) then
Begin
ImageRect.Right:=x;
ImageRect.Top:=y;
end;
teePrev_RightBottom : if (x<=PaperRect.Right) and (x>ImageRect.Left) and
(y<=PaperRect.Bottom) and (y>ImageRect.Top) then
Begin
ImageRect.Right:=x;
ImageRect.Bottom:=y;
end;
end;
RectSize(PaperRect,PaperWidth,PaperHeight);
if Assigned(Panel) then
begin
Panel.PrintProportional:=False;
With Panel.PrintMargins do
Begin
Left :=MulDiv((ImageRect.Left-PaperRect.Left),100,PaperWidth);
Right :=MulDiv((PaperRect.Right-ImageRect.Right),100,PaperWidth);
Top :=MulDiv((ImageRect.Top-PaperRect.Top),100,PaperHeight);
Bottom:=MulDiv((PaperRect.Bottom-ImageRect.Bottom),100,PaperHeight);
end;
end;
if Assigned(FOnChangeMargins) and Assigned(Panel) then
FOnChangeMargins(Self,True,Panel.PrintMargins);
if FDragImage then Invalidate
else DrawMargins(ImageRect);
end;
end;
end;
procedure TTeePreviewPanel.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
CancelMouse:=False; { 5.03 }
inherited;
if IDragged<>teePrev_None then
begin
IDragged:=teePrev_None;
if not FDragImage then Invalidate;
end;
end;
procedure TTeePreviewPanel.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
inherited;
IDragged:=WhereIsCursor(x,y);
if IDragged=teePrev_Image then
Begin
OldX:=x;
OldY:=y;
OldRect:=ImageRect;
end;
end;
Procedure TTeePreviewPanel.SetOrientation(Value:TTeePreviewPanelOrientation);
begin
if Value<>FOrientation then
begin
FOrientation:=Value;
Invalidate;
end;
end;
procedure TTeePreviewPanel.SetShadowColor(Value: TColor); // obsolete
begin
PaperShadow.Color:=Value;
end;
function TTeePreviewPanel.GetShadowColor: TColor; // obsolete
begin
result:=PaperShadow.Color;
end;
function TTeePreviewPanel.GetShadowSize: Integer; // obsolete
begin
result:=PaperShadow.Size;
end;
procedure TTeePreviewPanel.SetPaperShadow(Value: TTeeShadow);
begin
PaperShadow.Assign(Value);
end;
function TTeePreviewPanel.GetPanel: TCustomTeePanel;
begin
if Panels.Count=0 then result:=nil
else result:=Panels[0];
end;
{ TTeePanelsList }
function TTeePanelsList.Get(Index: Integer): TCustomTeePanel;
begin
result:=TCustomTeePanel(inherited Items[Index]);
end;
procedure TTeePanelsList.Put(Index: Integer; Value: TCustomTeePanel);
begin
inherited Items[Index]:=Value;
end;
{$IFDEF CLX}
function TPrinterSetupDialog.CreateForm: TDialogForm;
begin
result:=TDialogForm.CreateNew(nil);
end;
function TPrinterSetupDialog.DoExecute:Boolean;
begin
result:=Printer.ExecuteSetup;
end;
{ TPrintDialog }
function TPrintDialog.CreateForm: TDialogForm;
begin
result:=TDialogForm.CreateNew(nil);
end;
function TPrintDialog.DoExecute: Boolean;
begin
result:=Printer.ExecuteSetup;
end;
{$ENDIF}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -