Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/printsupport/dialogs/qprintpreviewdialog.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | - | |||||||
2 | - | |||||||
3 | - | |||||||
4 | - | |||||||
5 | static void initResources() | - | ||||||
6 | { | - | ||||||
7 | static bool resourcesInitialized = false; | - | ||||||
8 | if (!resourcesInitialized) { | - | ||||||
9 | do { extern int qInitResources_qprintdialog (); qInitResources_qprintdialog (); } while (0); | - | ||||||
10 | resourcesInitialized = true; | - | ||||||
11 | } | - | ||||||
12 | } | - | ||||||
13 | - | |||||||
14 | - | |||||||
15 | - | |||||||
16 | namespace { | - | ||||||
17 | class QPrintPreviewMainWindow : public QMainWindow | - | ||||||
18 | { | - | ||||||
19 | public: | - | ||||||
20 | QPrintPreviewMainWindow(QWidget *parent) : QMainWindow(parent) {} | - | ||||||
21 | QMenu *createPopupMenu() override { return 0; } | - | ||||||
22 | }; | - | ||||||
23 | - | |||||||
24 | class ZoomFactorValidator : public QDoubleValidator | - | ||||||
25 | { | - | ||||||
26 | public: | - | ||||||
27 | ZoomFactorValidator(QObject* parent) | - | ||||||
28 | : QDoubleValidator(parent) {} | - | ||||||
29 | ZoomFactorValidator(qreal bottom, qreal top, int decimals, QObject *parent) | - | ||||||
30 | : QDoubleValidator(bottom, top, decimals, parent) {} | - | ||||||
31 | - | |||||||
32 | State validate(QString &input, int &pos) const override | - | ||||||
33 | { | - | ||||||
34 | bool replacePercent = false; | - | ||||||
35 | if (input.endsWith(QLatin1Char('%'))) { | - | ||||||
36 | input = input.left(input.length() - 1); | - | ||||||
37 | replacePercent = true; | - | ||||||
38 | } | - | ||||||
39 | State state = QDoubleValidator::validate(input, pos); | - | ||||||
40 | if (replacePercent) | - | ||||||
41 | input += QLatin1Char('%'); | - | ||||||
42 | const int num_size = 4; | - | ||||||
43 | if (state == Intermediate) { | - | ||||||
44 | int i = input.indexOf(QLocale::system().decimalPoint()); | - | ||||||
45 | if ((i == -1 && input.size() > num_size) | - | ||||||
46 | || (i != -1 && i > num_size)) | - | ||||||
47 | return Invalid; | - | ||||||
48 | } | - | ||||||
49 | return state; | - | ||||||
50 | } | - | ||||||
51 | }; | - | ||||||
52 | - | |||||||
53 | class LineEdit : public QLineEdit | - | ||||||
54 | { | - | ||||||
55 | public: template <typename ThisObject> inline void qt_check_for_QOBJECT_macro(const ThisObject &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; } | - | ||||||
56 | #pragma GCC diagnostic push | - | ||||||
57 | static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); | - | ||||||
58 | #pragma GCC diagnostic pop | - | ||||||
59 | struct QPrivateSignal {}; | - | ||||||
60 | public: | - | ||||||
61 | LineEdit(QWidget* parent = 0) | - | ||||||
62 | : QLineEdit(parent) | - | ||||||
63 | { | - | ||||||
64 | setContextMenuPolicy(Qt::NoContextMenu); | - | ||||||
65 | connect(this, qFlagLocation("2""returnPressed()" "\0" __FILE__ ":" "114""120"), qFlagLocation("1""handleReturnPressed()" "\0" __FILE__ ":" "114""120")); | - | ||||||
66 | } | - | ||||||
67 | - | |||||||
68 | protected: | - | ||||||
69 | void focusInEvent(QFocusEvent *e) override | - | ||||||
70 | { | - | ||||||
71 | origText = text(); | - | ||||||
72 | QLineEdit::focusInEvent(e); | - | ||||||
73 | } | - | ||||||
74 | - | |||||||
75 | void focusOutEvent(QFocusEvent *e) override | - | ||||||
76 | { | - | ||||||
77 | if (isModified() && !hasAcceptableInput()) | - | ||||||
78 | setText(origText); | - | ||||||
79 | QLineEdit::focusOutEvent(e); | - | ||||||
80 | } | - | ||||||
81 | - | |||||||
82 | private : | - | ||||||
83 | void handleReturnPressed() | - | ||||||
84 | { | - | ||||||
85 | origText = text(); | - | ||||||
86 | } | - | ||||||
87 | - | |||||||
88 | private: | - | ||||||
89 | QString origText; | - | ||||||
90 | }; | - | ||||||
91 | } | - | ||||||
92 | - | |||||||
93 | class QPrintPreviewDialogPrivate : public QDialogPrivate | - | ||||||
94 | { | - | ||||||
95 | inline QPrintPreviewDialog* q_func() { return static_cast<QPrintPreviewDialog *>(q_ptr); } inline const QPrintPreviewDialog* q_func() const { return static_cast<const QPrintPreviewDialog *>(q_ptr); } friend class QPrintPreviewDialog; | - | ||||||
96 | public: | - | ||||||
97 | QPrintPreviewDialogPrivate() | - | ||||||
98 | : printDialog(0), ownPrinter(false), | - | ||||||
99 | initialized(false) {} | - | ||||||
100 | - | |||||||
101 | - | |||||||
102 | void _q_fit(QAction *action); | - | ||||||
103 | void _q_zoomIn(); | - | ||||||
104 | void _q_zoomOut(); | - | ||||||
105 | void _q_navigate(QAction *action); | - | ||||||
106 | void _q_setMode(QAction *action); | - | ||||||
107 | void _q_pageNumEdited(); | - | ||||||
108 | void _q_print(); | - | ||||||
109 | void _q_pageSetup(); | - | ||||||
110 | void _q_previewChanged(); | - | ||||||
111 | void _q_zoomFactorChanged(); | - | ||||||
112 | - | |||||||
113 | void init(QPrinter *printer = 0); | - | ||||||
114 | void populateScene(); | - | ||||||
115 | void layoutPages(); | - | ||||||
116 | void setupActions(); | - | ||||||
117 | void updateNavActions(); | - | ||||||
118 | void setFitting(bool on); | - | ||||||
119 | bool isFitting(); | - | ||||||
120 | void updatePageNumLabel(); | - | ||||||
121 | void updateZoomFactor(); | - | ||||||
122 | - | |||||||
123 | QPrintDialog *printDialog; | - | ||||||
124 | QPrintPreviewWidget *preview; | - | ||||||
125 | QPrinter *printer; | - | ||||||
126 | bool ownPrinter; | - | ||||||
127 | bool initialized; | - | ||||||
128 | - | |||||||
129 | - | |||||||
130 | QLineEdit *pageNumEdit; | - | ||||||
131 | QLabel *pageNumLabel; | - | ||||||
132 | QComboBox *zoomFactor; | - | ||||||
133 | - | |||||||
134 | - | |||||||
135 | QActionGroup* navGroup; | - | ||||||
136 | QAction *nextPageAction; | - | ||||||
137 | QAction *prevPageAction; | - | ||||||
138 | QAction *firstPageAction; | - | ||||||
139 | QAction *lastPageAction; | - | ||||||
140 | - | |||||||
141 | QActionGroup* fitGroup; | - | ||||||
142 | QAction *fitWidthAction; | - | ||||||
143 | QAction *fitPageAction; | - | ||||||
144 | - | |||||||
145 | QActionGroup* zoomGroup; | - | ||||||
146 | QAction *zoomInAction; | - | ||||||
147 | QAction *zoomOutAction; | - | ||||||
148 | - | |||||||
149 | QActionGroup* orientationGroup; | - | ||||||
150 | QAction *portraitAction; | - | ||||||
151 | QAction *landscapeAction; | - | ||||||
152 | - | |||||||
153 | QActionGroup* modeGroup; | - | ||||||
154 | QAction *singleModeAction; | - | ||||||
155 | QAction *facingModeAction; | - | ||||||
156 | QAction *overviewModeAction; | - | ||||||
157 | - | |||||||
158 | QActionGroup *printerGroup; | - | ||||||
159 | QAction *printAction; | - | ||||||
160 | QAction *pageSetupAction; | - | ||||||
161 | - | |||||||
162 | QPointer<QObject> receiverToDisconnectOnClose; | - | ||||||
163 | QByteArray memberToDisconnectOnClose; | - | ||||||
164 | }; | - | ||||||
165 | - | |||||||
166 | void QPrintPreviewDialogPrivate::init(QPrinter *_printer) | - | ||||||
167 | { | - | ||||||
168 | QPrintPreviewDialog * const q = q_func(); | - | ||||||
169 | - | |||||||
170 | initResources(); | - | ||||||
171 | - | |||||||
172 | if (_printer
| 0-1 | ||||||
173 | preview = new QPrintPreviewWidget(_printer, q); | - | ||||||
174 | printer = _printer; | - | ||||||
175 | } executed 1 time by 1 test: else {end of block Executed by:
| 1 | ||||||
176 | ownPrinter = true; | - | ||||||
177 | printer = new QPrinter; | - | ||||||
178 | preview = new QPrintPreviewWidget(printer, q); | - | ||||||
179 | } never executed: end of block | 0 | ||||||
180 | QObject::connect(preview, qFlagLocation("2""paintRequested(QPrinter*)" "\0" __FILE__ ":" "229""235"), q, qFlagLocation("2""paintRequested(QPrinter*)" "\0" __FILE__ ":" "229""235")); | - | ||||||
181 | QObject::connect(preview, qFlagLocation("2""previewChanged()" "\0" __FILE__ ":" "230""236"), q, qFlagLocation("1""_q_previewChanged()" "\0" __FILE__ ":" "230""236")); | - | ||||||
182 | setupActions(); | - | ||||||
183 | - | |||||||
184 | pageNumEdit = new LineEdit; | - | ||||||
185 | pageNumEdit->setAlignment(Qt::AlignRight); | - | ||||||
186 | pageNumEdit->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); | - | ||||||
187 | pageNumLabel = new QLabel; | - | ||||||
188 | QObject::connect(pageNumEdit, qFlagLocation("2""editingFinished()" "\0" __FILE__ ":" "237""243"), q, qFlagLocation("1""_q_pageNumEdited()" "\0" __FILE__ ":" "237""243")); | - | ||||||
189 | - | |||||||
190 | zoomFactor = new QComboBox; | - | ||||||
191 | zoomFactor->setEditable(true); | - | ||||||
192 | zoomFactor->setMinimumContentsLength(7); | - | ||||||
193 | zoomFactor->setInsertPolicy(QComboBox::NoInsert); | - | ||||||
194 | LineEdit *zoomEditor = new LineEdit; | - | ||||||
195 | zoomEditor->setValidator(new ZoomFactorValidator(1, 1000, 1, zoomEditor)); | - | ||||||
196 | zoomFactor->setLineEdit(zoomEditor); | - | ||||||
197 | static const short factorsX2[] = { 25, 50, 100, 200, 250, 300, 400, 800, 1600 }; | - | ||||||
198 | for (int i = 0; i < int(sizeof(factorsX2) / sizeof(auto factorX2 : factorsX2[0])); ++i) | - | ||||||
199 | zoomFactor->addItem(QPrintPreviewDialog::tr("%1%").arg(factorsX2[i]factorX2 / 2.0)); executed 9 times by 1 test: zoomFactor->addItem(QPrintPreviewDialog::tr("%1%").arg(factorX2 / 2.0)); Executed by:
| 9 | ||||||
200 | QObject::connect(zoomFactor->lineEdit(), qFlagLocation("2""editingFinished()" "\0" __FILE__ ":" "249""255"), | - | ||||||
201 | q, qFlagLocation("1""_q_zoomFactorChanged()" "\0" __FILE__ ":" "250""256")); | - | ||||||
202 | QObject::connect(zoomFactor, qFlagLocation("2""currentIndexChanged(int)" "\0" __FILE__ ":" "251""257"), | - | ||||||
203 | q, qFlagLocation("1""_q_zoomFactorChanged()" "\0" __FILE__ ":" "252""258")); | - | ||||||
204 | - | |||||||
205 | QPrintPreviewMainWindow *mw = new QPrintPreviewMainWindow(q); | - | ||||||
206 | QToolBar *toolbar = new QToolBar(mw); | - | ||||||
207 | toolbar->addAction(fitWidthAction); | - | ||||||
208 | toolbar->addAction(fitPageAction); | - | ||||||
209 | toolbar->addSeparator(); | - | ||||||
210 | toolbar->addWidget(zoomFactor); | - | ||||||
211 | toolbar->addAction(zoomOutAction); | - | ||||||
212 | toolbar->addAction(zoomInAction); | - | ||||||
213 | toolbar->addSeparator(); | - | ||||||
214 | toolbar->addAction(portraitAction); | - | ||||||
215 | toolbar->addAction(landscapeAction); | - | ||||||
216 | toolbar->addSeparator(); | - | ||||||
217 | toolbar->addAction(firstPageAction); | - | ||||||
218 | toolbar->addAction(prevPageAction); | - | ||||||
219 | - | |||||||
220 | - | |||||||
221 | - | |||||||
222 | - | |||||||
223 | QWidget *pageEdit = new QWidget(toolbar); | - | ||||||
224 | QVBoxLayout *vboxLayout = new QVBoxLayout; | - | ||||||
225 | vboxLayout->setContentsMargins(0, 0, 0, 0); | - | ||||||
226 | QFormLayout *formLayout = new QFormLayout; | - | ||||||
227 | - | |||||||
228 | - | |||||||
229 | - | |||||||
230 | - | |||||||
231 | formLayout->setWidget(0, QFormLayout::LabelRole, pageNumEdit); | - | ||||||
232 | formLayout->setWidget(0, QFormLayout::FieldRole, pageNumLabel); | - | ||||||
233 | vboxLayout->addLayout(formLayout); | - | ||||||
234 | vboxLayout->setAlignment(Qt::AlignVCenter); | - | ||||||
235 | pageEdit->setLayout(vboxLayout); | - | ||||||
236 | toolbar->addWidget(pageEdit); | - | ||||||
237 | - | |||||||
238 | toolbar->addAction(nextPageAction); | - | ||||||
239 | toolbar->addAction(lastPageAction); | - | ||||||
240 | toolbar->addSeparator(); | - | ||||||
241 | toolbar->addAction(singleModeAction); | - | ||||||
242 | toolbar->addAction(facingModeAction); | - | ||||||
243 | toolbar->addAction(overviewModeAction); | - | ||||||
244 | toolbar->addSeparator(); | - | ||||||
245 | toolbar->addAction(pageSetupAction); | - | ||||||
246 | toolbar->addAction(printAction); | - | ||||||
247 | - | |||||||
248 | - | |||||||
249 | QToolButton *zoomInButton = static_cast<QToolButton *>(toolbar->widgetForAction(zoomInAction)); | - | ||||||
250 | QToolButton *zoomOutButton = static_cast<QToolButton *>(toolbar->widgetForAction(zoomOutAction)); | - | ||||||
251 | zoomInButton->setAutoRepeat(true); | - | ||||||
252 | zoomInButton->setAutoRepeatInterval(200); | - | ||||||
253 | zoomInButton->setAutoRepeatDelay(200); | - | ||||||
254 | zoomOutButton->setAutoRepeat(true); | - | ||||||
255 | zoomOutButton->setAutoRepeatInterval(200); | - | ||||||
256 | zoomOutButton->setAutoRepeatDelay(200); | - | ||||||
257 | QObject::connect(zoomInButton, qFlagLocation("2""clicked()" "\0" __FILE__ ":" "315""321"), q, qFlagLocation("1""_q_zoomIn()" "\0" __FILE__ ":" "315""321")); | - | ||||||
258 | QObject::connect(zoomOutButton, qFlagLocation("2""clicked()" "\0" __FILE__ ":" "316""322"), q, qFlagLocation("1""_q_zoomOut()" "\0" __FILE__ ":" "316""322")); | - | ||||||
259 | - | |||||||
260 | mw->addToolBar(toolbar); | - | ||||||
261 | mw->setCentralWidget(preview); | - | ||||||
262 | - | |||||||
263 | - | |||||||
264 | mw->setParent(q, Qt::Widget); | - | ||||||
265 | - | |||||||
266 | QVBoxLayout *topLayout = new QVBoxLayout; | - | ||||||
267 | topLayout->addWidget(mw); | - | ||||||
268 | topLayout->setMargin(0); | - | ||||||
269 | q->setLayout(topLayout); | - | ||||||
270 | - | |||||||
271 | QString caption = QCoreApplication::translate("QPrintPreviewDialog", "Print Preview"); | - | ||||||
272 | if (!printer->docName().isEmpty()
| 0-1 | ||||||
273 | caption += QString::fromLatin1(": ") + printer->docName(); never executed: caption += QString::fromLatin1(": ") + printer->docName(); | 0 | ||||||
274 | q->setWindowTitle(caption); | - | ||||||
275 | - | |||||||
276 | if (!printer->isValid()
| 0-1 | ||||||
277 | - | |||||||
278 | - | |||||||
279 | - | |||||||
280 | ) | - | ||||||
281 | pageSetupAction->setEnabled(false); never executed: pageSetupAction->setEnabled(false); | 0 | ||||||
282 | preview->setFocus(); | - | ||||||
283 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||
284 | - | |||||||
285 | static inline void qt_setupActionIcon(QAction *action, QLatin1String name) | - | ||||||
286 | { | - | ||||||
287 | QLatin1String imagePrefix(":/qt-project.org/dialogs/qprintpreviewdialog/images/"); | - | ||||||
288 | QIcon icon; | - | ||||||
289 | icon.addFile(imagePrefix + name + QLatin1String("-24.png"), QSize(24, 24)); | - | ||||||
290 | icon.addFile(imagePrefix + name + QLatin1String("-32.png"), QSize(32, 32)); | - | ||||||
291 | action->setIcon(icon); | - | ||||||
292 | } | - | ||||||
293 | - | |||||||
294 | void QPrintPreviewDialogPrivate::setupActions() | - | ||||||
295 | { | - | ||||||
296 | QPrintPreviewDialog * const q = q_func(); | - | ||||||
297 | - | |||||||
298 | - | |||||||
299 | navGroup = new QActionGroup(q); | - | ||||||
300 | navGroup->setExclusive(false); | - | ||||||
301 | nextPageAction = navGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Next page")); | - | ||||||
302 | prevPageAction = navGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Previous page")); | - | ||||||
303 | firstPageAction = navGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "First page")); | - | ||||||
304 | lastPageAction = navGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Last page")); | - | ||||||
305 | qt_setupActionIcon(nextPageAction, QLatin1String("go-next")); | - | ||||||
306 | qt_setupActionIcon(prevPageAction, QLatin1String("go-previous")); | - | ||||||
307 | qt_setupActionIcon(firstPageAction, QLatin1String("go-first")); | - | ||||||
308 | qt_setupActionIcon(lastPageAction, QLatin1String("go-last")); | - | ||||||
309 | QObject::connect(navGroup, qFlagLocation("2""triggered(QAction*)" "\0" __FILE__ ":" "367""373"), q, qFlagLocation("1""_q_navigate(QAction*)" "\0" __FILE__ ":" "367""373")); | - | ||||||
310 | - | |||||||
311 | - | |||||||
312 | fitGroup = new QActionGroup(q); | - | ||||||
313 | fitWidthAction = fitGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Fit width")); | - | ||||||
314 | fitPageAction = fitGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Fit page")); | - | ||||||
315 | fitWidthAction->setObjectName(QLatin1String("fitWidthAction")); | - | ||||||
316 | fitPageAction->setObjectName(QLatin1String("fitPageAction")); | - | ||||||
317 | fitWidthAction->setCheckable(true); | - | ||||||
318 | fitPageAction->setCheckable(true); | - | ||||||
319 | qt_setupActionIcon(fitWidthAction, QLatin1String("fit-width")); | - | ||||||
320 | qt_setupActionIcon(fitPageAction, QLatin1String("fit-page")); | - | ||||||
321 | QObject::connect(fitGroup, qFlagLocation("2""triggered(QAction*)" "\0" __FILE__ ":" "379""385"), q, qFlagLocation("1""_q_fit(QAction*)" "\0" __FILE__ ":" "379""385")); | - | ||||||
322 | - | |||||||
323 | - | |||||||
324 | zoomGroup = new QActionGroup(q); | - | ||||||
325 | zoomInAction = zoomGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Zoom in")); | - | ||||||
326 | zoomOutAction = zoomGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Zoom out")); | - | ||||||
327 | qt_setupActionIcon(zoomInAction, QLatin1String("zoom-in")); | - | ||||||
328 | qt_setupActionIcon(zoomOutAction, QLatin1String("zoom-out")); | - | ||||||
329 | - | |||||||
330 | - | |||||||
331 | orientationGroup = new QActionGroup(q); | - | ||||||
332 | portraitAction = orientationGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Portrait")); | - | ||||||
333 | landscapeAction = orientationGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Landscape")); | - | ||||||
334 | portraitAction->setCheckable(true); | - | ||||||
335 | landscapeAction->setCheckable(true); | - | ||||||
336 | qt_setupActionIcon(portraitAction, QLatin1String("layout-portrait")); | - | ||||||
337 | qt_setupActionIcon(landscapeAction, QLatin1String("layout-landscape")); | - | ||||||
338 | QObject::connect(portraitAction, qFlagLocation("2""triggered(bool)" "\0" __FILE__ ":" "396""402"), preview, qFlagLocation("1""setPortraitOrientation()" "\0" __FILE__ ":" "396""402")); | - | ||||||
339 | QObject::connect(landscapeAction, qFlagLocation("2""triggered(bool)" "\0" __FILE__ ":" "397""403"), preview, qFlagLocation("1""setLandscapeOrientation()" "\0" __FILE__ ":" "397""403")); | - | ||||||
340 | - | |||||||
341 | - | |||||||
342 | modeGroup = new QActionGroup(q); | - | ||||||
343 | singleModeAction = modeGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Show single page")); | - | ||||||
344 | facingModeAction = modeGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Show facing pages")); | - | ||||||
345 | overviewModeAction = modeGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Show overview of all pages")); | - | ||||||
346 | qt_setupActionIcon(singleModeAction, QLatin1String("view-page-one")); | - | ||||||
347 | qt_setupActionIcon(facingModeAction, QLatin1String("view-page-sided")); | - | ||||||
348 | qt_setupActionIcon(overviewModeAction, QLatin1String("view-page-multi")); | - | ||||||
349 | singleModeAction->setObjectName(QLatin1String("singleModeAction")); | - | ||||||
350 | facingModeAction->setObjectName(QLatin1String("facingModeAction")); | - | ||||||
351 | overviewModeAction->setObjectName(QLatin1String("overviewModeAction")); | - | ||||||
352 | - | |||||||
353 | singleModeAction->setCheckable(true); | - | ||||||
354 | facingModeAction->setCheckable(true); | - | ||||||
355 | overviewModeAction->setCheckable(true); | - | ||||||
356 | QObject::connect(modeGroup, qFlagLocation("2""triggered(QAction*)" "\0" __FILE__ ":" "414""420"), q, qFlagLocation("1""_q_setMode(QAction*)" "\0" __FILE__ ":" "414""420")); | - | ||||||
357 | - | |||||||
358 | - | |||||||
359 | printerGroup = new QActionGroup(q); | - | ||||||
360 | printAction = printerGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Print")); | - | ||||||
361 | pageSetupAction = printerGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Page setup")); | - | ||||||
362 | qt_setupActionIcon(printAction, QLatin1String("print")); | - | ||||||
363 | qt_setupActionIcon(pageSetupAction, QLatin1String("page-setup")); | - | ||||||
364 | QObject::connect(printAction, qFlagLocation("2""triggered(bool)" "\0" __FILE__ ":" "422""428"), q, qFlagLocation("1""_q_print()" "\0" __FILE__ ":" "422""428")); | - | ||||||
365 | QObject::connect(pageSetupAction, qFlagLocation("2""triggered(bool)" "\0" __FILE__ ":" "423""429"), q, qFlagLocation("1""_q_pageSetup()" "\0" __FILE__ ":" "423""429")); | - | ||||||
366 | - | |||||||
367 | - | |||||||
368 | fitPageAction->setChecked(true); | - | ||||||
369 | singleModeAction->setChecked(true); | - | ||||||
370 | if (preview->orientation() == QPrinter::Portrait) | - | ||||||
371 | portraitAction->setChecked(true); | - | ||||||
372 | else | - | ||||||
373 | landscapeAction->setChecked(true); | - | ||||||
374 | } | - | ||||||
375 | - | |||||||
376 | - | |||||||
377 | bool QPrintPreviewDialogPrivate::isFitting() | - | ||||||
378 | { | - | ||||||
379 | return (fitGroup->isExclusive() | - | ||||||
380 | && (fitWidthAction->isChecked() || fitPageAction->isChecked())); | - | ||||||
381 | } | - | ||||||
382 | - | |||||||
383 | - | |||||||
384 | void QPrintPreviewDialogPrivate::setFitting(bool on) | - | ||||||
385 | { | - | ||||||
386 | if (isFitting() == on) | - | ||||||
387 | return; | - | ||||||
388 | fitGroup->setExclusive(on); | - | ||||||
389 | if (on) { | - | ||||||
390 | QAction* action = fitWidthAction->isChecked() ? fitWidthAction : fitPageAction; | - | ||||||
391 | action->setChecked(true); | - | ||||||
392 | if (fitGroup->checkedAction() != action) { | - | ||||||
393 | - | |||||||
394 | fitGroup->removeAction(action); | - | ||||||
395 | fitGroup->addAction(action); | - | ||||||
396 | } | - | ||||||
397 | } else { | - | ||||||
398 | fitWidthAction->setChecked(false); | - | ||||||
399 | fitPageAction->setChecked(false); | - | ||||||
400 | } | - | ||||||
401 | } | - | ||||||
402 | - | |||||||
403 | void QPrintPreviewDialogPrivate::updateNavActions() | - | ||||||
404 | { | - | ||||||
405 | int curPage = preview->currentPage(); | - | ||||||
406 | int numPages = preview->pageCount(); | - | ||||||
407 | nextPageAction->setEnabled(curPage < numPages); | - | ||||||
408 | prevPageAction->setEnabled(curPage > 1); | - | ||||||
409 | firstPageAction->setEnabled(curPage > 1); | - | ||||||
410 | lastPageAction->setEnabled(curPage < numPages); | - | ||||||
411 | pageNumEdit->setText(QString::number(curPage)); | - | ||||||
412 | } | - | ||||||
413 | - | |||||||
414 | void QPrintPreviewDialogPrivate::updatePageNumLabel() | - | ||||||
415 | { | - | ||||||
416 | QPrintPreviewDialog * const q = q_func(); | - | ||||||
417 | - | |||||||
418 | int numPages = preview->pageCount(); | - | ||||||
419 | int maxChars = QString::number(numPages).length(); | - | ||||||
420 | pageNumLabel->setText(QString::fromLatin1("/ %1").arg(numPages)); | - | ||||||
421 | int cyphersWidth = q->fontMetrics().width(QString().fill(QLatin1Char('8'), maxChars)); | - | ||||||
422 | int maxWidth = pageNumEdit->minimumSizeHint().width() + cyphersWidth; | - | ||||||
423 | pageNumEdit->setMinimumWidth(maxWidth); | - | ||||||
424 | pageNumEdit->setMaximumWidth(maxWidth); | - | ||||||
425 | pageNumEdit->setValidator(new QIntValidator(1, numPages, pageNumEdit)); | - | ||||||
426 | - | |||||||
427 | } | - | ||||||
428 | - | |||||||
429 | void QPrintPreviewDialogPrivate::updateZoomFactor() | - | ||||||
430 | { | - | ||||||
431 | zoomFactor->lineEdit()->setText(QString().sprintf("%.1f%%", preview->zoomFactor()*100)); | - | ||||||
432 | } | - | ||||||
433 | - | |||||||
434 | void QPrintPreviewDialogPrivate::_q_fit(QAction* action) | - | ||||||
435 | { | - | ||||||
436 | setFitting(true); | - | ||||||
437 | if (action == fitPageAction) | - | ||||||
438 | preview->fitInView(); | - | ||||||
439 | else | - | ||||||
440 | preview->fitToWidth(); | - | ||||||
441 | } | - | ||||||
442 | - | |||||||
443 | void QPrintPreviewDialogPrivate::_q_zoomIn() | - | ||||||
444 | { | - | ||||||
445 | setFitting(false); | - | ||||||
446 | preview->zoomIn(); | - | ||||||
447 | updateZoomFactor(); | - | ||||||
448 | } | - | ||||||
449 | - | |||||||
450 | void QPrintPreviewDialogPrivate::_q_zoomOut() | - | ||||||
451 | { | - | ||||||
452 | setFitting(false); | - | ||||||
453 | preview->zoomOut(); | - | ||||||
454 | updateZoomFactor(); | - | ||||||
455 | } | - | ||||||
456 | - | |||||||
457 | void QPrintPreviewDialogPrivate::_q_pageNumEdited() | - | ||||||
458 | { | - | ||||||
459 | bool ok = false; | - | ||||||
460 | int res = pageNumEdit->text().toInt(&ok); | - | ||||||
461 | if (ok) | - | ||||||
462 | preview->setCurrentPage(res); | - | ||||||
463 | } | - | ||||||
464 | - | |||||||
465 | void QPrintPreviewDialogPrivate::_q_navigate(QAction* action) | - | ||||||
466 | { | - | ||||||
467 | int curPage = preview->currentPage(); | - | ||||||
468 | if (action == prevPageAction) | - | ||||||
469 | preview->setCurrentPage(curPage - 1); | - | ||||||
470 | else if (action == nextPageAction) | - | ||||||
471 | preview->setCurrentPage(curPage + 1); | - | ||||||
472 | else if (action == firstPageAction) | - | ||||||
473 | preview->setCurrentPage(1); | - | ||||||
474 | else if (action == lastPageAction) | - | ||||||
475 | preview->setCurrentPage(preview->pageCount()); | - | ||||||
476 | updateNavActions(); | - | ||||||
477 | } | - | ||||||
478 | - | |||||||
479 | void QPrintPreviewDialogPrivate::_q_setMode(QAction* action) | - | ||||||
480 | { | - | ||||||
481 | if (action == overviewModeAction) { | - | ||||||
482 | preview->setViewMode(QPrintPreviewWidget::AllPagesView); | - | ||||||
483 | setFitting(false); | - | ||||||
484 | fitGroup->setEnabled(false); | - | ||||||
485 | navGroup->setEnabled(false); | - | ||||||
486 | pageNumEdit->setEnabled(false); | - | ||||||
487 | pageNumLabel->setEnabled(false); | - | ||||||
488 | } else if (action == facingModeAction) { | - | ||||||
489 | preview->setViewMode(QPrintPreviewWidget::FacingPagesView); | - | ||||||
490 | } else { | - | ||||||
491 | preview->setViewMode(QPrintPreviewWidget::SinglePageView); | - | ||||||
492 | } | - | ||||||
493 | if (action == facingModeAction || action == singleModeAction) { | - | ||||||
494 | fitGroup->setEnabled(true); | - | ||||||
495 | navGroup->setEnabled(true); | - | ||||||
496 | pageNumEdit->setEnabled(true); | - | ||||||
497 | pageNumLabel->setEnabled(true); | - | ||||||
498 | setFitting(true); | - | ||||||
499 | } | - | ||||||
500 | } | - | ||||||
501 | - | |||||||
502 | void QPrintPreviewDialogPrivate::_q_print() | - | ||||||
503 | { | - | ||||||
504 | QPrintPreviewDialog * const q = q_func(); | - | ||||||
505 | if (!printDialog) | - | ||||||
506 | printDialog = new QPrintDialog(printer, q); | - | ||||||
507 | if (printDialog->exec() == QDialog::Accepted) { | - | ||||||
508 | preview->print(); | - | ||||||
509 | q->accept(); | - | ||||||
510 | } | - | ||||||
511 | } | - | ||||||
512 | - | |||||||
513 | void QPrintPreviewDialogPrivate::_q_pageSetup() | - | ||||||
514 | { | - | ||||||
515 | QPrintPreviewDialog * const q = q_func(); | - | ||||||
516 | - | |||||||
517 | QPageSetupDialog pageSetup(printer, q); | - | ||||||
518 | if (pageSetup.exec() == QDialog::Accepted) { | - | ||||||
519 | - | |||||||
520 | if (preview->orientation() == QPrinter::Portrait) { | - | ||||||
521 | portraitAction->setChecked(true); | - | ||||||
522 | preview->setPortraitOrientation(); | - | ||||||
523 | }else { | - | ||||||
524 | landscapeAction->setChecked(true); | - | ||||||
525 | preview->setLandscapeOrientation(); | - | ||||||
526 | } | - | ||||||
527 | } | - | ||||||
528 | } | - | ||||||
529 | - | |||||||
530 | void QPrintPreviewDialogPrivate::_q_previewChanged() | - | ||||||
531 | { | - | ||||||
532 | updateNavActions(); | - | ||||||
533 | updatePageNumLabel(); | - | ||||||
534 | updateZoomFactor(); | - | ||||||
535 | } | - | ||||||
536 | - | |||||||
537 | void QPrintPreviewDialogPrivate::_q_zoomFactorChanged() | - | ||||||
538 | { | - | ||||||
539 | QString text = zoomFactor->lineEdit()->text(); | - | ||||||
540 | bool ok; | - | ||||||
541 | qreal factor = text.remove(QLatin1Char('%')).toFloat(&ok); | - | ||||||
542 | factor = qMax(qreal(1.0), qMin(qreal(1000.0), factor)); | - | ||||||
543 | if (ok) { | - | ||||||
544 | preview->setZoomFactor(factor/100.0); | - | ||||||
545 | zoomFactor->setEditText(QString::fromLatin1("%1%").arg(factor)); | - | ||||||
546 | setFitting(false); | - | ||||||
547 | } | - | ||||||
548 | } | - | ||||||
549 | QPrintPreviewDialog::QPrintPreviewDialog(QPrinter* printer, QWidget *parent, Qt::WindowFlags flags) | - | ||||||
550 | : QDialog(*new QPrintPreviewDialogPrivate, parent, flags) | - | ||||||
551 | { | - | ||||||
552 | QPrintPreviewDialogPrivate * const d = d_func(); | - | ||||||
553 | d->init(printer); | - | ||||||
554 | } | - | ||||||
555 | QPrintPreviewDialog::QPrintPreviewDialog(QWidget *parent, Qt::WindowFlags f) | - | ||||||
556 | : QDialog(*new QPrintPreviewDialogPrivate, parent, f) | - | ||||||
557 | { | - | ||||||
558 | QPrintPreviewDialogPrivate * const d = d_func(); | - | ||||||
559 | d->init(); | - | ||||||
560 | } | - | ||||||
561 | - | |||||||
562 | - | |||||||
563 | - | |||||||
564 | - | |||||||
565 | QPrintPreviewDialog::~QPrintPreviewDialog() | - | ||||||
566 | { | - | ||||||
567 | QPrintPreviewDialogPrivate * const d = d_func(); | - | ||||||
568 | if (d->ownPrinter) | - | ||||||
569 | delete d->printer; | - | ||||||
570 | delete d->printDialog; | - | ||||||
571 | } | - | ||||||
572 | - | |||||||
573 | - | |||||||
574 | - | |||||||
575 | - | |||||||
576 | void QPrintPreviewDialog::setVisible(bool visible) | - | ||||||
577 | { | - | ||||||
578 | QPrintPreviewDialogPrivate * const d = d_func(); | - | ||||||
579 | - | |||||||
580 | if (visible && !d->initialized) { | - | ||||||
581 | d->preview->updatePreview(); | - | ||||||
582 | d->initialized = true; | - | ||||||
583 | } | - | ||||||
584 | QDialog::setVisible(visible); | - | ||||||
585 | } | - | ||||||
586 | - | |||||||
587 | - | |||||||
588 | - | |||||||
589 | - | |||||||
590 | void QPrintPreviewDialog::done(int result) | - | ||||||
591 | { | - | ||||||
592 | QPrintPreviewDialogPrivate * const d = d_func(); | - | ||||||
593 | QDialog::done(result); | - | ||||||
594 | if (d->receiverToDisconnectOnClose) { | - | ||||||
595 | disconnect(this, qFlagLocation("2""finished(int)" "\0" __FILE__ ":" "729""735"), | - | ||||||
596 | d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose); | - | ||||||
597 | d->receiverToDisconnectOnClose = 0; | - | ||||||
598 | } | - | ||||||
599 | d->memberToDisconnectOnClose.clear(); | - | ||||||
600 | } | - | ||||||
601 | void QPrintPreviewDialog::open(QObject *receiver, const char *member) | - | ||||||
602 | { | - | ||||||
603 | QPrintPreviewDialogPrivate * const d = d_func(); | - | ||||||
604 | - | |||||||
605 | - | |||||||
606 | connect(this, qFlagLocation("2""finished(int)" "\0" __FILE__ ":" "750""756"), receiver, member); | - | ||||||
607 | d->receiverToDisconnectOnClose = receiver; | - | ||||||
608 | d->memberToDisconnectOnClose = member; | - | ||||||
609 | QDialog::open(); | - | ||||||
610 | } | - | ||||||
611 | - | |||||||
612 | - | |||||||
613 | - | |||||||
614 | - | |||||||
615 | - | |||||||
616 | QPrinter *QPrintPreviewDialog::printer() | - | ||||||
617 | { | - | ||||||
618 | QPrintPreviewDialogPrivate * const d = d_func(); | - | ||||||
619 | return d->printer; | - | ||||||
620 | } | - | ||||||
621 | - | |||||||
622 | - | |||||||
Switch to Source code | Preprocessed file |