diff --git a/doc/index.docbook b/doc/index.docbook --- a/doc/index.docbook +++ b/doc/index.docbook @@ -1195,6 +1195,21 @@ Exports the plotted graphs to an image file in all formats supported by &kde;. + + + + File + Print... + Opens print configuration window. Press the Options >> button then choose the KmPlot Options tab to configure options that are specific for &kmplot;. + + + + + + File + Print Preview + Shows the preliminary image of the current plot as printed on the current default printer. Press the rightmost button on the toolbar of the print preview window to configure options that are specific for &kmplot;. + diff --git a/kmplot/kmplot_part.rc b/kmplot/kmplot_part.rc --- a/kmplot/kmplot_part.rc +++ b/kmplot/kmplot_part.rc @@ -1,12 +1,13 @@ - + + diff --git a/kmplot/maindlg.h b/kmplot/maindlg.h --- a/kmplot/maindlg.h +++ b/kmplot/maindlg.h @@ -31,6 +31,7 @@ // Qt includes #include #include +#include #include #include @@ -107,7 +108,6 @@ /// Check whether the url links to an existing file static bool fileExists(const QUrl &url); - public Q_SLOTS: // DBus interface /// Asks the user and returns true if modified data shall be discarded. @@ -134,6 +134,8 @@ void slotSaveas(); ///Print the current plot void slotPrint(); + /// For calling print preview functionality + void slotPrintPreview(); ///Export the current plot as a png, svg or bmp picture void slotExport(); ///Implement the Configure KmPlot dialog @@ -211,6 +213,8 @@ QAction * m_undoAction; /// The redo action QAction * m_redoAction; + /// The print preview action + QAction* m_filePrintPreview; /// A pointer to ourselves static MainDlg * m_self; diff --git a/kmplot/maindlg.cpp b/kmplot/maindlg.cpp --- a/kmplot/maindlg.cpp +++ b/kmplot/maindlg.cpp @@ -37,6 +37,8 @@ #include #include #include +#include +#include #include #include #include @@ -230,6 +232,7 @@ m_recentFiles = KStandardAction::openRecent( this, SLOT(slotOpenRecent(QUrl)), this ); actionCollection()->addAction( "file_open_recent", m_recentFiles ); actionCollection()->addAction( KStandardAction::Print, "file_print", this, SLOT(slotPrint()) ); + actionCollection()->addAction( KStandardAction::PrintPreview, "file_print_preview", this, SLOT(slotPrintPreview()) ); KStandardAction::save( this, SLOT(slotSave()), actionCollection() ); KStandardAction::saveAs( this, SLOT(slotSaveas()), actionCollection() ); @@ -693,6 +696,43 @@ delete printDialog; } +void MainDlg::slotPrintPreview() +{ + QPrinter prt( QPrinter::PrinterResolution ); + prt.setResolution( 72 ); + QPrintPreviewDialog preview( &prt ); + KPrinterDlg* printdlg = new KPrinterDlg( m_parent ); + QList toolbarlist = preview.findChildren(); + if(!toolbarlist.isEmpty()) + { + QAction *printSettings = toolbarlist.first()->addAction( QIcon::fromTheme( "configure" ), i18n("Print Settings") ); + QList previewWidgetsList = preview.findChildren(); + QPrintPreviewWidget *previewWidget = previewWidgetsList.first(); + connect( printSettings, &QAction::triggered, [&preview, previewWidget, printdlg, &prt]{ + QDialog *printSettingsDialog = new QDialog( &preview, Qt::WindowFlags() ); + printSettingsDialog->setWindowTitle( i18n("Print Settings") ); + QVBoxLayout *mainLayout = new QVBoxLayout; + printSettingsDialog->setLayout(mainLayout); + mainLayout->addWidget(printdlg); + QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok|QDialogButtonBox::Cancel ); + connect(buttonBox, &QDialogButtonBox::accepted, [previewWidget, printSettingsDialog]{ + previewWidget->updatePreview(); + printSettingsDialog->close(); + } ); + connect(buttonBox, &QDialogButtonBox::rejected, printSettingsDialog, &QDialog::reject); + mainLayout->addWidget(buttonBox); + printSettingsDialog->show(); + }); + } + connect(&preview, &QPrintPreviewDialog::paintRequested, [&printdlg](QPrinter *p){ + View::self()->setPrintHeaderTable( printdlg->printHeaderTable() ); + View::self()->setPrintBackground( printdlg->printBackground() ); + View::self()->setPrintWidth( printdlg->printWidth() ); + View::self()->setPrintHeight( printdlg->printHeight() ); + View::self()->draw( p, View::Printer ); + } ); + preview.exec(); +} void MainDlg::editAxes() {