Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/printsupport/dialogs/qprintpreviewdialog.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||
2 | ** | - | ||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||
5 | ** | - | ||||||||||||
6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||||||||
7 | ** | - | ||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||
16 | ** | - | ||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||
25 | ** | - | ||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||
29 | ** | - | ||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||
31 | ** | - | ||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||
33 | - | |||||||||||||
34 | #include "qprintpreviewdialog.h" | - | ||||||||||||
35 | #include "qprintpreviewwidget.h" | - | ||||||||||||
36 | #include <private/qprinter_p.h> | - | ||||||||||||
37 | #include "private/qdialog_p.h" | - | ||||||||||||
38 | #include "qprintdialog.h" | - | ||||||||||||
39 | - | |||||||||||||
40 | #include <QtWidgets/qaction.h> | - | ||||||||||||
41 | #include <QtWidgets/qboxlayout.h> | - | ||||||||||||
42 | #include <QtWidgets/qcombobox.h> | - | ||||||||||||
43 | #include <QtWidgets/qlabel.h> | - | ||||||||||||
44 | #include <QtWidgets/qlineedit.h> | - | ||||||||||||
45 | #include <QtPrintSupport/qpagesetupdialog.h> | - | ||||||||||||
46 | #include <QtPrintSupport/qprinter.h> | - | ||||||||||||
47 | #include <QtWidgets/qstyle.h> | - | ||||||||||||
48 | #include <QtWidgets/qtoolbutton.h> | - | ||||||||||||
49 | #include <QtGui/qvalidator.h> | - | ||||||||||||
50 | #include <QtWidgets/qfiledialog.h> | - | ||||||||||||
51 | #include <QtWidgets/qmainwindow.h> | - | ||||||||||||
52 | #include <QtWidgets/qtoolbar.h> | - | ||||||||||||
53 | #include <QtWidgets/qformlayout.h> | - | ||||||||||||
54 | #include <QtCore/QCoreApplication> | - | ||||||||||||
55 | - | |||||||||||||
56 | #ifndef QT_NO_PRINTPREVIEWDIALOG | - | ||||||||||||
57 | - | |||||||||||||
58 | static void initResources() | - | ||||||||||||
59 | { | - | ||||||||||||
60 | static bool resourcesInitialized = false; | - | ||||||||||||
61 | if (!resourcesInitialized) {
| 0-1 | ||||||||||||
62 | Q_INIT_RESOURCE(qprintdialog); | - | ||||||||||||
63 | resourcesInitialized = true; | - | ||||||||||||
64 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
65 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
66 | - | |||||||||||||
67 | QT_BEGIN_NAMESPACE | - | ||||||||||||
68 | - | |||||||||||||
69 | namespace { | - | ||||||||||||
70 | class QPrintPreviewMainWindow : public QMainWindow | - | ||||||||||||
71 | { | - | ||||||||||||
72 | public: | - | ||||||||||||
73 | QPrintPreviewMainWindow(QWidget *parent) : QMainWindow(parent) {} executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
74 | QMenu *createPopupMenu() Q_DECL_OVERRIDE { return 0; } never executed: return 0; | 0 | ||||||||||||
75 | }; | - | ||||||||||||
76 | - | |||||||||||||
77 | class ZoomFactorValidator : public QDoubleValidator | - | ||||||||||||
78 | { | - | ||||||||||||
79 | public: | - | ||||||||||||
80 | ZoomFactorValidator(QObject* parent) | - | ||||||||||||
81 | : QDoubleValidator(parent) {} never executed: end of block | 0 | ||||||||||||
82 | ZoomFactorValidator(qreal bottom, qreal top, int decimals, QObject *parent) | - | ||||||||||||
83 | : QDoubleValidator(bottom, top, decimals, parent) {} executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
84 | - | |||||||||||||
85 | State validate(QString &input, int &pos) const Q_DECL_OVERRIDE | - | ||||||||||||
86 | { | - | ||||||||||||
87 | bool replacePercent = false; | - | ||||||||||||
88 | if (input.endsWith(QLatin1Char('%'))) {
| 0-4 | ||||||||||||
89 | input = input.left(input.length() - 1); | - | ||||||||||||
90 | replacePercent = true; | - | ||||||||||||
91 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||
92 | State state = QDoubleValidator::validate(input, pos); | - | ||||||||||||
93 | if (replacePercent)
| 0-4 | ||||||||||||
94 | input += QLatin1Char('%'); executed 4 times by 1 test: input += QLatin1Char('%'); Executed by:
| 4 | ||||||||||||
95 | const int num_size = 4; | - | ||||||||||||
96 | if (state == Intermediate) {
| 0-4 | ||||||||||||
97 | int i = input.indexOf(QLocale::system().decimalPoint()); | - | ||||||||||||
98 | if ((i == -1 && input.size() > num_size)
| 0 | ||||||||||||
99 | || (i != -1 && i > num_size))
| 0 | ||||||||||||
100 | return Invalid; never executed: return Invalid; | 0 | ||||||||||||
101 | } never executed: end of block | 0 | ||||||||||||
102 | return state; executed 4 times by 1 test: return state; Executed by:
| 4 | ||||||||||||
103 | } | - | ||||||||||||
104 | }; | - | ||||||||||||
105 | - | |||||||||||||
106 | class LineEdit : public QLineEdit | - | ||||||||||||
107 | { | - | ||||||||||||
108 | Q_OBJECT | - | ||||||||||||
109 | public: | - | ||||||||||||
110 | LineEdit(QWidget* parent = 0) | - | ||||||||||||
111 | : QLineEdit(parent) | - | ||||||||||||
112 | { | - | ||||||||||||
113 | setContextMenuPolicy(Qt::NoContextMenu); | - | ||||||||||||
114 | connect(this, SIGNAL(returnPressed()), SLOT(handleReturnPressed())); | - | ||||||||||||
115 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
116 | - | |||||||||||||
117 | protected: | - | ||||||||||||
118 | void focusInEvent(QFocusEvent *e) Q_DECL_OVERRIDE | - | ||||||||||||
119 | { | - | ||||||||||||
120 | origText = text(); | - | ||||||||||||
121 | QLineEdit::focusInEvent(e); | - | ||||||||||||
122 | } never executed: end of block | 0 | ||||||||||||
123 | - | |||||||||||||
124 | void focusOutEvent(QFocusEvent *e) Q_DECL_OVERRIDE | - | ||||||||||||
125 | { | - | ||||||||||||
126 | if (isModified() && !hasAcceptableInput())
| 0 | ||||||||||||
127 | setText(origText); never executed: setText(origText); | 0 | ||||||||||||
128 | QLineEdit::focusOutEvent(e); | - | ||||||||||||
129 | } never executed: end of block | 0 | ||||||||||||
130 | - | |||||||||||||
131 | private slots: | - | ||||||||||||
132 | void handleReturnPressed() | - | ||||||||||||
133 | { | - | ||||||||||||
134 | origText = text(); | - | ||||||||||||
135 | } never executed: end of block | 0 | ||||||||||||
136 | - | |||||||||||||
137 | private: | - | ||||||||||||
138 | QString origText; | - | ||||||||||||
139 | }; | - | ||||||||||||
140 | } // anonymous namespace | - | ||||||||||||
141 | - | |||||||||||||
142 | class QPrintPreviewDialogPrivate : public QDialogPrivate | - | ||||||||||||
143 | { | - | ||||||||||||
144 | Q_DECLARE_PUBLIC(QPrintPreviewDialog) | - | ||||||||||||
145 | public: | - | ||||||||||||
146 | QPrintPreviewDialogPrivate() | - | ||||||||||||
147 | : printDialog(0), ownPrinter(false), | - | ||||||||||||
148 | initialized(false) {} executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
149 | - | |||||||||||||
150 | // private slots | - | ||||||||||||
151 | void _q_fit(QAction *action); | - | ||||||||||||
152 | void _q_zoomIn(); | - | ||||||||||||
153 | void _q_zoomOut(); | - | ||||||||||||
154 | void _q_navigate(QAction *action); | - | ||||||||||||
155 | void _q_setMode(QAction *action); | - | ||||||||||||
156 | void _q_pageNumEdited(); | - | ||||||||||||
157 | void _q_print(); | - | ||||||||||||
158 | void _q_pageSetup(); | - | ||||||||||||
159 | void _q_previewChanged(); | - | ||||||||||||
160 | void _q_zoomFactorChanged(); | - | ||||||||||||
161 | - | |||||||||||||
162 | void init(QPrinter *printer = 0); | - | ||||||||||||
163 | void populateScene(); | - | ||||||||||||
164 | void layoutPages(); | - | ||||||||||||
165 | void setupActions(); | - | ||||||||||||
166 | void updateNavActions(); | - | ||||||||||||
167 | void setFitting(bool on); | - | ||||||||||||
168 | bool isFitting(); | - | ||||||||||||
169 | void updatePageNumLabel(); | - | ||||||||||||
170 | void updateZoomFactor(); | - | ||||||||||||
171 | - | |||||||||||||
172 | QPrintDialog *printDialog; | - | ||||||||||||
173 | QPrintPreviewWidget *preview; | - | ||||||||||||
174 | QPrinter *printer; | - | ||||||||||||
175 | bool ownPrinter; | - | ||||||||||||
176 | bool initialized; | - | ||||||||||||
177 | - | |||||||||||||
178 | // widgets: | - | ||||||||||||
179 | QLineEdit *pageNumEdit; | - | ||||||||||||
180 | QLabel *pageNumLabel; | - | ||||||||||||
181 | QComboBox *zoomFactor; | - | ||||||||||||
182 | - | |||||||||||||
183 | // actions: | - | ||||||||||||
184 | QActionGroup* navGroup; | - | ||||||||||||
185 | QAction *nextPageAction; | - | ||||||||||||
186 | QAction *prevPageAction; | - | ||||||||||||
187 | QAction *firstPageAction; | - | ||||||||||||
188 | QAction *lastPageAction; | - | ||||||||||||
189 | - | |||||||||||||
190 | QActionGroup* fitGroup; | - | ||||||||||||
191 | QAction *fitWidthAction; | - | ||||||||||||
192 | QAction *fitPageAction; | - | ||||||||||||
193 | - | |||||||||||||
194 | QActionGroup* zoomGroup; | - | ||||||||||||
195 | QAction *zoomInAction; | - | ||||||||||||
196 | QAction *zoomOutAction; | - | ||||||||||||
197 | - | |||||||||||||
198 | QActionGroup* orientationGroup; | - | ||||||||||||
199 | QAction *portraitAction; | - | ||||||||||||
200 | QAction *landscapeAction; | - | ||||||||||||
201 | - | |||||||||||||
202 | QActionGroup* modeGroup; | - | ||||||||||||
203 | QAction *singleModeAction; | - | ||||||||||||
204 | QAction *facingModeAction; | - | ||||||||||||
205 | QAction *overviewModeAction; | - | ||||||||||||
206 | - | |||||||||||||
207 | QActionGroup *printerGroup; | - | ||||||||||||
208 | QAction *printAction; | - | ||||||||||||
209 | QAction *pageSetupAction; | - | ||||||||||||
210 | - | |||||||||||||
211 | QPointer<QObject> receiverToDisconnectOnClose; | - | ||||||||||||
212 | QByteArray memberToDisconnectOnClose; | - | ||||||||||||
213 | }; | - | ||||||||||||
214 | - | |||||||||||||
215 | void QPrintPreviewDialogPrivate::init(QPrinter *_printer) | - | ||||||||||||
216 | { | - | ||||||||||||
217 | Q_Q(QPrintPreviewDialog); | - | ||||||||||||
218 | - | |||||||||||||
219 | initResources(); | - | ||||||||||||
220 | - | |||||||||||||
221 | if (_printer) {
| 0-1 | ||||||||||||
222 | preview = new QPrintPreviewWidget(_printer, q); | - | ||||||||||||
223 | printer = _printer; | - | ||||||||||||
224 | } else { executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
225 | ownPrinter = true; | - | ||||||||||||
226 | printer = new QPrinter; | - | ||||||||||||
227 | preview = new QPrintPreviewWidget(printer, q); | - | ||||||||||||
228 | } never executed: end of block | 0 | ||||||||||||
229 | QObject::connect(preview, SIGNAL(paintRequested(QPrinter*)), q, SIGNAL(paintRequested(QPrinter*))); | - | ||||||||||||
230 | QObject::connect(preview, SIGNAL(previewChanged()), q, SLOT(_q_previewChanged())); | - | ||||||||||||
231 | setupActions(); | - | ||||||||||||
232 | - | |||||||||||||
233 | pageNumEdit = new LineEdit; | - | ||||||||||||
234 | pageNumEdit->setAlignment(Qt::AlignRight); | - | ||||||||||||
235 | pageNumEdit->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); | - | ||||||||||||
236 | pageNumLabel = new QLabel; | - | ||||||||||||
237 | QObject::connect(pageNumEdit, SIGNAL(editingFinished()), q, SLOT(_q_pageNumEdited())); | - | ||||||||||||
238 | - | |||||||||||||
239 | zoomFactor = new QComboBox; | - | ||||||||||||
240 | zoomFactor->setEditable(true); | - | ||||||||||||
241 | zoomFactor->setMinimumContentsLength(7); | - | ||||||||||||
242 | zoomFactor->setInsertPolicy(QComboBox::NoInsert); | - | ||||||||||||
243 | LineEdit *zoomEditor = new LineEdit; | - | ||||||||||||
244 | zoomEditor->setValidator(new ZoomFactorValidator(1, 1000, 1, zoomEditor)); | - | ||||||||||||
245 | zoomFactor->setLineEdit(zoomEditor); | - | ||||||||||||
246 | static const short factorsX2[] = { 25, 50, 100, 200, 250, 300, 400, 800, 1600 }; | - | ||||||||||||
247 | for (int i = 0; i < int(sizeof(factorsX2) / sizeof(factorsX2[0])); ++i)
| 1-9 | ||||||||||||
248 | zoomFactor->addItem(QPrintPreviewDialog::tr("%1%").arg(factorsX2[i] / 2.0)); executed 9 times by 1 test: zoomFactor->addItem(QPrintPreviewDialog::tr("%1%").arg(factorsX2[i] / 2.0)); Executed by:
| 9 | ||||||||||||
249 | QObject::connect(zoomFactor->lineEdit(), SIGNAL(editingFinished()), | - | ||||||||||||
250 | q, SLOT(_q_zoomFactorChanged())); | - | ||||||||||||
251 | QObject::connect(zoomFactor, SIGNAL(currentIndexChanged(int)), | - | ||||||||||||
252 | q, SLOT(_q_zoomFactorChanged())); | - | ||||||||||||
253 | - | |||||||||||||
254 | QPrintPreviewMainWindow *mw = new QPrintPreviewMainWindow(q); | - | ||||||||||||
255 | QToolBar *toolbar = new QToolBar(mw); | - | ||||||||||||
256 | toolbar->addAction(fitWidthAction); | - | ||||||||||||
257 | toolbar->addAction(fitPageAction); | - | ||||||||||||
258 | toolbar->addSeparator(); | - | ||||||||||||
259 | toolbar->addWidget(zoomFactor); | - | ||||||||||||
260 | toolbar->addAction(zoomOutAction); | - | ||||||||||||
261 | toolbar->addAction(zoomInAction); | - | ||||||||||||
262 | toolbar->addSeparator(); | - | ||||||||||||
263 | toolbar->addAction(portraitAction); | - | ||||||||||||
264 | toolbar->addAction(landscapeAction); | - | ||||||||||||
265 | toolbar->addSeparator(); | - | ||||||||||||
266 | toolbar->addAction(firstPageAction); | - | ||||||||||||
267 | toolbar->addAction(prevPageAction); | - | ||||||||||||
268 | - | |||||||||||||
269 | // this is to ensure the label text and the editor text are | - | ||||||||||||
270 | // aligned in all styles - the extra QVBoxLayout is a workaround | - | ||||||||||||
271 | // for bug in QFormLayout | - | ||||||||||||
272 | QWidget *pageEdit = new QWidget(toolbar); | - | ||||||||||||
273 | QVBoxLayout *vboxLayout = new QVBoxLayout; | - | ||||||||||||
274 | vboxLayout->setContentsMargins(0, 0, 0, 0); | - | ||||||||||||
275 | #ifdef Q_OS_MAC | - | ||||||||||||
276 | // We query the widgets about their size and then we fix the size. | - | ||||||||||||
277 | // This should do the trick for the laying out part... | - | ||||||||||||
278 | QSize pageNumEditSize, pageNumLabelSize; | - | ||||||||||||
279 | pageNumEditSize = pageNumEdit->minimumSizeHint(); | - | ||||||||||||
280 | pageNumLabelSize = pageNumLabel->minimumSizeHint(); | - | ||||||||||||
281 | pageNumEdit->resize(pageNumEditSize); | - | ||||||||||||
282 | pageNumLabel->resize(pageNumLabelSize); | - | ||||||||||||
283 | #endif | - | ||||||||||||
284 | QFormLayout *formLayout = new QFormLayout; | - | ||||||||||||
285 | #ifdef Q_OS_MAC | - | ||||||||||||
286 | // We have to change the growth policy in Mac. | - | ||||||||||||
287 | formLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow); | - | ||||||||||||
288 | #endif | - | ||||||||||||
289 | formLayout->setWidget(0, QFormLayout::LabelRole, pageNumEdit); | - | ||||||||||||
290 | formLayout->setWidget(0, QFormLayout::FieldRole, pageNumLabel); | - | ||||||||||||
291 | vboxLayout->addLayout(formLayout); | - | ||||||||||||
292 | vboxLayout->setAlignment(Qt::AlignVCenter); | - | ||||||||||||
293 | pageEdit->setLayout(vboxLayout); | - | ||||||||||||
294 | toolbar->addWidget(pageEdit); | - | ||||||||||||
295 | - | |||||||||||||
296 | toolbar->addAction(nextPageAction); | - | ||||||||||||
297 | toolbar->addAction(lastPageAction); | - | ||||||||||||
298 | toolbar->addSeparator(); | - | ||||||||||||
299 | toolbar->addAction(singleModeAction); | - | ||||||||||||
300 | toolbar->addAction(facingModeAction); | - | ||||||||||||
301 | toolbar->addAction(overviewModeAction); | - | ||||||||||||
302 | toolbar->addSeparator(); | - | ||||||||||||
303 | toolbar->addAction(pageSetupAction); | - | ||||||||||||
304 | toolbar->addAction(printAction); | - | ||||||||||||
305 | - | |||||||||||||
306 | // Cannot use the actions' triggered signal here, since it doesn't autorepeat | - | ||||||||||||
307 | QToolButton *zoomInButton = static_cast<QToolButton *>(toolbar->widgetForAction(zoomInAction)); | - | ||||||||||||
308 | QToolButton *zoomOutButton = static_cast<QToolButton *>(toolbar->widgetForAction(zoomOutAction)); | - | ||||||||||||
309 | zoomInButton->setAutoRepeat(true); | - | ||||||||||||
310 | zoomInButton->setAutoRepeatInterval(200); | - | ||||||||||||
311 | zoomInButton->setAutoRepeatDelay(200); | - | ||||||||||||
312 | zoomOutButton->setAutoRepeat(true); | - | ||||||||||||
313 | zoomOutButton->setAutoRepeatInterval(200); | - | ||||||||||||
314 | zoomOutButton->setAutoRepeatDelay(200); | - | ||||||||||||
315 | QObject::connect(zoomInButton, SIGNAL(clicked()), q, SLOT(_q_zoomIn())); | - | ||||||||||||
316 | QObject::connect(zoomOutButton, SIGNAL(clicked()), q, SLOT(_q_zoomOut())); | - | ||||||||||||
317 | - | |||||||||||||
318 | mw->addToolBar(toolbar); | - | ||||||||||||
319 | mw->setCentralWidget(preview); | - | ||||||||||||
320 | // QMainWindows are always created as top levels, force it to be a | - | ||||||||||||
321 | // plain widget | - | ||||||||||||
322 | mw->setParent(q, Qt::Widget); | - | ||||||||||||
323 | - | |||||||||||||
324 | QVBoxLayout *topLayout = new QVBoxLayout; | - | ||||||||||||
325 | topLayout->addWidget(mw); | - | ||||||||||||
326 | topLayout->setMargin(0); | - | ||||||||||||
327 | q->setLayout(topLayout); | - | ||||||||||||
328 | - | |||||||||||||
329 | QString caption = QCoreApplication::translate("QPrintPreviewDialog", "Print Preview"); | - | ||||||||||||
330 | if (!printer->docName().isEmpty())
| 0-1 | ||||||||||||
331 | caption += QString::fromLatin1(": ") + printer->docName(); never executed: caption += QString::fromLatin1(": ") + printer->docName(); | 0 | ||||||||||||
332 | q->setWindowTitle(caption); | - | ||||||||||||
333 | - | |||||||||||||
334 | if (!printer->isValid()
| 0-1 | ||||||||||||
335 | #if defined(Q_OS_WIN) || defined(Q_OS_MAC) | - | ||||||||||||
336 | || printer->outputFormat() != QPrinter::NativeFormat | - | ||||||||||||
337 | #endif | - | ||||||||||||
338 | ) | - | ||||||||||||
339 | pageSetupAction->setEnabled(false); never executed: pageSetupAction->setEnabled(false); | 0 | ||||||||||||
340 | preview->setFocus(); | - | ||||||||||||
341 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
342 | - | |||||||||||||
343 | static inline void qt_setupActionIcon(QAction *action, QLatin1String name) | - | ||||||||||||
344 | { | - | ||||||||||||
345 | QLatin1String imagePrefix(":/qt-project.org/dialogs/qprintpreviewdialog/images/"); | - | ||||||||||||
346 | QIcon icon; | - | ||||||||||||
347 | icon.addFile(imagePrefix + name + QLatin1String("-24.png"), QSize(24, 24)); | - | ||||||||||||
348 | icon.addFile(imagePrefix + name + QLatin1String("-32.png"), QSize(32, 32)); | - | ||||||||||||
349 | action->setIcon(icon); | - | ||||||||||||
350 | } executed 15 times by 1 test: end of block Executed by:
| 15 | ||||||||||||
351 | - | |||||||||||||
352 | void QPrintPreviewDialogPrivate::setupActions() | - | ||||||||||||
353 | { | - | ||||||||||||
354 | Q_Q(QPrintPreviewDialog); | - | ||||||||||||
355 | - | |||||||||||||
356 | // Navigation | - | ||||||||||||
357 | navGroup = new QActionGroup(q); | - | ||||||||||||
358 | navGroup->setExclusive(false); | - | ||||||||||||
359 | nextPageAction = navGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Next page")); | - | ||||||||||||
360 | prevPageAction = navGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Previous page")); | - | ||||||||||||
361 | firstPageAction = navGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "First page")); | - | ||||||||||||
362 | lastPageAction = navGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Last page")); | - | ||||||||||||
363 | qt_setupActionIcon(nextPageAction, QLatin1String("go-next")); | - | ||||||||||||
364 | qt_setupActionIcon(prevPageAction, QLatin1String("go-previous")); | - | ||||||||||||
365 | qt_setupActionIcon(firstPageAction, QLatin1String("go-first")); | - | ||||||||||||
366 | qt_setupActionIcon(lastPageAction, QLatin1String("go-last")); | - | ||||||||||||
367 | QObject::connect(navGroup, SIGNAL(triggered(QAction*)), q, SLOT(_q_navigate(QAction*))); | - | ||||||||||||
368 | - | |||||||||||||
369 | - | |||||||||||||
370 | fitGroup = new QActionGroup(q); | - | ||||||||||||
371 | fitWidthAction = fitGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Fit width")); | - | ||||||||||||
372 | fitPageAction = fitGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Fit page")); | - | ||||||||||||
373 | fitWidthAction->setObjectName(QLatin1String("fitWidthAction")); | - | ||||||||||||
374 | fitPageAction->setObjectName(QLatin1String("fitPageAction")); | - | ||||||||||||
375 | fitWidthAction->setCheckable(true); | - | ||||||||||||
376 | fitPageAction->setCheckable(true); | - | ||||||||||||
377 | qt_setupActionIcon(fitWidthAction, QLatin1String("fit-width")); | - | ||||||||||||
378 | qt_setupActionIcon(fitPageAction, QLatin1String("fit-page")); | - | ||||||||||||
379 | QObject::connect(fitGroup, SIGNAL(triggered(QAction*)), q, SLOT(_q_fit(QAction*))); | - | ||||||||||||
380 | - | |||||||||||||
381 | // Zoom | - | ||||||||||||
382 | zoomGroup = new QActionGroup(q); | - | ||||||||||||
383 | zoomInAction = zoomGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Zoom in")); | - | ||||||||||||
384 | zoomOutAction = zoomGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Zoom out")); | - | ||||||||||||
385 | qt_setupActionIcon(zoomInAction, QLatin1String("zoom-in")); | - | ||||||||||||
386 | qt_setupActionIcon(zoomOutAction, QLatin1String("zoom-out")); | - | ||||||||||||
387 | - | |||||||||||||
388 | // Portrait/Landscape | - | ||||||||||||
389 | orientationGroup = new QActionGroup(q); | - | ||||||||||||
390 | portraitAction = orientationGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Portrait")); | - | ||||||||||||
391 | landscapeAction = orientationGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Landscape")); | - | ||||||||||||
392 | portraitAction->setCheckable(true); | - | ||||||||||||
393 | landscapeAction->setCheckable(true); | - | ||||||||||||
394 | qt_setupActionIcon(portraitAction, QLatin1String("layout-portrait")); | - | ||||||||||||
395 | qt_setupActionIcon(landscapeAction, QLatin1String("layout-landscape")); | - | ||||||||||||
396 | QObject::connect(portraitAction, SIGNAL(triggered(bool)), preview, SLOT(setPortraitOrientation())); | - | ||||||||||||
397 | QObject::connect(landscapeAction, SIGNAL(triggered(bool)), preview, SLOT(setLandscapeOrientation())); | - | ||||||||||||
398 | - | |||||||||||||
399 | // Display mode | - | ||||||||||||
400 | modeGroup = new QActionGroup(q); | - | ||||||||||||
401 | singleModeAction = modeGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Show single page")); | - | ||||||||||||
402 | facingModeAction = modeGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Show facing pages")); | - | ||||||||||||
403 | overviewModeAction = modeGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Show overview of all pages")); | - | ||||||||||||
404 | qt_setupActionIcon(singleModeAction, QLatin1String("view-page-one")); | - | ||||||||||||
405 | qt_setupActionIcon(facingModeAction, QLatin1String("view-page-sided")); | - | ||||||||||||
406 | qt_setupActionIcon(overviewModeAction, QLatin1String("view-page-multi")); | - | ||||||||||||
407 | singleModeAction->setObjectName(QLatin1String("singleModeAction")); | - | ||||||||||||
408 | facingModeAction->setObjectName(QLatin1String("facingModeAction")); | - | ||||||||||||
409 | overviewModeAction->setObjectName(QLatin1String("overviewModeAction")); | - | ||||||||||||
410 | - | |||||||||||||
411 | singleModeAction->setCheckable(true); | - | ||||||||||||
412 | facingModeAction->setCheckable(true); | - | ||||||||||||
413 | overviewModeAction->setCheckable(true); | - | ||||||||||||
414 | QObject::connect(modeGroup, SIGNAL(triggered(QAction*)), q, SLOT(_q_setMode(QAction*))); | - | ||||||||||||
415 | - | |||||||||||||
416 | - | |||||||||||||
417 | printerGroup = new QActionGroup(q); | - | ||||||||||||
418 | printAction = printerGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Print")); | - | ||||||||||||
419 | pageSetupAction = printerGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Page setup")); | - | ||||||||||||
420 | qt_setupActionIcon(printAction, QLatin1String("print")); | - | ||||||||||||
421 | qt_setupActionIcon(pageSetupAction, QLatin1String("page-setup")); | - | ||||||||||||
422 | QObject::connect(printAction, SIGNAL(triggered(bool)), q, SLOT(_q_print())); | - | ||||||||||||
423 | QObject::connect(pageSetupAction, SIGNAL(triggered(bool)), q, SLOT(_q_pageSetup())); | - | ||||||||||||
424 | - | |||||||||||||
425 | // Initial state: | - | ||||||||||||
426 | fitPageAction->setChecked(true); | - | ||||||||||||
427 | singleModeAction->setChecked(true); | - | ||||||||||||
428 | if (preview->orientation() == QPrinter::Portrait)
| 0-1 | ||||||||||||
429 | portraitAction->setChecked(true); executed 1 time by 1 test: portraitAction->setChecked(true); Executed by:
| 1 | ||||||||||||
430 | else | - | ||||||||||||
431 | landscapeAction->setChecked(true); never executed: landscapeAction->setChecked(true); | 0 | ||||||||||||
432 | } | - | ||||||||||||
433 | - | |||||||||||||
434 | - | |||||||||||||
435 | bool QPrintPreviewDialogPrivate::isFitting() | - | ||||||||||||
436 | { | - | ||||||||||||
437 | return (fitGroup->isExclusive() never executed: return (fitGroup->isExclusive() && (fitWidthAction->isChecked() || fitPageAction->isChecked()));
| 0 | ||||||||||||
438 | && (fitWidthAction->isChecked() || fitPageAction->isChecked())); never executed: return (fitGroup->isExclusive() && (fitWidthAction->isChecked() || fitPageAction->isChecked()));
| 0 | ||||||||||||
439 | } | - | ||||||||||||
440 | - | |||||||||||||
441 | - | |||||||||||||
442 | void QPrintPreviewDialogPrivate::setFitting(bool on) | - | ||||||||||||
443 | { | - | ||||||||||||
444 | if (isFitting() == on)
| 0 | ||||||||||||
445 | return; never executed: return; | 0 | ||||||||||||
446 | fitGroup->setExclusive(on); | - | ||||||||||||
447 | if (on) {
| 0 | ||||||||||||
448 | QAction* action = fitWidthAction->isChecked() ? fitWidthAction : fitPageAction;
| 0 | ||||||||||||
449 | action->setChecked(true); | - | ||||||||||||
450 | if (fitGroup->checkedAction() != action) {
| 0 | ||||||||||||
451 | // work around exclusitivity problem | - | ||||||||||||
452 | fitGroup->removeAction(action); | - | ||||||||||||
453 | fitGroup->addAction(action); | - | ||||||||||||
454 | } never executed: end of block | 0 | ||||||||||||
455 | } else { never executed: end of block | 0 | ||||||||||||
456 | fitWidthAction->setChecked(false); | - | ||||||||||||
457 | fitPageAction->setChecked(false); | - | ||||||||||||
458 | } never executed: end of block | 0 | ||||||||||||
459 | } | - | ||||||||||||
460 | - | |||||||||||||
461 | void QPrintPreviewDialogPrivate::updateNavActions() | - | ||||||||||||
462 | { | - | ||||||||||||
463 | int curPage = preview->currentPage(); | - | ||||||||||||
464 | int numPages = preview->pageCount(); | - | ||||||||||||
465 | nextPageAction->setEnabled(curPage < numPages); | - | ||||||||||||
466 | prevPageAction->setEnabled(curPage > 1); | - | ||||||||||||
467 | firstPageAction->setEnabled(curPage > 1); | - | ||||||||||||
468 | lastPageAction->setEnabled(curPage < numPages); | - | ||||||||||||
469 | pageNumEdit->setText(QString::number(curPage)); | - | ||||||||||||
470 | } executed 13 times by 1 test: end of block Executed by:
| 13 | ||||||||||||
471 | - | |||||||||||||
472 | void QPrintPreviewDialogPrivate::updatePageNumLabel() | - | ||||||||||||
473 | { | - | ||||||||||||
474 | Q_Q(QPrintPreviewDialog); | - | ||||||||||||
475 | - | |||||||||||||
476 | int numPages = preview->pageCount(); | - | ||||||||||||
477 | int maxChars = QString::number(numPages).length(); | - | ||||||||||||
478 | pageNumLabel->setText(QString::fromLatin1("/ %1").arg(numPages)); | - | ||||||||||||
479 | int cyphersWidth = q->fontMetrics().width(QString().fill(QLatin1Char('8'), maxChars)); | - | ||||||||||||
480 | int maxWidth = pageNumEdit->minimumSizeHint().width() + cyphersWidth; | - | ||||||||||||
481 | pageNumEdit->setMinimumWidth(maxWidth); | - | ||||||||||||
482 | pageNumEdit->setMaximumWidth(maxWidth); | - | ||||||||||||
483 | pageNumEdit->setValidator(new QIntValidator(1, numPages, pageNumEdit)); | - | ||||||||||||
484 | // any old one will be deleted later along with its parent pageNumEdit | - | ||||||||||||
485 | } executed 13 times by 1 test: end of block Executed by:
| 13 | ||||||||||||
486 | - | |||||||||||||
487 | void QPrintPreviewDialogPrivate::updateZoomFactor() | - | ||||||||||||
488 | { | - | ||||||||||||
489 | zoomFactor->lineEdit()->setText(QString().sprintf("%.1f%%", preview->zoomFactor()*100)); | - | ||||||||||||
490 | } executed 13 times by 1 test: end of block Executed by:
| 13 | ||||||||||||
491 | - | |||||||||||||
492 | void QPrintPreviewDialogPrivate::_q_fit(QAction* action) | - | ||||||||||||
493 | { | - | ||||||||||||
494 | setFitting(true); | - | ||||||||||||
495 | if (action == fitPageAction)
| 0 | ||||||||||||
496 | preview->fitInView(); never executed: preview->fitInView(); | 0 | ||||||||||||
497 | else | - | ||||||||||||
498 | preview->fitToWidth(); never executed: preview->fitToWidth(); | 0 | ||||||||||||
499 | } | - | ||||||||||||
500 | - | |||||||||||||
501 | void QPrintPreviewDialogPrivate::_q_zoomIn() | - | ||||||||||||
502 | { | - | ||||||||||||
503 | setFitting(false); | - | ||||||||||||
504 | preview->zoomIn(); | - | ||||||||||||
505 | updateZoomFactor(); | - | ||||||||||||
506 | } never executed: end of block | 0 | ||||||||||||
507 | - | |||||||||||||
508 | void QPrintPreviewDialogPrivate::_q_zoomOut() | - | ||||||||||||
509 | { | - | ||||||||||||
510 | setFitting(false); | - | ||||||||||||
511 | preview->zoomOut(); | - | ||||||||||||
512 | updateZoomFactor(); | - | ||||||||||||
513 | } never executed: end of block | 0 | ||||||||||||
514 | - | |||||||||||||
515 | void QPrintPreviewDialogPrivate::_q_pageNumEdited() | - | ||||||||||||
516 | { | - | ||||||||||||
517 | bool ok = false; | - | ||||||||||||
518 | int res = pageNumEdit->text().toInt(&ok); | - | ||||||||||||
519 | if (ok)
| 0 | ||||||||||||
520 | preview->setCurrentPage(res); never executed: preview->setCurrentPage(res); | 0 | ||||||||||||
521 | } never executed: end of block | 0 | ||||||||||||
522 | - | |||||||||||||
523 | void QPrintPreviewDialogPrivate::_q_navigate(QAction* action) | - | ||||||||||||
524 | { | - | ||||||||||||
525 | int curPage = preview->currentPage(); | - | ||||||||||||
526 | if (action == prevPageAction)
| 0 | ||||||||||||
527 | preview->setCurrentPage(curPage - 1); never executed: preview->setCurrentPage(curPage - 1); | 0 | ||||||||||||
528 | else if (action == nextPageAction)
| 0 | ||||||||||||
529 | preview->setCurrentPage(curPage + 1); never executed: preview->setCurrentPage(curPage + 1); | 0 | ||||||||||||
530 | else if (action == firstPageAction)
| 0 | ||||||||||||
531 | preview->setCurrentPage(1); never executed: preview->setCurrentPage(1); | 0 | ||||||||||||
532 | else if (action == lastPageAction)
| 0 | ||||||||||||
533 | preview->setCurrentPage(preview->pageCount()); never executed: preview->setCurrentPage(preview->pageCount()); | 0 | ||||||||||||
534 | updateNavActions(); | - | ||||||||||||
535 | } never executed: end of block | 0 | ||||||||||||
536 | - | |||||||||||||
537 | void QPrintPreviewDialogPrivate::_q_setMode(QAction* action) | - | ||||||||||||
538 | { | - | ||||||||||||
539 | if (action == overviewModeAction) {
| 0 | ||||||||||||
540 | preview->setViewMode(QPrintPreviewWidget::AllPagesView); | - | ||||||||||||
541 | setFitting(false); | - | ||||||||||||
542 | fitGroup->setEnabled(false); | - | ||||||||||||
543 | navGroup->setEnabled(false); | - | ||||||||||||
544 | pageNumEdit->setEnabled(false); | - | ||||||||||||
545 | pageNumLabel->setEnabled(false); | - | ||||||||||||
546 | } else if (action == facingModeAction) { never executed: end of block
| 0 | ||||||||||||
547 | preview->setViewMode(QPrintPreviewWidget::FacingPagesView); | - | ||||||||||||
548 | } else { never executed: end of block | 0 | ||||||||||||
549 | preview->setViewMode(QPrintPreviewWidget::SinglePageView); | - | ||||||||||||
550 | } never executed: end of block | 0 | ||||||||||||
551 | if (action == facingModeAction || action == singleModeAction) {
| 0 | ||||||||||||
552 | fitGroup->setEnabled(true); | - | ||||||||||||
553 | navGroup->setEnabled(true); | - | ||||||||||||
554 | pageNumEdit->setEnabled(true); | - | ||||||||||||
555 | pageNumLabel->setEnabled(true); | - | ||||||||||||
556 | setFitting(true); | - | ||||||||||||
557 | } never executed: end of block | 0 | ||||||||||||
558 | } never executed: end of block | 0 | ||||||||||||
559 | - | |||||||||||||
560 | void QPrintPreviewDialogPrivate::_q_print() | - | ||||||||||||
561 | { | - | ||||||||||||
562 | Q_Q(QPrintPreviewDialog); | - | ||||||||||||
563 | - | |||||||||||||
564 | #if defined(Q_OS_WIN) || defined(Q_OS_MAC) | - | ||||||||||||
565 | if (printer->outputFormat() != QPrinter::NativeFormat) { | - | ||||||||||||
566 | QString title = QCoreApplication::translate("QPrintPreviewDialog", "Export to PDF"); | - | ||||||||||||
567 | QString suffix = QLatin1String(".pdf"); | - | ||||||||||||
568 | QString fileName = QFileDialog::getSaveFileName(q, title, printer->outputFileName(), | - | ||||||||||||
569 | QLatin1Char('*') + suffix); | - | ||||||||||||
570 | if (!fileName.isEmpty()) { | - | ||||||||||||
571 | if (QFileInfo(fileName).suffix().isEmpty()) | - | ||||||||||||
572 | fileName.append(suffix); | - | ||||||||||||
573 | printer->setOutputFileName(fileName); | - | ||||||||||||
574 | } | - | ||||||||||||
575 | if (!printer->outputFileName().isEmpty()) | - | ||||||||||||
576 | preview->print(); | - | ||||||||||||
577 | q->accept(); | - | ||||||||||||
578 | return; | - | ||||||||||||
579 | } | - | ||||||||||||
580 | #endif | - | ||||||||||||
581 | - | |||||||||||||
582 | if (!printDialog)
| 0 | ||||||||||||
583 | printDialog = new QPrintDialog(printer, q); never executed: printDialog = new QPrintDialog(printer, q); | 0 | ||||||||||||
584 | if (printDialog->exec() == QDialog::Accepted) {
| 0 | ||||||||||||
585 | preview->print(); | - | ||||||||||||
586 | q->accept(); | - | ||||||||||||
587 | } never executed: end of block | 0 | ||||||||||||
588 | } never executed: end of block | 0 | ||||||||||||
589 | - | |||||||||||||
590 | void QPrintPreviewDialogPrivate::_q_pageSetup() | - | ||||||||||||
591 | { | - | ||||||||||||
592 | Q_Q(QPrintPreviewDialog); | - | ||||||||||||
593 | - | |||||||||||||
594 | QPageSetupDialog pageSetup(printer, q); | - | ||||||||||||
595 | if (pageSetup.exec() == QDialog::Accepted) {
| 0 | ||||||||||||
596 | // update possible orientation changes | - | ||||||||||||
597 | if (preview->orientation() == QPrinter::Portrait) {
| 0 | ||||||||||||
598 | portraitAction->setChecked(true); | - | ||||||||||||
599 | preview->setPortraitOrientation(); | - | ||||||||||||
600 | }else { never executed: end of block | 0 | ||||||||||||
601 | landscapeAction->setChecked(true); | - | ||||||||||||
602 | preview->setLandscapeOrientation(); | - | ||||||||||||
603 | } never executed: end of block | 0 | ||||||||||||
604 | } | - | ||||||||||||
605 | } never executed: end of block | 0 | ||||||||||||
606 | - | |||||||||||||
607 | void QPrintPreviewDialogPrivate::_q_previewChanged() | - | ||||||||||||
608 | { | - | ||||||||||||
609 | updateNavActions(); | - | ||||||||||||
610 | updatePageNumLabel(); | - | ||||||||||||
611 | updateZoomFactor(); | - | ||||||||||||
612 | } executed 13 times by 1 test: end of block Executed by:
| 13 | ||||||||||||
613 | - | |||||||||||||
614 | void QPrintPreviewDialogPrivate::_q_zoomFactorChanged() | - | ||||||||||||
615 | { | - | ||||||||||||
616 | QString text = zoomFactor->lineEdit()->text(); | - | ||||||||||||
617 | bool ok; | - | ||||||||||||
618 | qreal factor = text.remove(QLatin1Char('%')).toFloat(&ok); | - | ||||||||||||
619 | factor = qMax(qreal(1.0), qMin(qreal(1000.0), factor)); | - | ||||||||||||
620 | if (ok) {
| 0 | ||||||||||||
621 | preview->setZoomFactor(factor/100.0); | - | ||||||||||||
622 | zoomFactor->setEditText(QString::fromLatin1("%1%").arg(factor)); | - | ||||||||||||
623 | setFitting(false); | - | ||||||||||||
624 | } never executed: end of block | 0 | ||||||||||||
625 | } never executed: end of block | 0 | ||||||||||||
626 | - | |||||||||||||
627 | /////////////////////////////////////////////////////////////////////////// | - | ||||||||||||
628 | - | |||||||||||||
629 | /*! | - | ||||||||||||
630 | \class QPrintPreviewDialog | - | ||||||||||||
631 | \since 4.4 | - | ||||||||||||
632 | - | |||||||||||||
633 | \brief The QPrintPreviewDialog class provides a dialog for | - | ||||||||||||
634 | previewing and configuring page layouts for printer output. | - | ||||||||||||
635 | - | |||||||||||||
636 | \ingroup standard-dialogs | - | ||||||||||||
637 | \ingroup printing | - | ||||||||||||
638 | \inmodule QtPrintSupport | - | ||||||||||||
639 | - | |||||||||||||
640 | Using QPrintPreviewDialog in your existing application is | - | ||||||||||||
641 | straightforward: | - | ||||||||||||
642 | - | |||||||||||||
643 | \list 1 | - | ||||||||||||
644 | \li Create the QPrintPreviewDialog. | - | ||||||||||||
645 | - | |||||||||||||
646 | You can construct a QPrintPreviewDialog with an existing QPrinter | - | ||||||||||||
647 | object, or you can have QPrintPreviewDialog create one for you, | - | ||||||||||||
648 | which will be the system default printer. | - | ||||||||||||
649 | - | |||||||||||||
650 | \li Connect the paintRequested() signal to a slot. | - | ||||||||||||
651 | - | |||||||||||||
652 | When the dialog needs to generate a set of preview pages, the | - | ||||||||||||
653 | paintRequested() signal will be emitted. You can use the exact | - | ||||||||||||
654 | same code for the actual printing as for having the preview | - | ||||||||||||
655 | generated, including calling QPrinter::newPage() to start a new | - | ||||||||||||
656 | page in the preview. Connect a slot to the paintRequested() | - | ||||||||||||
657 | signal, where you draw onto the QPrinter object that is passed | - | ||||||||||||
658 | into the slot. | - | ||||||||||||
659 | - | |||||||||||||
660 | \li Call exec(). | - | ||||||||||||
661 | - | |||||||||||||
662 | Call QPrintPreviewDialog::exec() to show the preview dialog. | - | ||||||||||||
663 | \endlist | - | ||||||||||||
664 | - | |||||||||||||
665 | \sa QPrinter, QPrintDialog, QPageSetupDialog, QPrintPreviewWidget | - | ||||||||||||
666 | */ | - | ||||||||||||
667 | - | |||||||||||||
668 | /*! | - | ||||||||||||
669 | Constructs a QPrintPreviewDialog based on \a printer and with \a | - | ||||||||||||
670 | parent as the parent widget. The widget flags \a flags are passed on | - | ||||||||||||
671 | to the QWidget constructor. | - | ||||||||||||
672 | - | |||||||||||||
673 | \sa QWidget::setWindowFlags() | - | ||||||||||||
674 | */ | - | ||||||||||||
675 | QPrintPreviewDialog::QPrintPreviewDialog(QPrinter* printer, QWidget *parent, Qt::WindowFlags flags) | - | ||||||||||||
676 | : QDialog(*new QPrintPreviewDialogPrivate, parent, flags) | - | ||||||||||||
677 | { | - | ||||||||||||
678 | Q_D(QPrintPreviewDialog); | - | ||||||||||||
679 | d->init(printer); | - | ||||||||||||
680 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
681 | - | |||||||||||||
682 | /*! | - | ||||||||||||
683 | \overload | - | ||||||||||||
684 | \fn QPrintPreviewDialog::QPrintPreviewDialog(QWidget *parent, Qt::WindowFlags flags) | - | ||||||||||||
685 | - | |||||||||||||
686 | This will create an internal QPrinter object, which will use the | - | ||||||||||||
687 | system default printer. | - | ||||||||||||
688 | */ | - | ||||||||||||
689 | QPrintPreviewDialog::QPrintPreviewDialog(QWidget *parent, Qt::WindowFlags f) | - | ||||||||||||
690 | : QDialog(*new QPrintPreviewDialogPrivate, parent, f) | - | ||||||||||||
691 | { | - | ||||||||||||
692 | Q_D(QPrintPreviewDialog); | - | ||||||||||||
693 | d->init(); | - | ||||||||||||
694 | } never executed: end of block | 0 | ||||||||||||
695 | - | |||||||||||||
696 | /*! | - | ||||||||||||
697 | Destroys the QPrintPreviewDialog. | - | ||||||||||||
698 | */ | - | ||||||||||||
699 | QPrintPreviewDialog::~QPrintPreviewDialog() | - | ||||||||||||
700 | { | - | ||||||||||||
701 | Q_D(QPrintPreviewDialog); | - | ||||||||||||
702 | if (d->ownPrinter)
| 0-1 | ||||||||||||
703 | delete d->printer; never executed: delete d->printer; | 0 | ||||||||||||
704 | delete d->printDialog; | - | ||||||||||||
705 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
706 | - | |||||||||||||
707 | /*! | - | ||||||||||||
708 | \reimp | - | ||||||||||||
709 | */ | - | ||||||||||||
710 | void QPrintPreviewDialog::setVisible(bool visible) | - | ||||||||||||
711 | { | - | ||||||||||||
712 | Q_D(QPrintPreviewDialog); | - | ||||||||||||
713 | // this will make the dialog get a decent default size | - | ||||||||||||
714 | if (visible && !d->initialized) {
| 0-1 | ||||||||||||
715 | d->preview->updatePreview(); | - | ||||||||||||
716 | d->initialized = true; | - | ||||||||||||
717 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
718 | QDialog::setVisible(visible); | - | ||||||||||||
719 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
720 | - | |||||||||||||
721 | /*! | - | ||||||||||||
722 | \reimp | - | ||||||||||||
723 | */ | - | ||||||||||||
724 | void QPrintPreviewDialog::done(int result) | - | ||||||||||||
725 | { | - | ||||||||||||
726 | Q_D(QPrintPreviewDialog); | - | ||||||||||||
727 | QDialog::done(result); | - | ||||||||||||
728 | if (d->receiverToDisconnectOnClose) {
| 0 | ||||||||||||
729 | disconnect(this, SIGNAL(finished(int)), | - | ||||||||||||
730 | d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose); | - | ||||||||||||
731 | d->receiverToDisconnectOnClose = 0; | - | ||||||||||||
732 | } never executed: end of block | 0 | ||||||||||||
733 | d->memberToDisconnectOnClose.clear(); | - | ||||||||||||
734 | } never executed: end of block | 0 | ||||||||||||
735 | - | |||||||||||||
736 | /*! | - | ||||||||||||
737 | \overload | - | ||||||||||||
738 | \since 4.5 | - | ||||||||||||
739 | - | |||||||||||||
740 | Opens the dialog and connects its finished(int) signal to the slot specified | - | ||||||||||||
741 | by \a receiver and \a member. | - | ||||||||||||
742 | - | |||||||||||||
743 | The signal will be disconnected from the slot when the dialog is closed. | - | ||||||||||||
744 | */ | - | ||||||||||||
745 | void QPrintPreviewDialog::open(QObject *receiver, const char *member) | - | ||||||||||||
746 | { | - | ||||||||||||
747 | Q_D(QPrintPreviewDialog); | - | ||||||||||||
748 | // the int parameter isn't very useful here; we could just as well connect | - | ||||||||||||
749 | // to reject(), but this feels less robust somehow | - | ||||||||||||
750 | connect(this, SIGNAL(finished(int)), receiver, member); | - | ||||||||||||
751 | d->receiverToDisconnectOnClose = receiver; | - | ||||||||||||
752 | d->memberToDisconnectOnClose = member; | - | ||||||||||||
753 | QDialog::open(); | - | ||||||||||||
754 | } never executed: end of block | 0 | ||||||||||||
755 | - | |||||||||||||
756 | /*! | - | ||||||||||||
757 | Returns a pointer to the QPrinter object this dialog is currently | - | ||||||||||||
758 | operating on. | - | ||||||||||||
759 | */ | - | ||||||||||||
760 | QPrinter *QPrintPreviewDialog::printer() | - | ||||||||||||
761 | { | - | ||||||||||||
762 | Q_D(QPrintPreviewDialog); | - | ||||||||||||
763 | return d->printer; never executed: return d->printer; | 0 | ||||||||||||
764 | } | - | ||||||||||||
765 | - | |||||||||||||
766 | /*! | - | ||||||||||||
767 | \fn void QPrintPreviewDialog::paintRequested(QPrinter *printer) | - | ||||||||||||
768 | - | |||||||||||||
769 | This signal is emitted when the QPrintPreviewDialog needs to generate | - | ||||||||||||
770 | a set of preview pages. | - | ||||||||||||
771 | - | |||||||||||||
772 | The \a printer instance supplied is the paint device onto which you should | - | ||||||||||||
773 | paint the contents of each page, using the QPrinter instance in the same way | - | ||||||||||||
774 | as you would when printing directly. | - | ||||||||||||
775 | */ | - | ||||||||||||
776 | - | |||||||||||||
777 | - | |||||||||||||
778 | QT_END_NAMESPACE | - | ||||||||||||
779 | - | |||||||||||||
780 | #include "moc_qprintpreviewdialog.cpp" | - | ||||||||||||
781 | #include "qprintpreviewdialog.moc" | - | ||||||||||||
782 | - | |||||||||||||
783 | #endif // QT_NO_PRINTPREVIEWDIALOG | - | ||||||||||||
784 | - | |||||||||||||
785 | - | |||||||||||||
Source code | Switch to Preprocessed file |