Qt 4.8
qprintpreviewwidget.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 "qprintpreviewwidget.h"
43 #include "private/qwidget_p.h"
44 #include <private/qprinter_p.h>
45 
46 #include <QtCore/qmath.h>
47 #include <QtGui/qboxlayout.h>
48 #include <QtGui/qgraphicsitem.h>
49 #include <QtGui/qgraphicsview.h>
50 #include <QtGui/qscrollbar.h>
51 #include <QtGui/qstyleoption.h>
52 
53 #ifndef QT_NO_PRINTPREVIEWWIDGET
54 
56 
57 namespace {
58 class PageItem : public QGraphicsItem
59 {
60 public:
61  PageItem(int _pageNum, const QPicture* _pagePicture, QSize _paperSize, QRect _pageRect)
62  : pageNum(_pageNum), pagePicture(_pagePicture),
63  paperSize(_paperSize), pageRect(_pageRect)
64  {
65  qreal border = qMax(paperSize.height(), paperSize.width()) / 25;
66  brect = QRectF(QPointF(-border, -border),
67  QSizeF(paperSize)+QSizeF(2*border, 2*border));
68  setCacheMode(DeviceCoordinateCache);
69  }
70 
71  inline QRectF boundingRect() const
72  { return brect; }
73 
74  inline int pageNumber() const
75  { return pageNum; }
76 
77  void paint(QPainter *painter, const QStyleOptionGraphicsItem *item, QWidget *widget);
78 
79 private:
80  int pageNum;
81  const QPicture* pagePicture;
83  QRect pageRect;
84  QRectF brect;
85 };
86 
87 void PageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
88 {
89  Q_UNUSED(widget);
90 
91 #if 0
92  // Draw item bounding rect, for debugging
93  painter->save();
94  painter->setPen(QPen(Qt::red, 0));
95  painter->setBrush(Qt::NoBrush);
96  painter->drawRect(QRectF(-border()+1.0, -border()+1.0, boundingRect().width()-2, boundingRect().height()-2));
97  painter->restore();
98 #endif
99 
100  QRectF paperRect(0,0, paperSize.width(), paperSize.height());
101 
102  // Draw shadow
103  painter->setClipRect(option->exposedRect);
104  qreal shWidth = paperRect.width()/100;
105  QRectF rshadow(paperRect.topRight() + QPointF(0, shWidth),
106  paperRect.bottomRight() + QPointF(shWidth, 0));
107  QLinearGradient rgrad(rshadow.topLeft(), rshadow.topRight());
108  rgrad.setColorAt(0.0, QColor(0,0,0,255));
109  rgrad.setColorAt(1.0, QColor(0,0,0,0));
110  painter->fillRect(rshadow, QBrush(rgrad));
111  QRectF bshadow(paperRect.bottomLeft() + QPointF(shWidth, 0),
112  paperRect.bottomRight() + QPointF(0, shWidth));
113  QLinearGradient bgrad(bshadow.topLeft(), bshadow.bottomLeft());
114  bgrad.setColorAt(0.0, QColor(0,0,0,255));
115  bgrad.setColorAt(1.0, QColor(0,0,0,0));
116  painter->fillRect(bshadow, QBrush(bgrad));
117  QRectF cshadow(paperRect.bottomRight(),
118  paperRect.bottomRight() + QPointF(shWidth, shWidth));
119  QRadialGradient cgrad(cshadow.topLeft(), shWidth, cshadow.topLeft());
120  cgrad.setColorAt(0.0, QColor(0,0,0,255));
121  cgrad.setColorAt(1.0, QColor(0,0,0,0));
122  painter->fillRect(cshadow, QBrush(cgrad));
123 
124  painter->setClipRect(paperRect & option->exposedRect);
125  painter->fillRect(paperRect, Qt::white);
126  if (!pagePicture)
127  return;
128  painter->drawPicture(pageRect.topLeft(), *pagePicture);
129 
130  // Effect: make anything drawn in the margins look washed out.
131  QPainterPath path;
132  path.addRect(paperRect);
133  path.addRect(pageRect);
134  painter->setPen(QPen(Qt::NoPen));
135  painter->setBrush(QColor(255, 255, 255, 180));
136  painter->drawPath(path);
137 
138 #if 0
139  // Draw frame around paper.
140  painter->setPen(QPen(Qt::black, 0));
141  painter->setBrush(Qt::NoBrush);
142  painter->drawRect(paperRect);
143 #endif
144 
145  // todo: drawtext "Page N" below paper
146 }
147 
148 class GraphicsView : public QGraphicsView
149 {
150  Q_OBJECT
151 public:
152  GraphicsView(QWidget* parent = 0)
153  : QGraphicsView(parent)
154  {
155 #ifdef Q_WS_MAC
156  setFrameStyle(QFrame::NoFrame);
157 #endif
158  }
159 signals:
160  void resized();
161 
162 protected:
163  void resizeEvent(QResizeEvent* e)
164  {
166  emit resized();
167  }
168 
169  void showEvent(QShowEvent* e)
170  {
172  emit resized();
173  }
174 };
175 
176 } // anonymous namespace
177 
179 {
181 public:
183  : scene(0), curPage(1),
184  viewMode(QPrintPreviewWidget::SinglePageView),
185  zoomMode(QPrintPreviewWidget::FitInView),
186  zoomFactor(1), initialized(false), fitting(true)
187  {}
188 
189  // private slots
190  void _q_fit(bool doFitting = false);
191  void _q_updateCurrentPage();
192 
193  void init();
194  void populateScene();
195  void layoutPages();
196  void generatePreview();
197  void setCurrentPage(int pageNumber);
198  void zoom(qreal zoom);
199  void setZoomFactor(qreal zoomFactor);
200  int calcCurrentPage();
201 
202  GraphicsView *graphicsView;
204 
205  int curPage;
208 
215  bool fitting;
216 };
217 
219 {
221 
222  if (curPage < 1 || curPage > pages.count())
223  return;
224 
225  if (!doFitting && !fitting)
226  return;
227 
228  if (doFitting && fitting) {
229  QRect viewRect = graphicsView->viewport()->rect();
230  if (zoomMode == QPrintPreviewWidget::FitInView) {
231  QList<QGraphicsItem*> containedItems = graphicsView->items(viewRect, Qt::ContainsItemBoundingRect);
232  foreach(QGraphicsItem* item, containedItems) {
233  PageItem* pg = static_cast<PageItem*>(item);
234  if (pg->pageNumber() == curPage)
235  return;
236  }
237  }
238 
239  int newPage = calcCurrentPage();
240  if (newPage != curPage)
241  curPage = newPage;
242  }
243 
244  QRectF target = pages.at(curPage-1)->sceneBoundingRect();
245  if (viewMode == QPrintPreviewWidget::FacingPagesView) {
246  // fit two pages
247  if (curPage % 2)
248  target.setLeft(target.left() - target.width());
249  else
250  target.setRight(target.right() + target.width());
251  } else if (viewMode == QPrintPreviewWidget::AllPagesView) {
252  target = scene->itemsBoundingRect();
253  }
254 
255  if (zoomMode == QPrintPreviewWidget::FitToWidth) {
256  QTransform t;
257  qreal scale = graphicsView->viewport()->width() / target.width();
258  t.scale(scale, scale);
259  graphicsView->setTransform(t);
260  if (doFitting && fitting) {
261  QRectF viewSceneRect = graphicsView->viewportTransform().mapRect(graphicsView->viewport()->rect());
262  viewSceneRect.moveTop(target.top());
263  graphicsView->ensureVisible(viewSceneRect); // Nah...
264  }
265  } else {
266  graphicsView->fitInView(target, Qt::KeepAspectRatio);
267  if (zoomMode == QPrintPreviewWidget::FitInView) {
268  int step = qRound(graphicsView->matrix().mapRect(target).height());
269  graphicsView->verticalScrollBar()->setSingleStep(step);
270  graphicsView->verticalScrollBar()->setPageStep(step);
271  }
272  }
273 
274  zoomFactor = graphicsView->transform().m11() * (float(printer->logicalDpiY()) / q->logicalDpiY());
275  emit q->previewChanged();
276 }
277 
279 {
281 
282  if (viewMode == QPrintPreviewWidget::AllPagesView)
283  return;
284 
285  int newPage = calcCurrentPage();
286  if (newPage != curPage) {
287  curPage = newPage;
288  emit q->previewChanged();
289  }
290 }
291 
293 {
294  int maxArea = 0;
295  int newPage = curPage;
296  QRect viewRect = graphicsView->viewport()->rect();
297  QList<QGraphicsItem*> items = graphicsView->items(viewRect);
298  for (int i=0; i<items.size(); ++i) {
299  PageItem* pg = static_cast<PageItem*>(items.at(i));
300  QRect overlap = graphicsView->mapFromScene(pg->sceneBoundingRect()).boundingRect() & viewRect;
301  int area = overlap.width() * overlap.height();
302  if (area > maxArea) {
303  maxArea = area;
304  newPage = pg->pageNumber();
305  } else if (area == maxArea && pg->pageNumber() < newPage) {
306  newPage = pg->pageNumber();
307  }
308  }
309  return newPage;
310 }
311 
313 {
315 
316  graphicsView = new GraphicsView;
317  graphicsView->setInteractive(false);
318  graphicsView->setDragMode(QGraphicsView::ScrollHandDrag);
319  graphicsView->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
320  QObject::connect(graphicsView->verticalScrollBar(), SIGNAL(valueChanged(int)),
321  q, SLOT(_q_updateCurrentPage()));
322  QObject::connect(graphicsView, SIGNAL(resized()), q, SLOT(_q_fit()));
323 
324  scene = new QGraphicsScene(graphicsView);
325  scene->setBackgroundBrush(Qt::gray);
326  graphicsView->setScene(scene);
327 
329  q->setLayout(layout);
330  layout->setContentsMargins(0, 0, 0, 0);
331  layout->addWidget(graphicsView);
332 }
333 
335 {
336  // remove old pages
337  for (int i = 0; i < pages.size(); i++)
338  scene->removeItem(pages.at(i));
339  qDeleteAll(pages);
340  pages.clear();
341 
342  int numPages = pictures.count();
343  QSize paperSize = printer->paperRect().size();
344  QRect pageRect = printer->pageRect();
345 
346  for (int i = 0; i < numPages; i++) {
347  PageItem* item = new PageItem(i+1, pictures.at(i), paperSize, pageRect);
348  scene->addItem(item);
349  pages.append(item);
350  }
351 }
352 
354 {
355  int numPages = pages.count();
356  if (numPages < 1)
357  return;
358 
359  int numPagePlaces = numPages;
360  int cols = 1; // singleMode and default
361  if (viewMode == QPrintPreviewWidget::AllPagesView) {
362  if (printer->orientation() == QPrinter::Portrait)
363  cols = qCeil(qSqrt((float) numPages));
364  else
365  cols = qFloor(qSqrt((float) numPages));
366  cols += cols % 2; // Nicer with an even number of cols
367  }
368  else if (viewMode == QPrintPreviewWidget::FacingPagesView) {
369  cols = 2;
370  numPagePlaces += 1;
371  }
372  int rows = qCeil(qreal(numPagePlaces) / cols);
373 
374  qreal itemWidth = pages.at(0)->boundingRect().width();
375  qreal itemHeight = pages.at(0)->boundingRect().height();
376  int pageNum = 1;
377  for (int i = 0; i < rows && pageNum <= numPages; i++) {
378  for (int j = 0; j < cols && pageNum <= numPages; j++) {
379  if (!i && !j && viewMode == QPrintPreviewWidget::FacingPagesView) {
380  // Front page doesn't have a facing page
381  continue;
382  } else {
383  pages.at(pageNum-1)->setPos(QPointF(j*itemWidth, i*itemHeight));
384  pageNum++;
385  }
386  }
387  }
388  scene->setSceneRect(scene->itemsBoundingRect());
389 }
390 
392 {
393  //### If QPrinter::setPreviewMode() becomes public, handle the
394  //### case that we have been constructed with a printer that
395  //### _already_ has been preview-painted to, so we should
396  //### initially just show the pages it already contains, and not
397  //### emit paintRequested() until the user changes some parameter
398 
400  printer->d_func()->setPreviewMode(true);
401  emit q->paintRequested(printer);
402  printer->d_func()->setPreviewMode(false);
403  pictures = printer->d_func()->previewPages();
404  populateScene(); // i.e. setPreviewPrintedPictures() e.l.
405  layoutPages();
406  curPage = qBound(1, curPage, pages.count());
407  if (fitting)
408  _q_fit();
409  emit q->previewChanged();
410 }
411 
413 {
414  if (pageNumber < 1 || pageNumber > pages.count())
415  return;
416 
417  int lastPage = curPage;
418  curPage = pageNumber;
419 
420  if (lastPage != curPage && lastPage > 0 && lastPage <= pages.count()) {
421  if (zoomMode != QPrintPreviewWidget::FitInView) {
422  QScrollBar *hsc = graphicsView->horizontalScrollBar();
423  QScrollBar *vsc = graphicsView->verticalScrollBar();
424  QPointF pt = graphicsView->transform().map(pages.at(curPage-1)->pos());
425  vsc->setValue(int(pt.y()) - 10);
426  hsc->setValue(int(pt.x()) - 10);
427  } else {
428  graphicsView->centerOn(pages.at(curPage-1));
429  }
430  }
431 }
432 
434 {
435  zoomFactor *= zoom;
436  graphicsView->scale(zoom, zoom);
437 }
438 
440 {
442  zoomFactor = _zoomFactor;
443  graphicsView->resetTransform();
444  int dpi_y = q->logicalDpiY();
445  int printer_dpi_y = printer->logicalDpiY();
446  graphicsView->scale(zoomFactor*(dpi_y/float(printer_dpi_y)),
447  zoomFactor*(dpi_y/float(printer_dpi_y)));
448 }
449 
451 
533 QPrintPreviewWidget::QPrintPreviewWidget(QPrinter *printer, QWidget *parent, Qt::WindowFlags flags)
534  : QWidget(*new QPrintPreviewWidgetPrivate, parent, flags)
535 {
537  d->printer = printer;
538  d->ownPrinter = false;
539  d->init();
540 }
541 
553  : QWidget(*new QPrintPreviewWidgetPrivate, parent, flags)
554 {
556  d->printer = new QPrinter;
557  d->ownPrinter = true;
558  d->init();
559 }
560 
561 
566 {
568  if (d->ownPrinter)
569  delete d->printer;
570 }
571 
576 {
577  Q_D(const QPrintPreviewWidget);
578  return d->viewMode;
579 }
580 
586 {
588  d->viewMode = mode;
589  d->layoutPages();
590  if (d->viewMode == AllPagesView) {
591  d->graphicsView->fitInView(d->scene->itemsBoundingRect(), Qt::KeepAspectRatio);
592  d->fitting = false;
594  d->zoomFactor = d->graphicsView->transform().m11() * (float(d->printer->logicalDpiY()) / logicalDpiY());
596  } else {
597  d->fitting = true;
598  d->_q_fit();
599  }
600 }
601 
607 {
608  Q_D(const QPrintPreviewWidget);
609  return d->printer->orientation();
610 }
611 
617 {
619  d->printer->setOrientation(orientation);
620  d->generatePreview();
621 }
622 
627 {
629  // ### make use of the generated pages
630  emit paintRequested(d->printer);
631 }
632 
638 {
640  d->fitting = false;
642  d->zoom(factor);
643 }
644 
650 {
652  d->fitting = false;
654  d->zoom(1/factor);
655 }
656 
661 {
662  Q_D(const QPrintPreviewWidget);
663  return d->zoomFactor;
664 }
665 
674 {
676  d->fitting = false;
678  d->setZoomFactor(factor);
679 }
680 
690 {
691  Q_D(const QPrintPreviewWidget);
692  return d->pages.size();
693 }
694 
703 {
704  Q_D(const QPrintPreviewWidget);
705  return d->pages.size();
706 }
707 
712 {
713  Q_D(const QPrintPreviewWidget);
714  return d->curPage;
715 }
716 
722 {
724  d->setCurrentPage(page);
725 }
726 
732 {
734 }
735 
741 {
743 }
744 
751 {
753  d->zoomMode = zoomMode;
754  if (d->zoomMode == FitInView || d->zoomMode == FitToWidth) {
755  d->fitting = true;
756  d->_q_fit(true);
757  } else {
758  d->fitting = false;
759  }
760 }
761 
768 {
769  Q_D(const QPrintPreviewWidget);
770  return d->zoomMode;
771 }
772 
778 {
780 }
781 
787 {
789 }
790 
796 {
798 }
799 
805 {
807 }
808 
814 {
816 }
817 
818 
824 {
826  d->initialized = true;
827  d->generatePreview();
828  d->graphicsView->updateGeometry();
829 }
830 
834 {
836  if (visible && !d->initialized)
837  updatePreview();
838  QWidget::setVisible(visible);
839 }
840 
861 
862 #include "moc_qprintpreviewwidget.cpp"
863 #include "qprintpreviewwidget.moc"
864 
865 #endif // QT_NO_PRINTPREVIEWWIDGET
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
void moveTop(qreal pos)
Moves the rectangle vertically, leaving the rectangle&#39;s top line at the given y coordinate.
Definition: qrect.h:691
void print()
Prints the preview to the printer associated with the preview.
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
qreal right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:527
void drawPath(const QPainterPath &path)
Draws the given painter path using the current pen for outline and the current brush for filling...
Definition: qpainter.cpp:3502
PaperSize paperSize(QPrinter::PaperSize paperSize)
Definition: qpdf.cpp:905
double qreal
Definition: qglobal.h:1193
void setColorAt(qreal pos, const QColor &color)
Creates a stop point at the given position with the given color.
Definition: qbrush.cpp:1475
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QPointer< QWidget > widget
void setZoomMode(ZoomMode zoomMode)
Sets the zoom mode to zoomMode.
ViewMode viewMode() const
Returns the current view mode.
void setLeft(qreal pos)
Sets the left edge of the rectangle to the given x coordinate.
Definition: qrect.h:670
int qCeil(qreal v)
Definition: qmath.h:63
QPrintPreviewWidget::ZoomMode zoomMode
int logicalDpiY() const
Definition: qpaintdevice.h:96
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
void _q_fit(bool doFitting=false)
void zoomOut(qreal zoom=1.1)
Zooms the current view out by factor.
int qFloor(qreal v)
Definition: qmath.h:73
virtual QRectF boundingRect() const =0
This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be ...
void setClipRect(const QRectF &, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip region to the given rectangle using the given clip operation...
Definition: qpainter.cpp:2801
QList< const QPicture * > pictures
#define SLOT(a)
Definition: qobjectdefs.h:226
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
void setSinglePageViewMode()
This is a convenience function and is the same as calling {setViewMode(QPrintPreviewWidget::SinglePag...
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
Orientation
This enum type (not to be confused with Orientation) is used to specify each page&#39;s orientation...
Definition: qprinter.h:78
QPrintPreviewWidget::ViewMode viewMode
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
The QRadialGradient class is used in combination with QBrush to specify a radial gradient brush...
Definition: qbrush.h:297
#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 QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
void setRight(qreal pos)
Sets the right edge of the rectangle to the given x coordinate.
Definition: qrect.h:672
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
ViewMode
This enum is used to describe the view mode of the preview widget.
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
#define Q_Q(Class)
Definition: qglobal.h:2483
static const QRectF boundingRect(const QPointF *points, int pointCount)
void setViewMode(ViewMode viewMode)
Sets the view mode to mode.
#define SIGNAL(a)
Definition: qobjectdefs.h:227
The QScrollBar widget provides a vertical or horizontal scroll bar.
Definition: qscrollbar.h:59
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void fitInView()
This is a convenience function and is the same as calling {setZoomMode(QPrintPreviewWidget::FitInView...
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void updatePreview()
This function updates the preview, which causes the paintRequested() signal to be emitted...
bool visible
whether the widget is visible
Definition: qwidget.h:191
void drawPicture(const QPointF &p, const QPicture &picture)
Replays the given picture at the given point.
Definition: qpainter.cpp:7282
void setCacheMode(CacheMode mode, const QSize &cacheSize=QSize())
Sets the item&#39;s cache mode to mode.
void resizeEvent(QResizeEvent *event)
Reimplemented Function
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
static bool init
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
ZoomMode zoomMode() const
Returns the current zoom mode.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
const char * layout
void setVisible(bool visible)
Reimplemented Function
The QResizeEvent class contains event parameters for resize events.
Definition: qevent.h:349
void setPortraitOrientation()
This is a convenience function and is the same as calling {setOrientation(QPrinter::Portrait)}.
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
QPrinter::Orientation orientation() const
Returns the current orientation of the preview.
void showEvent(QShowEvent *event)
Reimplemented Function
void setFacingPagesViewMode()
This is a convenience function and is the same as calling {setViewMode(QPrintPreviewWidget::FacingPag...
The QShowEvent class provides an event that is sent when a widget is shown.
Definition: qevent.h:380
void setCurrentPage(int pageNumber)
#define Q_OBJECT
Definition: qobjectdefs.h:157
virtual void setVisible(bool visible)
Definition: qwidget.cpp:7991
int pageCount() const
Returns the number of pages in the preview.
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
void setOrientation(QPrinter::Orientation orientation)
Sets the current orientation to orientation.
The QPrintPreviewWidget class provides a widget for previewing page layouts for printer output...
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
qreal zoomFactor() const
Returns the zoom factor of the view.
void fitToWidth()
This is a convenience function and is the same as calling {setZoomMode(QPrintPreviewWidget::FitToWidt...
void setZoomFactor(qreal zoomFactor)
The QLinearGradient class is used in combination with QBrush to specify a linear gradient brush...
Definition: qbrush.h:280
void zoomIn(qreal zoom=1.1)
Zooms the current view in by factor.
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
~QPrintPreviewWidget()
Destroys the QPrintPreviewWidget.
void setLandscapeOrientation()
This is a convenience function and is the same as calling {setOrientation(QPrinter::Landscape)}.
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
void setBrush(const QBrush &brush)
Sets the painter&#39;s brush to the given brush.
Definition: qpainter.cpp:4171
void setCurrentPage(int pageNumber)
Sets the current page in the preview.
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
void setZoomFactor(qreal zoomFactor)
Sets the zoom factor of the view to factor.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
void previewChanged()
This signal is emitted whenever the preview widget has changed some internal state, such as the orientation.
void drawRect(const QRectF &rect)
Draws the current rectangle with the current pen and brush.
Definition: qpainter.h:650
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
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
QList< QGraphicsItem * > pages
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)=0
This function, which is usually called by QGraphicsView, paints the contents of an item in local coor...
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void paintRequested(QPrinter *printer)
This signal is emitted when the preview widget needs to generate a set of preview pages...
QTransform & scale(qreal sx, qreal sy)
Scales the coordinate system by sx horizontally and sy vertically, and returns a reference to the mat...
Definition: qtransform.cpp:485
The QVBoxLayout class lines up widgets vertically.
Definition: qboxlayout.h:149
QRectF exposedRect
the exposed rectangle, in item coordinates
Definition: qstyleoption.h:873
QPrintPreviewWidget(QPrinter *printer, QWidget *parent=0, Qt::WindowFlags flags=0)
Constructs a QPrintPreviewWidget based on printer and with parent as the parent widget.
#define signals
Definition: qobjectdefs.h:69
QT_DEPRECATED int numPages() const
Returns the number of pages in the preview.
The QPicture class is a paint device that records and replays QPainter commands.
Definition: qpicture.h:58
void setAllPagesViewMode()
This is a convenience function and is the same as calling {setViewMode(QPrintPreviewWidget::AllPagesV...
int currentPage() const
Returns the currently viewed page in the preview.
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem...
Definition: qstyleoption.h:867
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
qreal qSqrt(qreal v)
Definition: qmath.h:205
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
ZoomMode
This enum is used to describe zoom mode of the preview widget.
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
static int area(const QSize &s)
Definition: qicon.cpp:155