Qt 4.8
qprintpreviewdialog.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 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 
47 #include <QtGui/qaction.h>
48 #include <QtGui/qboxlayout.h>
49 #include <QtGui/qcombobox.h>
50 #include <QtGui/qlabel.h>
51 #include <QtGui/qlineedit.h>
52 #include <QtGui/qpagesetupdialog.h>
53 #include <QtGui/qprinter.h>
54 #include <QtGui/qstyle.h>
55 #include <QtGui/qtoolbutton.h>
56 #include <QtGui/qvalidator.h>
57 #include <QtGui/qfiledialog.h>
58 #include <QtGui/qmainwindow.h>
59 #include <QtGui/qtoolbar.h>
60 #include <QtGui/qformlayout.h>
61 #include <QtCore/QCoreApplication>
62 
63 #include <math.h>
64 
65 #ifndef QT_NO_PRINTPREVIEWDIALOG
66 
68 
69 namespace {
70 class QPrintPreviewMainWindow : public QMainWindow
71 {
72 public:
73  QPrintPreviewMainWindow(QWidget *parent) : QMainWindow(parent) {}
74  QMenu *createPopupMenu() { return 0; }
75 };
76 
77 class ZoomFactorValidator : public QDoubleValidator
78 {
79 public:
80  ZoomFactorValidator(QObject* parent)
81  : QDoubleValidator(parent) {}
82  ZoomFactorValidator(qreal bottom, qreal top, int decimals, QObject *parent)
83  : QDoubleValidator(bottom, top, decimals, parent) {}
84 
85  State validate(QString &input, int &pos) const
86  {
87  bool replacePercent = false;
88  if (input.endsWith(QLatin1Char('%'))) {
89  input = input.left(input.length() - 1);
90  replacePercent = true;
91  }
92  State state = QDoubleValidator::validate(input, pos);
93  if (replacePercent)
94  input += QLatin1Char('%');
95  const int num_size = 4;
96  if (state == Intermediate) {
97  int i = input.indexOf(QLocale::system().decimalPoint());
98  if ((i == -1 && input.size() > num_size)
99  || (i != -1 && i > num_size))
100  return Invalid;
101  }
102  return state;
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  }
116 
117 protected:
118  void focusInEvent(QFocusEvent *e)
119  {
120  origText = text();
122  }
123 
124  void focusOutEvent(QFocusEvent *e)
125  {
126  if (isModified() && !hasAcceptableInput())
127  setText(origText);
129  }
130 
131 private slots:
132  void handleReturnPressed()
133  {
134  origText = text();
135  }
136 
137 private:
138  QString origText;
139 };
140 } // anonymous namespace
141 
143 {
145 public:
147  : printDialog(0), ownPrinter(false),
148  initialized(false) {}
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 
177 
178  // widgets:
182 
183  // actions:
189 
193 
197 
201 
206 
210 #if defined(Q_WS_MAC) && !defined(QT_MAC_USE_COCOA)
212 #endif
213 
216 };
217 
219 {
221 
222  if (_printer) {
223  preview = new QPrintPreviewWidget(_printer, q);
224  printer = _printer;
225  } else {
226  ownPrinter = true;
227  printer = new QPrinter;
228  preview = new QPrintPreviewWidget(printer, q);
229  }
230  QObject::connect(preview, SIGNAL(paintRequested(QPrinter*)), q, SIGNAL(paintRequested(QPrinter*)));
231  QObject::connect(preview, SIGNAL(previewChanged()), q, SLOT(_q_previewChanged()));
232  setupActions();
233 
234  pageNumEdit = new LineEdit;
235  pageNumEdit->setAlignment(Qt::AlignRight);
236  pageNumEdit->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
237  pageNumLabel = new QLabel;
238  QObject::connect(pageNumEdit, SIGNAL(editingFinished()), q, SLOT(_q_pageNumEdited()));
239 
240  zoomFactor = new QComboBox;
241  zoomFactor->setEditable(true);
242  zoomFactor->setMinimumContentsLength(7);
243  zoomFactor->setInsertPolicy(QComboBox::NoInsert);
244  LineEdit *zoomEditor = new LineEdit;
245  zoomEditor->setValidator(new ZoomFactorValidator(1, 1000, 1, zoomEditor));
246  zoomFactor->setLineEdit(zoomEditor);
247  static const short factorsX2[] = { 25, 50, 100, 200, 250, 300, 400, 800, 1600 };
248  for (int i = 0; i < int(sizeof(factorsX2) / sizeof(factorsX2[0])); ++i)
249  zoomFactor->addItem(QPrintPreviewDialog::tr("%1%").arg(factorsX2[i] / 2.0));
250  QObject::connect(zoomFactor->lineEdit(), SIGNAL(editingFinished()),
251  q, SLOT(_q_zoomFactorChanged()));
252  QObject::connect(zoomFactor, SIGNAL(currentIndexChanged(int)),
253  q, SLOT(_q_zoomFactorChanged()));
254 
255  QPrintPreviewMainWindow *mw = new QPrintPreviewMainWindow(q);
256  QToolBar *toolbar = new QToolBar(mw);
257  toolbar->addAction(fitWidthAction);
258  toolbar->addAction(fitPageAction);
259  toolbar->addSeparator();
260  toolbar->addWidget(zoomFactor);
261  toolbar->addAction(zoomOutAction);
262  toolbar->addAction(zoomInAction);
263  toolbar->addSeparator();
264  toolbar->addAction(portraitAction);
265  toolbar->addAction(landscapeAction);
266  toolbar->addSeparator();
267  toolbar->addAction(firstPageAction);
268  toolbar->addAction(prevPageAction);
269 
270  // this is to ensure the label text and the editor text are
271  // aligned in all styles - the extra QVBoxLayout is a workaround
272  // for bug in QFormLayout
273  QWidget *pageEdit = new QWidget(toolbar);
274  QVBoxLayout *vboxLayout = new QVBoxLayout;
275  vboxLayout->setContentsMargins(0, 0, 0, 0);
276 #ifdef Q_WS_MAC
277  // We query the widgets about their size and then we fix the size.
278  // This should do the trick for the laying out part...
279  QSize pageNumEditSize, pageNumLabelSize;
280  pageNumEditSize = pageNumEdit->minimumSizeHint();
281  pageNumLabelSize = pageNumLabel->minimumSizeHint();
282  pageNumEdit->resize(pageNumEditSize);
283  pageNumLabel->resize(pageNumLabelSize);
284 #endif
285  QFormLayout *formLayout = new QFormLayout;
286 #ifdef Q_WS_MAC
287  // We have to change the growth policy in Mac.
289 #endif
290  formLayout->setWidget(0, QFormLayout::LabelRole, pageNumEdit);
291  formLayout->setWidget(0, QFormLayout::FieldRole, pageNumLabel);
292  vboxLayout->addLayout(formLayout);
293  vboxLayout->setAlignment(Qt::AlignVCenter);
294  pageEdit->setLayout(vboxLayout);
295  toolbar->addWidget(pageEdit);
296 
297  toolbar->addAction(nextPageAction);
298  toolbar->addAction(lastPageAction);
299  toolbar->addSeparator();
300  toolbar->addAction(singleModeAction);
301  toolbar->addAction(facingModeAction);
302  toolbar->addAction(overviewModeAction);
303  toolbar->addSeparator();
304  toolbar->addAction(pageSetupAction);
305  toolbar->addAction(printAction);
306 #if defined(Q_WS_MAC) && !defined(QT_MAC_USE_COCOA)
307  toolbar->addAction(closeAction);
308 #endif
309 
310  // Cannot use the actions' triggered signal here, since it doesn't autorepeat
311  QToolButton *zoomInButton = static_cast<QToolButton *>(toolbar->widgetForAction(zoomInAction));
312  QToolButton *zoomOutButton = static_cast<QToolButton *>(toolbar->widgetForAction(zoomOutAction));
313  zoomInButton->setAutoRepeat(true);
314  zoomInButton->setAutoRepeatInterval(200);
315  zoomInButton->setAutoRepeatDelay(200);
316  zoomOutButton->setAutoRepeat(true);
317  zoomOutButton->setAutoRepeatInterval(200);
318  zoomOutButton->setAutoRepeatDelay(200);
319  QObject::connect(zoomInButton, SIGNAL(clicked()), q, SLOT(_q_zoomIn()));
320  QObject::connect(zoomOutButton, SIGNAL(clicked()), q, SLOT(_q_zoomOut()));
321 
322  mw->addToolBar(toolbar);
323  mw->setCentralWidget(preview);
324  // QMainWindows are always created as top levels, force it to be a
325  // plain widget
326  mw->setParent(q, Qt::Widget);
327 
328  QVBoxLayout *topLayout = new QVBoxLayout;
329  topLayout->addWidget(mw);
330  topLayout->setMargin(0);
331  q->setLayout(topLayout);
332 
333  QString caption = QCoreApplication::translate("QPrintPreviewDialog", "Print Preview");
334  if (!printer->docName().isEmpty())
335  caption += QString::fromLatin1(": ") + printer->docName();
336  q->setWindowTitle(caption);
337 
338  if (!printer->isValid()
339 #if defined(Q_WS_WIN) || defined(Q_WS_MAC)
340  || printer->outputFormat() != QPrinter::NativeFormat
341 #endif
342  )
343  pageSetupAction->setEnabled(false);
344  preview->setFocus();
345 }
346 
347 static inline void qt_setupActionIcon(QAction *action, const QLatin1String &name)
348 {
349  QLatin1String imagePrefix(":/trolltech/dialogs/qprintpreviewdialog/images/");
350  QIcon icon;
351  icon.addFile(imagePrefix + name + QLatin1String("-24.png"), QSize(24, 24));
352  icon.addFile(imagePrefix + name + QLatin1String("-32.png"), QSize(32, 32));
353  action->setIcon(icon);
354 }
355 
357 {
359 
360  // Navigation
361  navGroup = new QActionGroup(q);
362  navGroup->setExclusive(false);
363  nextPageAction = navGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Next page"));
364  prevPageAction = navGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Previous page"));
365  firstPageAction = navGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "First page"));
366  lastPageAction = navGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Last page"));
367  qt_setupActionIcon(nextPageAction, QLatin1String("go-next"));
368  qt_setupActionIcon(prevPageAction, QLatin1String("go-previous"));
369  qt_setupActionIcon(firstPageAction, QLatin1String("go-first"));
370  qt_setupActionIcon(lastPageAction, QLatin1String("go-last"));
371  QObject::connect(navGroup, SIGNAL(triggered(QAction*)), q, SLOT(_q_navigate(QAction*)));
372 
373 
374  fitGroup = new QActionGroup(q);
375  fitWidthAction = fitGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Fit width"));
376  fitPageAction = fitGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Fit page"));
377  fitWidthAction->setObjectName(QLatin1String("fitWidthAction"));
378  fitPageAction->setObjectName(QLatin1String("fitPageAction"));
379  fitWidthAction->setCheckable(true);
380  fitPageAction->setCheckable(true);
381  qt_setupActionIcon(fitWidthAction, QLatin1String("fit-width"));
382  qt_setupActionIcon(fitPageAction, QLatin1String("fit-page"));
383  QObject::connect(fitGroup, SIGNAL(triggered(QAction*)), q, SLOT(_q_fit(QAction*)));
384 
385  // Zoom
386  zoomGroup = new QActionGroup(q);
387  zoomInAction = zoomGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Zoom in"));
388  zoomOutAction = zoomGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Zoom out"));
389  qt_setupActionIcon(zoomInAction, QLatin1String("zoom-in"));
390  qt_setupActionIcon(zoomOutAction, QLatin1String("zoom-out"));
391 
392  // Portrait/Landscape
393  orientationGroup = new QActionGroup(q);
394  portraitAction = orientationGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Portrait"));
395  landscapeAction = orientationGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Landscape"));
396  portraitAction->setCheckable(true);
397  landscapeAction->setCheckable(true);
398  qt_setupActionIcon(portraitAction, QLatin1String("layout-portrait"));
399  qt_setupActionIcon(landscapeAction, QLatin1String("layout-landscape"));
400  QObject::connect(portraitAction, SIGNAL(triggered(bool)), preview, SLOT(setPortraitOrientation()));
401  QObject::connect(landscapeAction, SIGNAL(triggered(bool)), preview, SLOT(setLandscapeOrientation()));
402 
403  // Display mode
404  modeGroup = new QActionGroup(q);
405  singleModeAction = modeGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Show single page"));
406  facingModeAction = modeGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Show facing pages"));
407  overviewModeAction = modeGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Show overview of all pages"));
408  qt_setupActionIcon(singleModeAction, QLatin1String("view-page-one"));
409  qt_setupActionIcon(facingModeAction, QLatin1String("view-page-sided"));
410  qt_setupActionIcon(overviewModeAction, QLatin1String("view-page-multi"));
411  singleModeAction->setObjectName(QLatin1String("singleModeAction"));
412  facingModeAction->setObjectName(QLatin1String("facingModeAction"));
413  overviewModeAction->setObjectName(QLatin1String("overviewModeAction"));
414 
415  singleModeAction->setCheckable(true);
416  facingModeAction->setCheckable(true);
417  overviewModeAction->setCheckable(true);
418  QObject::connect(modeGroup, SIGNAL(triggered(QAction*)), q, SLOT(_q_setMode(QAction*)));
419 
420  // Print
421  printerGroup = new QActionGroup(q);
422  printAction = printerGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Print"));
423  pageSetupAction = printerGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Page setup"));
424  qt_setupActionIcon(printAction, QLatin1String("print"));
425  qt_setupActionIcon(pageSetupAction, QLatin1String("page-setup"));
426  QObject::connect(printAction, SIGNAL(triggered(bool)), q, SLOT(_q_print()));
427  QObject::connect(pageSetupAction, SIGNAL(triggered(bool)), q, SLOT(_q_pageSetup()));
428 #if defined(Q_WS_MAC) && !defined(QT_MAC_USE_COCOA)
429  closeAction = printerGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Close"));
430  QObject::connect(closeAction, SIGNAL(triggered(bool)), q, SLOT(reject()));
431 #endif
432 
433  // Initial state:
434  fitPageAction->setChecked(true);
435  singleModeAction->setChecked(true);
436  if (preview->orientation() == QPrinter::Portrait)
437  portraitAction->setChecked(true);
438  else
439  landscapeAction->setChecked(true);
440 }
441 
442 
444 {
445  return (fitGroup->isExclusive()
446  && (fitWidthAction->isChecked() || fitPageAction->isChecked()));
447 }
448 
449 
451 {
452  if (isFitting() == on)
453  return;
454  fitGroup->setExclusive(on);
455  if (on) {
456  QAction* action = fitWidthAction->isChecked() ? fitWidthAction : fitPageAction;
457  action->setChecked(true);
458  if (fitGroup->checkedAction() != action) {
459  // work around exclusitivity problem
460  fitGroup->removeAction(action);
461  fitGroup->addAction(action);
462  }
463  } else {
464  fitWidthAction->setChecked(false);
465  fitPageAction->setChecked(false);
466  }
467 }
468 
470 {
471  int curPage = preview->currentPage();
472  int numPages = preview->pageCount();
473  nextPageAction->setEnabled(curPage < numPages);
474  prevPageAction->setEnabled(curPage > 1);
475  firstPageAction->setEnabled(curPage > 1);
476  lastPageAction->setEnabled(curPage < numPages);
477  pageNumEdit->setText(QString::number(curPage));
478 }
479 
481 {
483 
484  int numPages = preview->pageCount();
485  int maxChars = QString::number(numPages).length();
486  pageNumLabel->setText(QString::fromLatin1("/ %1").arg(numPages));
487  int cyphersWidth = q->fontMetrics().width(QString().fill(QLatin1Char('8'), maxChars));
488  int maxWidth = pageNumEdit->minimumSizeHint().width() + cyphersWidth;
489  pageNumEdit->setMinimumWidth(maxWidth);
490  pageNumEdit->setMaximumWidth(maxWidth);
491  pageNumEdit->setValidator(new QIntValidator(1, numPages, pageNumEdit));
492  // any old one will be deleted later along with its parent pageNumEdit
493 }
494 
496 {
497  zoomFactor->lineEdit()->setText(QString().sprintf("%.1f%%", preview->zoomFactor()*100));
498 }
499 
501 {
502  setFitting(true);
503  if (action == fitPageAction)
504  preview->fitInView();
505  else
506  preview->fitToWidth();
507 }
508 
510 {
511  setFitting(false);
512  preview->zoomIn();
513  updateZoomFactor();
514 }
515 
517 {
518  setFitting(false);
519  preview->zoomOut();
520  updateZoomFactor();
521 }
522 
524 {
525  bool ok = false;
526  int res = pageNumEdit->text().toInt(&ok);
527  if (ok)
528  preview->setCurrentPage(res);
529 }
530 
532 {
533  int curPage = preview->currentPage();
534  if (action == prevPageAction)
535  preview->setCurrentPage(curPage - 1);
536  else if (action == nextPageAction)
537  preview->setCurrentPage(curPage + 1);
538  else if (action == firstPageAction)
539  preview->setCurrentPage(1);
540  else if (action == lastPageAction)
541  preview->setCurrentPage(preview->pageCount());
542  updateNavActions();
543 }
544 
546 {
547  if (action == overviewModeAction) {
548  preview->setViewMode(QPrintPreviewWidget::AllPagesView);
549  setFitting(false);
550  fitGroup->setEnabled(false);
551  navGroup->setEnabled(false);
552  pageNumEdit->setEnabled(false);
553  pageNumLabel->setEnabled(false);
554  } else if (action == facingModeAction) {
555  preview->setViewMode(QPrintPreviewWidget::FacingPagesView);
556  } else {
557  preview->setViewMode(QPrintPreviewWidget::SinglePageView);
558  }
559  if (action == facingModeAction || action == singleModeAction) {
560  fitGroup->setEnabled(true);
561  navGroup->setEnabled(true);
562  pageNumEdit->setEnabled(true);
563  pageNumLabel->setEnabled(true);
564  setFitting(true);
565  }
566 }
567 
569 {
571 
572 #if defined(Q_WS_WIN) || defined(Q_WS_MAC)
573  if (printer->outputFormat() != QPrinter::NativeFormat) {
574  QString title;
575  QString suffix;
576  if (printer->outputFormat() == QPrinter::PdfFormat) {
577  title = QCoreApplication::translate("QPrintPreviewDialog", "Export to PDF");
578  suffix = QLatin1String(".pdf");
579  } else {
580  title = QCoreApplication::translate("QPrintPreviewDialog", "Export to PostScript");
581  suffix = QLatin1String(".ps");
582  }
583  QString fileName = QFileDialog::getSaveFileName(q, title, printer->outputFileName(),
584  QLatin1Char('*') + suffix);
585  if (!fileName.isEmpty()) {
586  if (QFileInfo(fileName).suffix().isEmpty())
587  fileName.append(suffix);
588  printer->setOutputFileName(fileName);
589  }
590  if (!printer->outputFileName().isEmpty())
591  preview->print();
592  q->accept();
593  return;
594  }
595 #endif
596 
597  if (!printDialog)
598  printDialog = new QPrintDialog(printer, q);
599  if (printDialog->exec() == QDialog::Accepted) {
600  preview->print();
601  q->accept();
602  }
603 }
604 
606 {
608 
609  QPageSetupDialog pageSetup(printer, q);
610  if (pageSetup.exec() == QDialog::Accepted) {
611  // update possible orientation changes
612  if (preview->orientation() == QPrinter::Portrait) {
613  portraitAction->setChecked(true);
614  preview->setPortraitOrientation();
615  }else {
616  landscapeAction->setChecked(true);
617  preview->setLandscapeOrientation();
618  }
619  }
620 }
621 
623 {
624  updateNavActions();
625  updatePageNumLabel();
626  updateZoomFactor();
627 }
628 
630 {
631  QString text = zoomFactor->lineEdit()->text();
632  bool ok;
633  qreal factor = text.remove(QLatin1Char('%')).toFloat(&ok);
634  factor = qMax(qreal(1.0), qMin(qreal(1000.0), factor));
635  if (ok) {
636  preview->setZoomFactor(factor/100.0);
637  zoomFactor->setEditText(QString::fromLatin1("%1%").arg(factor));
638  setFitting(false);
639  }
640 }
641 
643 
695 QPrintPreviewDialog::QPrintPreviewDialog(QPrinter* printer, QWidget *parent, Qt::WindowFlags flags)
696  : QDialog(*new QPrintPreviewDialogPrivate, parent, flags)
697 {
699  d->init(printer);
700 }
701 
710  : QDialog(*new QPrintPreviewDialogPrivate, parent, f)
711 {
713  d->init();
714 }
715 
720 {
722  if (d->ownPrinter)
723  delete d->printer;
724  delete d->printDialog;
725 }
726 
731 {
733  // this will make the dialog get a decent default size
734  if (visible && !d->initialized) {
735  d->preview->updatePreview();
736  d->initialized = true;
737  }
738  QDialog::setVisible(visible);
739 }
740 
745 {
747  QDialog::done(result);
748  if (d->receiverToDisconnectOnClose) {
749  disconnect(this, SIGNAL(finished(int)),
750  d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose);
751  d->receiverToDisconnectOnClose = 0;
752  }
753  d->memberToDisconnectOnClose.clear();
754 }
755 
768 void QPrintPreviewDialog::open(QObject *receiver, const char *member)
769 {
771  // the int parameter isn't very useful here; we could just as well connect
772  // to reject(), but this feels less robust somehow
773  connect(this, SIGNAL(finished(int)), receiver, member);
774  d->receiverToDisconnectOnClose = receiver;
775  d->memberToDisconnectOnClose = member;
776  QDialog::open();
777 }
778 
784 {
786  return d->printer;
787 }
788 
802 
803 #include "moc_qprintpreviewdialog.cpp"
804 #include "qprintpreviewdialog.moc"
805 
806 #endif // QT_NO_PRINTPREVIEWDIALOG
807 
808 
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
double d
Definition: qnumeric_p.h:62
void _q_navigate(QAction *action)
void done(int result)
Reimplemented Function
virtual QMenu * createPopupMenu()
Returns a popup menu containing checkable entries for the toolbars and dock widgets present in the ma...
float toFloat(bool *ok=0) const
Definition: qstring.cpp:6257
double qreal
Definition: qglobal.h:1193
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static QString getSaveFileName(QWidget *parent=0, const QString &caption=QString(), const QString &dir=QString(), const QString &filter=QString(), QString *selectedFilter=0, Options options=0)
This is a convenience static function that will return a file name selected by the user...
void setAutoRepeatDelay(int)
void focusInEvent(QFocusEvent *)
em>Reimplemented Function
Definition: qlineedit.cpp:1900
The QDialog class is the base class of dialog windows.
Definition: qdialog.h:56
void setLayout(QLayout *)
Sets the layout manager for this widget to layout.
Definition: qwidget.cpp:10104
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void addLayout(QLayout *layout, int stretch=0)
Adds layout to the end of the box, with serial stretch factor stretch.
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
#define SLOT(a)
Definition: qobjectdefs.h:226
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
QWidget * widgetForAction(QAction *action) const
Returns the widget associated with the specified action.
Definition: qtoolbar.cpp:1358
#define Q_D(Class)
Definition: qglobal.h:2482
void addWidget(QWidget *, int stretch=0, Qt::Alignment alignment=0)
Adds widget to the end of this box layout, with a stretch factor of stretch and alignment alignment...
The QIntValidator class provides a validator that ensures a string contains a valid integer within a ...
Definition: qvalidator.h:96
NSToolbar * toolbar
The QActionGroup class groups actions together.
Definition: qactiongroup.h:57
~QPrintPreviewDialog()
Destroys the QPrintPreviewDialog.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
static QLocale system()
Returns a QLocale object initialized to the system locale.
Definition: qlocale.cpp:1917
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
#define Q_Q(Class)
Definition: qglobal.h:2483
void setAutoRepeat(bool)
void setWidget(int row, ItemRole role, QWidget *widget)
Sets the widget in the given row for the given role to widget, extending the layout with empty rows i...
#define SIGNAL(a)
Definition: qobjectdefs.h:227
The QPrintDialog class provides a dialog for specifying the printer&#39;s configuration.
Definition: qprintdialog.h:81
The QPageSetupDialog class provides a configuration dialog for the page-related options on a printer...
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
bool visible
whether the widget is visible
Definition: qwidget.h:191
void setEditable(bool editable)
Definition: qcombobox.cpp:1759
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static bool init
The QToolBar class provides a movable panel that contains a set of controls.
Definition: qtoolbar.h:62
const char * name
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
QValidator::State validate(QString &, int &) const
Returns Acceptable if the string input contains a double that is within the valid range and is in the...
Definition: qvalidator.cpp:689
The QPrintPreviewDialog class provides a dialog for previewing and configuring page layouts for print...
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
void init(QPrinter *printer=0)
The State element defines configurations of objects and properties.
#define Q_OBJECT
Definition: qobjectdefs.h:157
virtual void done(int)
Closes the dialog and sets its result code to r.
Definition: qdialog.cpp:617
QPrinter * printer()
Returns a pointer to the QPrinter object this dialog is currently operating on.
QAction * addSeparator()
Adds a separator to the end of the toolbar.
Definition: qtoolbar.cpp:936
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
The QPrintPreviewWidget class provides a widget for previewing page layouts for printer output...
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
QString & append(QChar c)
Definition: qstring.cpp:1777
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
void setChecked(bool)
Definition: qaction.cpp:1138
void setFieldGrowthPolicy(FieldGrowthPolicy policy)
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
void focusOutEvent(QFocusEvent *)
em>Reimplemented Function
Definition: qlineedit.cpp:1949
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
void setAutoRepeatInterval(int)
QAction * addWidget(QWidget *widget)
Adds the given widget to the toolbar as the toolbar&#39;s last item.
Definition: qtoolbar.cpp:973
QString suffix() const
Returns the suffix of the file.
Definition: qfileinfo.cpp:834
int result() const
In general returns the modal dialog&#39;s result code, Accepted or Rejected.
Definition: qdialog.cpp:458
QByteArray suffix
QPrintPreviewDialog(QWidget *parent=0, Qt::WindowFlags flags=0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63
void setIcon(const QIcon &icon)
Definition: qaction.cpp:772
The QLabel widget provides a text or image display.
Definition: qlabel.h:55
bool isChecked() const
Definition: qaction.cpp:1151
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
QPointer< QObject > receiverToDisconnectOnClose
void setContentsMargins(int left, int top, int right, int bottom)
Sets the left, top, right, and bottom margins to use around the layout.
Definition: qlayout.cpp:502
void _q_setMode(QAction *action)
void setVisible(bool visible)
Reimplemented Function
The QFormLayout class manages forms of input widgets and their associated labels. ...
Definition: qformlayout.h:55
void open()
Shows the dialog as a window modal dialog, returning immediately.
Definition: qdialog.cpp:492
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
The QVBoxLayout class lines up widgets vertically.
Definition: qboxlayout.h:149
The QToolButton class provides a quick-access button to commands or options, usually used inside a QT...
Definition: qtoolbutton.h:59
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867
#define slots
Definition: qobjectdefs.h:68
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
QAction * addAction(const QString &text)
Creates a new action with the given text.
Definition: qtoolbar.cpp:868
void setMargin(int)
Definition: qlayout.cpp:464
void finished(int result)
This signal is emitted when the dialog&#39;s result code has been set, either by the user or by calling d...
void setVisible(bool visible)
Reimplemented Function
Definition: qdialog.cpp:756
static QString fileName(const QString &fileUrl)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
void addFile(const QString &fileName, const QSize &size=QSize(), Mode mode=Normal, State state=Off)
Adds an image from the file with the given fileName to the icon, as a specialization for size...
Definition: qicon.cpp:851
The QFocusEvent class contains event parameters for widget focus events.
Definition: qevent.h:275
bool setAlignment(QWidget *w, Qt::Alignment alignment)
Sets the alignment for widget w to alignment and returns true if w is found in this layout (not inclu...
Definition: qlayout.cpp:332
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
#define text
Definition: qobjectdefs.h:80
The QDoubleValidator class provides range checking of floating-point numbers.
Definition: qvalidator.h:134
static void qt_setupActionIcon(QAction *action, const QLatin1String &name)
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60