Commit 1414513d authored by Yuri Chornoivan's avatar Yuri Chornoivan

Print preview for KmPlot

Differential Revision:
parent 4ec38cf9
......@@ -1220,7 +1220,28 @@ chapter of the &kde; Fundamentals documentation &kmplot; has these application s
<listitem><para><action>Exports</action> the plotted graphs to an image file in all formats supported by &kde;.</para></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>
<guimenuitem>Print Preview</guimenuitem>
<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>
<!DOCTYPE kpartgui>
<kpartgui name="kmplot" version="15">
<kpartgui name="kmplot" version="16">
<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"/>
<Action name="export"/>
......@@ -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 *>();
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;
QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok|QDialogButtonBox::Cancel );
connect(buttonBox, &QDialogButtonBox::accepted, [previewWidget, printSettingsDialog]{
} );
connect(buttonBox, &QDialogButtonBox::rejected, printSettingsDialog, &QDialog::reject);
connect(preview, &QPrintPreviewDialog::paintRequested, [this, &printdlg, &prt]{
setupPrinter(printdlg, &prt);
} );
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()
......@@ -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:
/// 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;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment