dialogs/qprintpreviewdialog.cpp

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

Generated by Squish Coco Non-Commercial