From 99b58efb540c67bc98601db4b277c6aad70967b0 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Sun, 3 Jul 2016 14:47:03 +0000 Subject: [PATCH] tvplanit: Initial version with printing capabilities (still lots of bugs...) git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4903 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/tvplanit/examples/demo/demo.lpi | 9 +- components/tvplanit/examples/demo/demo.lpr | 3 +- .../tvplanit/examples/demo/demomain.lfm | 86 +++++++++++++++++-- .../tvplanit/examples/demo/demomain.lrt | 2 + .../tvplanit/examples/demo/demomain.pas | 58 +++++++++++-- components/tvplanit/languages/demo.de.po | 8 ++ components/tvplanit/languages/demo.po | 8 ++ components/tvplanit/source/vpprtprvdlg.pas | 2 +- 8 files changed, 155 insertions(+), 21 deletions(-) diff --git a/components/tvplanit/examples/demo/demo.lpi b/components/tvplanit/examples/demo/demo.lpi index b100b9b08..b570d4199 100644 --- a/components/tvplanit/examples/demo/demo.lpi +++ b/components/tvplanit/examples/demo/demo.lpi @@ -28,13 +28,16 @@ - + - + - + + + + diff --git a/components/tvplanit/examples/demo/demo.lpr b/components/tvplanit/examples/demo/demo.lpr index cb6c898e8..05674537a 100644 --- a/components/tvplanit/examples/demo/demo.lpr +++ b/components/tvplanit/examples/demo/demo.lpr @@ -7,7 +7,8 @@ uses cthreads, {$ENDIF}{$ENDIF} Interfaces, // this includes the LCL widgetset - Forms, demoMain, laz_visualplanit, LCLTranslator, DefaultTranslator; + Forms, demoMain, laz_visualplanit, LCLTranslator, DefaultTranslator, + printer4lazarus; {$R *.res} diff --git a/components/tvplanit/examples/demo/demomain.lfm b/components/tvplanit/examples/demo/demomain.lfm index f36b5f3da..67145af51 100644 --- a/components/tvplanit/examples/demo/demomain.lfm +++ b/components/tvplanit/examples/demo/demomain.lfm @@ -689,15 +689,52 @@ object MainForm: TMainForm object VpControlLink1: TVpControlLink DataStore = VpBufDSDataStore1 LocalizationFile = '../../source/vplocalize.xml' - Printer.BottomMargin = 0 - Printer.DayStart = h_08 - Printer.DayEnd = h_05 - Printer.Granularity = gr30Min - Printer.LeftMargin = 0 - Printer.MarginUnits = imAbsolutePixel - Printer.PrintFormats = <> - Printer.RightMargin = 0 - Printer.TopMargin = 0 + Printer.BottomMargin = 5 + Printer.DayStart = h_07 + Printer.DayEnd = h_18 + Printer.Granularity = gr60Min + Printer.LeftMargin = 5 + Printer.MarginUnits = imPercent + Printer.PrintFormats = < + item + Version = 'v1.04' + DayInc = 0 + DayIncUnits = duDay + Elements = < + item + Version = 'v1.04' + Caption.Caption = 'Current week' + Caption.Font.Style = [fsItalic] + DayOffset = 1 + DayOffsetUnits = duDay + Height = 100 + Left = 0 + Shape.Shape = ustRectangle + Top = 0 + Width = 100 + end> + FormatName = 'Current week (dayview)' + end + item + Version = 'v1.04' + DayInc = 0 + DayIncUnits = duWeek + Elements = < + item + Version = 'v1.04' + DayOffset = 0 + DayOffsetUnits = duDay + Height = 100 + ItemType = itWeekView + Left = 0 + Shape.Shape = ustRectangle + Top = 0 + Width = 100 + end> + FormatName = 'Current week (Week view)' + end> + Printer.RightMargin = 5 + Printer.TopMargin = 5 left = 312 top = 200 end @@ -1910,6 +1947,13 @@ object MainForm: TMainForm top = 221 object MenuItem1: TMenuItem Caption = 'File' + object MnuPrintPreview: TMenuItem + Caption = 'Print preview...' + OnClick = MnuPrintPreviewClick + end + object MenuItem3: TMenuItem + Caption = '-' + end object MnuQuit: TMenuItem Caption = 'Quit' OnClick = MnuQuitClick @@ -1934,4 +1978,28 @@ object MainForm: TMainForm end end end + object PrintDialog1: TPrintDialog + left = 560 + top = 128 + end + object VpPrintPreviewDialog1: TVpPrintPreviewDialog + Version = 'v1.04' + DataStore = VpBufDSDataStore1 + BottomMargin = 5 + ControlLink = VpControlLink1 + EndDate = 42561.5151169907 + LeftMargin = 5 + MarginUnits = imPercent + RightMargin = 5 + StartDate = 42554.5151169907 + TopMargin = 5 + Options = [doSizeable] + Placement.Position = mpCenter + Placement.Top = 10 + Placement.Left = 10 + Placement.Height = 500 + Placement.Width = 1000 + left = 560 + top = 192 + end end diff --git a/components/tvplanit/examples/demo/demomain.lrt b/components/tvplanit/examples/demo/demomain.lrt index 1aa6ec81b..32f25be29 100644 --- a/components/tvplanit/examples/demo/demomain.lrt +++ b/components/tvplanit/examples/demo/demomain.lrt @@ -23,6 +23,8 @@ TMAINFORM.COMBOBOX1.TEXT=ComboBox1 TMAINFORM.CBDRAWINGSTYLE.TEXT=flat TMAINFORM.TITLELBL.CAPTION=TitleLbl TMAINFORM.MENUITEM1.CAPTION=File +TMAINFORM.MNUPRINTPREVIEW.CAPTION=Print preview... +TMAINFORM.MENUITEM3.CAPTION=- TMAINFORM.MNUQUIT.CAPTION=Quit TMAINFORM.MNUMAINTENANCE.CAPTION=Maintenance TMAINFORM.MNURESOURCES.CAPTION=Resources diff --git a/components/tvplanit/examples/demo/demomain.pas b/components/tvplanit/examples/demo/demomain.pas index 722dd31a5..ecc185aaf 100644 --- a/components/tvplanit/examples/demo/demomain.pas +++ b/components/tvplanit/examples/demo/demomain.pas @@ -5,11 +5,10 @@ unit demoMain; interface uses - Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls, - StdCtrls, ComCtrls, LCLTranslator, Menus, - VpBaseDS, VpDayView, VpWeekView, VpTaskList, VpAbout, - VpContactGrid, VpMonthView, VpResEditDlg, VpContactButtons, VpBufDS, VpNavBar, - VpData, Types; + Classes, SysUtils, FileUtil, PrintersDlgs, Forms, Controls, Graphics, Dialogs, + ExtCtrls, StdCtrls, ComCtrls, LCLTranslator, Menus, VpBaseDS, VpDayView, + VpWeekView, VpTaskList, VpAbout, VpContactGrid, VpMonthView, VpResEditDlg, + VpContactButtons, VpBufDS, VpNavBar, VpData, VpPrtPrvDlg, Types; type @@ -36,6 +35,9 @@ type LblGranularity: TLabel; LblLanguage: TLabel; LblVisibleDays: TLabel; + MenuItem3: TMenuItem; + MnuPrintPreview: TMenuItem; + PrintDialog1: TPrintDialog; TitleLbl: TLabel; MainMenu1: TMainMenu; MenuItem1: TMenuItem; @@ -68,6 +70,7 @@ type VpDayView1: TVpDayView; VpMonthView1: TVpMonthView; VpNavBar1: TVpNavBar; + VpPrintPreviewDialog1: TVpPrintPreviewDialog; VpResourceCombo1: TVpResourceCombo; VpResourceEditDialog1: TVpResourceEditDialog; VpTaskList1: TVpTaskList; @@ -85,6 +88,7 @@ type procedure CbTimeFormatChange(Sender: TObject); procedure FormCloseQuery(Sender: TObject; var CanClose: boolean); procedure FormCreate(Sender: TObject); + procedure MnuPrintPreviewClick(Sender: TObject); procedure MnuQuitClick(Sender: TObject); procedure MnuResourcesClick(Sender: TObject); procedure MnuSettingsClick(Sender: TObject); @@ -129,8 +133,9 @@ uses {$IFDEF WINDOWS} Windows, {$ENDIF} - LResources, LazFileUtils, LazUTF8, StrUtils, Translations, IniFiles, Math, - VpMisc, VpBase; + LResources, LazFileUtils, LazUTF8, StrUtils, DateUtils, Translations, + IniFiles, Math, Printers, + VpMisc, VpBase, VpPrtFmt; const LANGUAGE_DIR = '..\..\languages\'; @@ -348,6 +353,45 @@ begin end; end; +procedure TMainForm.MnuPrintPreviewClick(Sender: TObject); +var + t1, t2: TDateTime; + fmt: TVpPrintFormatItem; + fmtidx: Integer; +begin + fmtidx := VpPrintPreviewDialog1.ControlLink.Printer.CurFormat; + fmt := VpPrintPreviewDialog1.ControlLink.Printer.PrintFormats.Items[fmtidx]; + case fmtidx of + 0: begin // current week in DayView + t1 := StartOfTheWeek(now); + t2 := t1 + 7 - VpDayView1.NumDays mod 7; // + 7; + fmt.DayInc := VpDayView1.NumDays; + VpControlLink1.Printer.Granularity := VpDayView1.Granularity; + VpControlLink1.Printer.DayStart := h_08; //VpDayView1.DefaultTopHour; + VpControlLink1.Printer.DayEnd := h_17; + end; + 1: begin // current week in WeekView + t1 := StartOfTheWeek(now); + t2 := t1; // it all fits on one single page + end; + end; + VpPrintPreviewDialog1.ControlLink := VpControlLink1; + VpPrintPreviewDialog1.Printer := Printer; + VpPrintPreviewDialog1.StartDate := t1; + VPPrintPreviewDialog1.EndDate := t2; + if VpPrintPreviewDialog1.Execute then + if PrintDialog1.Execute then begin + Printer.BeginDoc; + try + t1 := VpPrintPreviewDialog1.StartDate; + t2 := VpPrintPreviewDialog1.EndDate; + VpPrintPreviewDialog1.ControlLink.Printer.Print(Printer, t1, t2); + finally + Printer.EndDoc; + end; + end; +end; + procedure TMainForm.MnuSettingsClick(Sender: TObject); begin ShowSettings; diff --git a/components/tvplanit/languages/demo.de.po b/components/tvplanit/languages/demo.de.po index bc508f9cd..717b89653 100644 --- a/components/tvplanit/languages/demo.de.po +++ b/components/tvplanit/languages/demo.de.po @@ -256,6 +256,10 @@ msgstr "Datei" msgid "Help" msgstr "Hilfe" +#: tmainform.menuitem3.caption +msgid "-" +msgstr "" + #: tmainform.mnuabout.caption msgid "About Visual PlanIt" msgstr "Über Visual PlanIt" @@ -265,6 +269,10 @@ msgctxt "tmainform.mnumaintenance.caption" msgid "Maintenance" msgstr "Wartung" +#: tmainform.mnuprintpreview.caption +msgid "Print preview..." +msgstr "" + #: tmainform.mnuquit.caption msgid "Quit" msgstr "Beenden" diff --git a/components/tvplanit/languages/demo.po b/components/tvplanit/languages/demo.po index cdb129516..c080e1710 100644 --- a/components/tvplanit/languages/demo.po +++ b/components/tvplanit/languages/demo.po @@ -245,6 +245,10 @@ msgstr "" msgid "Help" msgstr "" +#: tmainform.menuitem3.caption +msgid "-" +msgstr "" + #: tmainform.mnuabout.caption msgid "About Visual PlanIt" msgstr "" @@ -254,6 +258,10 @@ msgctxt "TMAINFORM.MNUMAINTENANCE.CAPTION" msgid "Maintenance" msgstr "" +#: tmainform.mnuprintpreview.caption +msgid "Print preview..." +msgstr "" + #: tmainform.mnuquit.caption msgid "Quit" msgstr "" diff --git a/components/tvplanit/source/vpprtprvdlg.pas b/components/tvplanit/source/vpprtprvdlg.pas index f044f1a08..151ea1660 100644 --- a/components/tvplanit/source/vpprtprvdlg.pas +++ b/components/tvplanit/source/vpprtprvdlg.pas @@ -202,7 +202,7 @@ constructor TVpPrintPreviewDialog.Create(AOwner: TComponent); begin inherited Create (AOwner); FPlacement.Height := 480; - FPlacement.Width := 640; + FPlacement.Width := 720; StartDate := Now; EndDate := Now + 7; FZoomFactor := zfFitToControl;