[kmplot] /: Print preview for KmPlot
Yuri Chornoivan
null at kde.org
Wed Jan 16 08:50:17 GMT 2019
Git commit 1414513d4479c164b4d6c547d963d8ee8a29fbbf by Yuri Chornoivan.
Committed on 16/01/2019 at 08:50.
Pushed by yurchor into branch 'master'.
Print preview for KmPlot
Differential Revision: https://phabricator.kde.org/D17626
M +22 -1 doc/index.docbook
M +2 -1 kmplot/kmplot_part.rc
M +47 -7 kmplot/maindlg.cpp
M +6 -0 kmplot/maindlg.h
https://commits.kde.org/kmplot/1414513d4479c164b4d6c547d963d8ee8a29fbbf
diff --git a/doc/index.docbook b/doc/index.docbook
index 0af1f56..b65eb2b 100644
--- a/doc/index.docbook
+++ b/doc/index.docbook
@@ -1220,7 +1220,28 @@ chapter of the &kde; Fundamentals documentation &kmplot; has these application s
<guimenuitem>Export...</guimenuitem></menuchoice></term>
<listitem><para><action>Exports</action> the plotted graphs to an image file in all formats supported by &kde;.</para></listitem>
</varlistentry>
-
+ <varlistentry>
+ <term>
+ <menuchoice>
+ <guimenu>File</guimenu>
+ <guimenuitem>Print...</guimenuitem>
+ </menuchoice>
+ </term>
+ <listitem>
+ <para><action>Opens</action> print configuration window. Press the <guibutton>Options >></guibutton> button then choose the <guilabel>KmPlot Options</guilabel> tab to configure options that are specific for &kmplot;.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>
+ <menuchoice>
+ <guimenu>File</guimenu>
+ <guimenuitem>Print Preview</guimenuitem>
+ </menuchoice>
+ </term>
+ <listitem>
+ <para><action>Shows</action> 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;.</para>
+ </listitem>
+ </varlistentry>
</variablelist>
</sect2>
diff --git a/kmplot/kmplot_part.rc b/kmplot/kmplot_part.rc
index 21034d1..e59a07c 100644
--- a/kmplot/kmplot_part.rc
+++ b/kmplot/kmplot_part.rc
@@ -1,5 +1,5 @@
<!DOCTYPE kpartgui>
-<kpartgui name="kmplot" version="15">
+<kpartgui name="kmplot" version="16">
<MenuBar>
<Menu name="file">
<Action name="file_open_recent"/>
@@ -7,6 +7,7 @@
<Action name="file_save"/>
<Action name="file_save_as"/>
<Action name="file_print"/>
+ <Action name="file_print_preview"/>
<Separator/>
<Action name="export"/>
</Menu>
diff --git a/kmplot/maindlg.cpp b/kmplot/maindlg.cpp
index 858b092..a5a624e 100644
--- a/kmplot/maindlg.cpp
+++ b/kmplot/maindlg.cpp
@@ -37,7 +37,8 @@
#include <QMimeType>
#include <QPixmap>
#include <QPrintDialog>
-#include <QPrinter>
+#include <QPrintPreviewDialog>
+#include <QPrintPreviewWidget>
#include <QStandardPaths>
#include <QSvgGenerator>
#include <QTemporaryFile>
@@ -60,7 +61,6 @@
#include "calculator.h"
#include "functiontools.h"
#include "functioneditor.h"
-#include "kprinterdlg.h"
#include "kconstanteditor.h"
#include "xparser.h"
@@ -232,6 +232,7 @@ void MainDlg::setupActions()
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() );
@@ -708,15 +709,54 @@ void MainDlg::slotPrint()
if (printDialog->exec())
{
- View::self()->setPrintHeaderTable( printdlg->printHeaderTable() );
- View::self()->setPrintBackground( printdlg->printBackground() );
- View::self()->setPrintWidth( printdlg->printWidth() );
- View::self()->setPrintHeight( printdlg->printHeight() );
- View::self()->draw(&prt, View::Printer);
+ setupPrinter(printdlg, &prt);
}
delete printDialog;
}
+void MainDlg::slotPrintPreview()
+{
+ QPrinter prt( QPrinter::PrinterResolution );
+ QPointer<QPrintPreviewDialog> preview = new QPrintPreviewDialog( &prt );
+ QPointer<KPrinterDlg> printdlg = new KPrinterDlg( m_parent );
+ QList<QToolBar *> toolbarlist = preview->findChildren<QToolBar *>();
+ if(!toolbarlist.isEmpty())
+ {
+ QAction *printSettings = toolbarlist.first()->addAction( QIcon::fromTheme( "configure" ), i18n("Print Settings") );
+ QList<QPrintPreviewWidget*> previewWidgetsList = preview->findChildren<QPrintPreviewWidget*>();
+ 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, [this, &printdlg, &prt]{
+ setupPrinter(printdlg, &prt);
+ } );
+ preview->exec();
+ delete printdlg;
+ delete preview;
+}
+
+void MainDlg::setupPrinter(KPrinterDlg *printDialog, QPrinter *printer)
+{
+ View::self()->setPrintHeaderTable( printDialog->printHeaderTable() );
+ View::self()->setPrintBackground( printDialog->printBackground() );
+ View::self()->setPrintWidth( printDialog->printWidth() );
+ View::self()->setPrintHeight( printDialog->printHeight() );
+ View::self()->draw(printer, View::Printer);
+}
void MainDlg::editAxes()
{
diff --git a/kmplot/maindlg.h b/kmplot/maindlg.h
index 0f57b79..318b4be 100644
--- a/kmplot/maindlg.h
+++ b/kmplot/maindlg.h
@@ -31,6 +31,7 @@
// Qt includes
#include <QDomDocument>
#include <QMenu>
+#include <QPrinter>
#include <QStack>
#include <QStandardPaths>
@@ -47,6 +48,7 @@
#include "coordsconfigdialog.h"
#include "view.h"
#include "kmplotio.h"
+#include "kprinterdlg.h"
class BrowserExtension;
class Calculator;
@@ -134,6 +136,8 @@ public slots:
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
@@ -151,6 +155,8 @@ public slots:
private:
/// Settings the standard and non standard actions of the application.
void setupActions();
+ /// Sets the printer options and draw the plot with the current options.
+ void setupPrinter(KPrinterDlg *printDialog, QPrinter *printer);
/// Called when a file is opened. The filename is m_url
bool openFile() Q_DECL_OVERRIDE;
More information about the kde-doc-english
mailing list