diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mainwindow.cpp | 32 | ||||
-rw-r--r-- | src/mainwindow.h | 4 |
2 files changed, 32 insertions, 4 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 85a526d..244cf4a 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -27,6 +27,7 @@ #include <QSettings> #include <QPrinter> #include <QPrintDialog> +#include <QPrintPreviewDialog> #include <QMessageBox> #include <QDebug> #include <QDockWidget> @@ -54,6 +55,7 @@ public: QMap<QString, int> propertyEditorsIndexes; QAction *printAction; + QAction *printPreviewAction; QActionGroup *notationActionGroup; QMenu *notationMenu; @@ -224,8 +226,15 @@ MainWindow::setupActions() d->printAction = new QAction(this); d->printAction->setText(tr("&Print...")); d->printAction->setIcon(loadIcon("document-print")); + d->printAction->setShortcut(QKeySequence(tr("Ctrl+P"))); connect(d->printAction, SIGNAL(triggered(bool)), SLOT(print())); + d->printPreviewAction = new QAction(this); + d->printPreviewAction->setText(tr("Print Previe&w...")); + d->printPreviewAction->setIcon(loadIcon("document-print-preview")); + d->printPreviewAction->setShortcut(QKeySequence(tr("Ctrl+Shift+P"))); + connect(d->printPreviewAction, SIGNAL(triggered(bool)), SLOT(printPreview())); + for (int i = 0; i < MaxRecentFiles; i++) { m_actionRecentFile[i] = new QAction(this); m_actionRecentFile[i]->setVisible(false); @@ -386,6 +395,7 @@ MainWindow::setupMenuBar() menu->addSeparator(); menu->addAction(m_actionExportPNG); + menu->addAction(d->printPreviewAction); menu->addAction(d->printAction); m_actionRecentFilesSeparator = menu->addSeparator(); for (int i = 0; i < MaxRecentFiles; i++) @@ -508,14 +518,28 @@ MainWindow::print() QPrinter printer; QPrintDialog printDialog(&printer, this); if (printDialog.exec() == QDialog::Accepted) { - QPainter painter(&printer); - m_model->setPrinting(true); - m_model->render(&painter); - m_model->setPrinting(false); + paintOnPrinter(&printer); } } void +MainWindow::printPreview() +{ + QPrintPreviewDialog printPreviewDialog(this); + connect(&printPreviewDialog, SIGNAL(paintRequested(QPrinter*)), SLOT(paintOnPrinter(QPrinter*))); + printPreviewDialog.exec(); +} + +void +MainWindow::paintOnPrinter(QPrinter *printer) +{ + QPainter painter(printer); + m_model->setPrinting(true); + m_model->render(&painter); + m_model->setPrinting(false); +} + +void MainWindow::newModel(DiagramDocument *newModel) { if (!newModel) { diff --git a/src/mainwindow.h b/src/mainwindow.h index 4f059cc..6c1a094 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -26,6 +26,8 @@ #include "diagramview.h" #include "diagramdocument.h" +class QPrinter; + class MainWindow: public QMainWindow { Q_OBJECT @@ -54,6 +56,8 @@ public slots: bool saveAs(); void exportDocument(); void print(); + void printPreview(); + void paintOnPrinter(QPrinter *); void setViewScale(const QString &scale); void about(); |