summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLukáš Lalinský <lalinsky@gmail.com>2009-07-10 00:20:29 +0200
committerLukáš Lalinský <lalinsky@gmail.com>2009-07-10 00:20:29 +0200
commit3fd2b2342f7fe84d5e9338473293819d663941c3 (patch)
tree9920772211e3d710d369dd0235fcfaa57a439d96 /src
parent324d3cc714f66ecf3bcdea3d4f877ae177ef2bfa (diff)
downloaddbmodel-3fd2b2342f7fe84d5e9338473293819d663941c3.tar.xz
Use a shared printer
Diffstat (limited to 'src')
-rw-r--r--src/mainwindow.cpp25
-rw-r--r--src/mainwindow.h4
2 files changed, 21 insertions, 8 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 2de4853..1eb136e 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -48,12 +48,15 @@ class MainWindow::MainWindowPrivate
{
public:
MainWindowPrivate()
- {}
+ : printer(0)
+ {}
QDockWidget *itemPropsDock;
QStackedWidget *propertyEditorsStack;
QMap<QString, int> propertyEditorsIndexes;
+ QPrinter *printer;
+
QAction *printAction;
QAction *printPreviewAction;
@@ -513,25 +516,33 @@ MainWindow::exportDocument()
}
void
+MainWindow::initPrinter()
+{
+ if (!d->printer)
+ d->printer = new QPrinter();
+}
+
+void
MainWindow::print()
{
- QPrinter printer;
- QPrintDialog printDialog(&printer, this);
+ initPrinter();
+ QPrintDialog printDialog(d->printer, this);
if (printDialog.exec() == QDialog::Accepted) {
- paintOnPrinter(&printer);
+ printPreview(d->printer);
}
}
void
MainWindow::printPreview()
{
- QPrintPreviewDialog printPreviewDialog(this);
- connect(&printPreviewDialog, SIGNAL(paintRequested(QPrinter*)), SLOT(paintOnPrinter(QPrinter*)));
+ QPrintPreviewDialog printPreviewDialog(d->printer, this);
+ connect(&printPreviewDialog, SIGNAL(paintRequested(QPrinter*)),
+ SLOT(printPreview(QPrinter*)));
printPreviewDialog.exec();
}
void
-MainWindow::paintOnPrinter(QPrinter *printer)
+MainWindow::printPreview(QPrinter *printer)
{
QPainter painter(printer);
m_model->setPrinting(true);
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 6c1a094..7a77b8e 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -57,7 +57,7 @@ public slots:
void exportDocument();
void print();
void printPreview();
- void paintOnPrinter(QPrinter *);
+ void printPreview(QPrinter *);
void setViewScale(const QString &scale);
void about();
@@ -96,6 +96,8 @@ private:
class MainWindowPrivate;
MainWindowPrivate *const d;
+ void initPrinter();
+
DiagramView *m_view;
DiagramDocument *m_model;