tvplanit: Show current page number and page count in PrintPreview.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8507 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-10-02 21:31:29 +00:00
parent d54c06b420
commit 6bf5ba0284
4 changed files with 63 additions and 3 deletions

View File

@ -107,6 +107,7 @@ type
FScrollY: Integer;
FOnPageChange: TVpPageChange;
FDefaultPopup: TPopupMenu;
function GetPageCount: Integer;
protected
function CalculatePageHeight(Printer: TPrinter): Integer;
@ -175,6 +176,7 @@ type
procedure ForceUpdate;
procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
property PageCount: Integer read GetPageCount;
property Printer: TPrinter read FPrinter write SetPrinter;
property DestPrinter: TPrinter read FPrinter write SetPrinter;
@ -506,6 +508,11 @@ begin
end;
end;
function TVpPrintPreview.GetPageCount: Integer;
begin
Result := FPageInfo.Count;
end;
procedure TVpPrintPreview.InitHScrollBar(PageSize, TotalSize: Integer);
var
ScrollBarInfo: TScrollInfo;

View File

@ -14,7 +14,6 @@ object frmPrintPreview: TfrmPrintPreview
OnCreate = FormCreate
OnKeyDown = FormKeyDown
OnShow = FormShow
LCLVersion = '2.3.0.0'
object Panel1: TPanel
Left = 0
Height = 56
@ -42,6 +41,7 @@ object frmPrintPreview: TfrmPrintPreview
ShowCaptions = True
ShowHint = True
TabOrder = 0
OnResize = ToolBar1Resize
object btnPrint: TToolButton
Left = 1
Top = 0
@ -50,7 +50,7 @@ object frmPrintPreview: TfrmPrintPreview
end
object ToolButton3: TToolButton
Left = 55
Height = 5
Height = 25
Top = 0
Caption = 'ToolButton3'
ImageIndex = 2
@ -86,7 +86,7 @@ object frmPrintPreview: TfrmPrintPreview
end
object ToolButton8: TToolButton
Left = 152
Height = 5
Height = 25
Top = 0
Caption = 'ToolButton8'
ImageIndex = 6
@ -98,6 +98,30 @@ object frmPrintPreview: TfrmPrintPreview
Action = actCancel
AutoSize = True
end
object pnlPageCount: TPanel
AnchorSideTop.Side = asrCenter
Left = 266
Height = 25
Top = 0
Width = 119
BevelOuter = bvNone
ClientHeight = 25
ClientWidth = 119
TabOrder = 0
object PageInfo: TLabel
AnchorSideTop.Control = pnlPageCount
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = pnlPageCount
AnchorSideRight.Side = asrBottom
Left = 64
Height = 15
Top = 5
Width = 47
Anchors = [akTop, akRight]
BorderSpacing.Right = 8
Caption = 'PageInfo'
end
end
end
object Panel2: TPanel
Left = 0

View File

@ -3,6 +3,7 @@
{"hash":106991073,"name":"tfrmprintpreview.toolbar1.caption","sourcebytes":[84,111,111,108,66,97,114,49],"value":"ToolBar1"},
{"hash":160486419,"name":"tfrmprintpreview.toolbutton3.caption","sourcebytes":[84,111,111,108,66,117,116,116,111,110,51],"value":"ToolButton3"},
{"hash":160486424,"name":"tfrmprintpreview.toolbutton8.caption","sourcebytes":[84,111,111,108,66,117,116,116,111,110,56],"value":"ToolButton8"},
{"hash":131727791,"name":"tfrmprintpreview.pageinfo.caption","sourcebytes":[80,97,103,101,73,110,102,111],"value":"PageInfo"},
{"hash":45584468,"name":"tfrmprintpreview.actprint.caption","sourcebytes":[38,80,114,105,110,116],"value":"&Print"},
{"hash":5738580,"name":"tfrmprintpreview.actprint.hint","sourcebytes":[80,114,105,110,116],"value":"Print"},
{"hash":172865349,"name":"tfrmprintpreview.actfirstpage.caption","sourcebytes":[38,70,105,114,115,116,32,112,97,103,101],"value":"&First page"},

View File

@ -51,10 +51,12 @@ type
TfrmPrintPreview = class(TForm)
Bevel1: TBevel;
PageInfo: TLabel;
Panel1: TPanel;
cboxZoom: TComboBox;
btnCancel: TToolButton;
Panel2: TPanel;
pnlPageCount: TPanel;
VpPrintPreview1: TVpPrintPreview;
VpPrintFormatComboBox1: TVpPrintFormatComboBox;
ToolBar1: TToolBar;
@ -86,6 +88,7 @@ type
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure ToolBar1Resize(Sender: TObject);
procedure VpPrintFormatComboBox1Change(Sender: TObject);
private
@ -93,6 +96,7 @@ type
procedure PopulateImageList;
procedure SetCaptions;
procedure SetDrawingStyle(AValue: TVpDrawingStyle);
procedure UpdatePageInfo;
public
Resource: TVpResource;
@ -234,6 +238,7 @@ procedure TfrmPrintPreview.VpPrintFormatComboBox1Change(Sender: TObject);
begin
VpPrintPreview1.ForceUpdate;
VpPrintPreview1.FirstPage;
UpdatePageInfo;
end;
procedure TfrmPrintPreview.OKBtnClick(Sender: TObject);
@ -280,6 +285,7 @@ begin
EditForm.VpPrintPreview1.ForceUpdate;
EditForm.VpPrintPreview1.FirstPage;
EditForm.DrawingStyle := FDrawingStyle;
// EditForm.PageInfo.Caption := Format('%d pages', [EditForm.VpPrintPreview1.PageCount]);
EditForm.ShowModal;
if EditForm.ReturnCode = rtCommit then begin
Result := True;
@ -383,6 +389,9 @@ begin
VpPrintPreview1.ZoomFactor := TVpPPZoomFactor(cboxZoom.ItemIndex);
end;
{ Print button clicked. The PrintView form itself does not send anything to
the printer. The calling procedure - in this case: the PrintPreviewDialog.Execute
method - must do this if the ReturnCode of the PrintPreview is rtCommit. }
procedure TfrmPrintPreview.actPrintExecute(Sender: TObject);
begin
ReturnCode := rtCommit;
@ -392,23 +401,29 @@ end;
procedure TfrmPrintPreview.actFirstPageExecute(Sender: TObject);
begin
VpPrintPreview1.FirstPage;
UpdatePageInfo;
end;
procedure TfrmPrintPreview.actPrevPageExecute(Sender: TObject);
begin
VpPrintPreview1.PrevPage;
UpdatePageInfo;
end;
procedure TfrmPrintPreview.actNextPageExecute(Sender: TObject);
begin
VpPrintPreview1.NextPage;
UpdatePageInfo;
end;
procedure TfrmPrintPreview.actLastPageExecute(Sender: TObject);
begin
VpPrintPreview1.LastPage;
UpdatePageInfo;
end;
{ OnUpdate handler for the main form actionlist. Enables/disables the actions
(first/previous/next/last page buttons). }
procedure TfrmPrintPreview.actMainUpdate(Action: TBasicAction;
var Handled: Boolean);
begin
@ -457,6 +472,9 @@ var
begin
if VpPrintPreview1.ControlLink = nil then
exit;
UpdatePageInfo;
(*
cnv := TControlCanvas.Create;
try
@ -475,5 +493,15 @@ begin
end;*)
end;
procedure TfrmPrintPreview.ToolBar1Resize(Sender: TObject);
begin
pnlPageCount.Width := Toolbar1.ClientWidth - pnlPageCount.Left;
end;
procedure TfrmPrintPreview.UpdatePageInfo;
begin
PageInfo.Caption := Format('page %d of %d', [VpPrintPreview1.CurPage+1, VpPrintPreview1.PageCount]);
end;
end.