"Post Window" -> "Post window" prevents it being seen as two separate
[supercollider.git] / QtCollider / widgets / QcPenPrinter.h
blob905c79061702a8be655fbc2cac5d7876aae9f3a5
1 /************************************************************************
3 * Copyright 2011 Jonatan Liljedahl <lijon@kymatica.com>
5 * This file is part of SuperCollider Qt GUI.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ************************************************************************/
22 #ifndef QC_PEN_PRINTER_H
23 #define QC_PEN_PRINTER_H
25 #include "../painting.h"
26 #include "../debug.h"
27 #include <QPrintDialog>
28 #include <QPrinter>
29 #include <QPainter>
31 class QcPenPrinter : public QObject
33 Q_OBJECT
34 Q_PROPERTY( QRect pageRect READ pageRect );
35 Q_PROPERTY( QRect paperRect READ paperRect );
36 Q_PROPERTY( int fromPage READ fromPage );
37 Q_PROPERTY( int toPage READ toPage );
39 public:
41 QcPenPrinter(): dialog(0) {}
43 ~QcPenPrinter() {
44 delete dialog;
47 QRect pageRect() const { return printer.pageRect(); }
48 QRect paperRect() const { return printer.paperRect(); }
49 int fromPage() const { return printer.fromPage(); }
50 int toPage() const { return printer.toPage(); }
52 Q_SIGNALS:
54 void dialogDone(int);
55 void printFunc();
57 private Q_SLOTS:
59 void show() {
60 if( !dialog ) {
61 dialog = new QPrintDialog(&printer);
62 dialog->setWindowTitle( QString("Print Document") );
63 dialog->setOptions (
64 QAbstractPrintDialog::PrintToFile |
65 QAbstractPrintDialog::PrintPageRange |
66 QAbstractPrintDialog::PrintShowPageSize
68 connect( dialog, SIGNAL(finished(int)), this, SIGNAL(dialogDone(int)) );
70 if( dialog->isVisible() )
71 qcWarningMsg("WARNING: Print dialog already open.");
72 else
73 dialog->exec();
76 void print() {
77 QPainter painter;
78 painter.begin(&printer);
79 QtCollider::beginPainting(&painter);
80 Q_EMIT ( printFunc() );
81 painter.end();
82 QtCollider::endPainting();
85 void newPage() {
86 printer.newPage();
89 private:
91 QPrinter printer;
92 QPrintDialog *dialog;
95 #endif // QC_PEN_PRINTER_H