Qt 4.8
Public Functions | Public Variables | List of all members
QPrintPreviewWidgetPrivate Class Reference
Inheritance diagram for QPrintPreviewWidgetPrivate:
QWidgetPrivate QObjectPrivate QObjectData

Public Functions

void _q_fit (bool doFitting=false)
 
void _q_updateCurrentPage ()
 
int calcCurrentPage ()
 
void generatePreview ()
 
void init ()
 
void layoutPages ()
 
void populateScene ()
 
 QPrintPreviewWidgetPrivate ()
 
void setCurrentPage (int pageNumber)
 
void setZoomFactor (qreal zoomFactor)
 
void zoom (qreal zoom)
 
- Public Functions inherited from QWidgetPrivate
void _q_showIfNotHidden ()
 
virtual void aboutToDestroy ()
 
void activateChildLayoutsRecursively ()
 
QSize adjustedSize () const
 
void adjustQuitOnCloseAttribute ()
 
QInputContextassignedInputContext () const
 
QPainterbeginSharedPainter ()
 
QWidgetchildAt_helper (const QPoint &, bool) const
 
QWidgetchildAtRecursiveHelper (const QPoint &p, bool, bool includeFrame=false) const
 
QRect clipRect () const
 
QRegion clipRegion () const
 
void clipToEffectiveMask (QRegion &region) const
 
bool close_helper (CloseMode mode)
 
void create_sys (WId window, bool initializeWindow, bool destroyOldWindow)
 
QWindowSurfacecreateDefaultWindowSurface ()
 
QWindowSurfacecreateDefaultWindowSurface_sys ()
 
void createExtra ()
 Creates the widget extra data. More...
 
void createRecursively ()
 
void createSysExtra ()
 
void createTLExtra ()
 
void createTLSysExtra ()
 
void createWinId (WId id=0)
 
void deactivateWidgetCleanup ()
 
void deleteExtra ()
 Deletes the widget extra data. More...
 
void deleteSysExtra ()
 
void deleteTLSysExtra ()
 
void drawWidget (QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, int flags, QPainter *sharedPainter=0, QWidgetBackingStore *backingStore=0)
 
QWidgeteffectiveFocusWidget ()
 
QRect effectiveRectFor (const QRect &rect) const
 
bool endSharedPainter ()
 
void enforceNativeChildren ()
 
QWExtraextraData () const
 
QRect frameStrut () const
 
void getLayoutItemMargins (int *left, int *top, int *right, int *bottom) const
 
const QRegiongetOpaqueChildren () const
 
void handleSoftwareInputPanel (Qt::MouseButton button, bool clickCausedFocus)
 
virtual bool hasHeightForWidth () const
 
void hide_helper ()
 
void hide_sys ()
 Platform-specific part of QWidget::hide(). More...
 
void hideChildren (bool spontaneous)
 
void inheritStyle ()
 
void init (QWidget *desktopWidget, Qt::WindowFlags f)
 
QInputContextinputContext () const
 
void invalidateBuffer (const QRegion &)
 Invalidates the rgn (in widget's coordinates) of the backing store, i.e. More...
 
void invalidateBuffer (const QRect &)
 This function is equivalent to calling invalidateBuffer(QRegion(rect), ...), but is more efficient as it eliminates QRegion operations/allocations and can use the rect more precisely for additional cut-offs. More...
 
void invalidateBuffer_resizeHelper (const QPoint &oldPos, const QSize &oldSize)
 Invalidates the buffer when the widget is resized. More...
 
void invalidateGraphicsEffectsRecursively ()
 
bool isAboutToShow () const
 
bool isBackgroundInherited () const
 
bool isOverlapped (const QRect &) const
 
void lower_sys ()
 
QPoint mapFromGlobal (const QPoint &pos) const
 
QPoint mapToGlobal (const QPoint &pos) const
 
QWidgetBackingStoremaybeBackingStore () const
 
QTLWExtramaybeTopData () const
 
void moveRect (const QRect &, int dx, int dy)
 
bool nativeChildrenForced () const
 
QFont naturalWidgetFont (uint inheritedMask) const
 
QPalette naturalWidgetPalette (uint inheritedMask) const
 Returns the palette that the widget w inherits from its ancestors and QApplication::palette. More...
 
void paintBackground (QPainter *, const QRegion &, int flags=DrawAsRoot) const
 
bool paintOnScreen () const
 
void paintSiblingsRecursive (QPaintDevice *pdev, const QObjectList &children, int index, const QRegion &rgn, const QPoint &offset, int flags, QPainter *sharedPainter, QWidgetBackingStore *backingStore)
 
bool pointInsideRectAndMask (const QPoint &) const
 
QRegion prepareToRender (const QRegion &region, QWidget::RenderFlags renderFlags)
 
void propagatePaletteChange ()
 Propagate this widget's palette to all children, except style sheet widgets, and windows that don't enable window propagation (palettes don't normally propagate to windows). More...
 
 QWidgetPrivate (int version=QObjectPrivateVersion)
 
void raise_sys ()
 
QPaintDeviceredirected (QPoint *offset) const
 
void registerDropSite (bool)
 
void render (QPaintDevice *target, const QPoint &targetOffset, const QRegion &sourceRegion, QWidget::RenderFlags renderFlags, bool readyToRender)
 
void render_helper (QPainter *painter, const QPoint &targetOffset, const QRegion &sourceRegion, QWidget::RenderFlags renderFlags)
 
void repaint_sys (const QRegion &rgn)
 
void reparentFocusWidgets (QWidget *oldtlw)
 
void resolveFont ()
 Determine which font is implicitly imposed on this widget by its ancestors and QApplication::font, resolve this against its own font (attributes from the implicit font are copied over). More...
 
void resolveLayoutDirection ()
 
void resolveLocale ()
 
void resolvePalette ()
 Determine which palette is inherited from this widget's ancestors and QApplication::palette, resolve this against this widget's palette (attributes from the inherited palette are copied over this widget's palette). More...
 
void restoreRedirected ()
 
void scroll_sys (int dx, int dy)
 
void scroll_sys (int dx, int dy, const QRect &r)
 
void scrollChildren (int dx, int dy)
 
void scrollRect (const QRect &, int dx, int dy)
 
void sendPendingMoveAndResizeEvents (bool recursive=false, bool disableUpdates=false)
 
void sendStartupMessage (const char *message) const
 Platform-specific part of QWidget::show(). More...
 
void setConstraints_sys ()
 
void setCursor_sys (const QCursor &cursor)
 
void setDirtyOpaqueRegion ()
 
void setEnabled_helper (bool)
 
void setFocus_sys ()
 
void setFont_helper (const QFont &font)
 
void setGeometry_sys (int, int, int, int, bool)
 
void setLayoutDirection_helper (Qt::LayoutDirection)
 
void setLayoutItemMargins (int left, int top, int right, int bottom)
 
void setLayoutItemMargins (QStyle::SubElement element, const QStyleOption *opt=0)
 
void setLocale_helper (const QLocale &l, bool forceUpdate=false)
 
void setMask_sys (const QRegion &)
 
bool setMaximumSize_helper (int &maxw, int &maxh)
 
bool setMinimumSize_helper (int &minw, int &minh)
 
void setModal_sys ()
 
void setNetWmWindowTypes ()
 
void setOpaque (bool opaque)
 
void setPalette_helper (const QPalette &)
 
void setParent_sys (QWidget *parent, Qt::WindowFlags)
 
void setRedirected (QPaintDevice *replacement, const QPoint &offset)
 
void setSharedPainter (QPainter *painter)
 
void setStyle_helper (QStyle *newStyle, bool propagate, bool metalHack=false)
 
void setUpdatesEnabled_helper (bool)
 
void setWindowFilePath_helper (const QString &filePath)
 
void setWindowIcon_helper ()
 
void setWindowIcon_sys (bool forceReset=false)
 
void setWindowIconText_helper (const QString &cap)
 
void setWindowIconText_sys (const QString &cap)
 
void setWindowOpacity_sys (qreal opacity)
 
void setWindowRole ()
 
void setWindowTitle_helper (const QString &cap)
 
void setWindowTitle_sys (const QString &cap)
 
void setWinId (WId)
 
QPaintersharedPainter () const
 
void show_helper ()
 
void show_recursive ()
 Makes the widget visible in the isVisible() meaning of the word. More...
 
void show_sys ()
 Platform-specific part of QWidget::show(). More...
 
void showChildren (bool spontaneous)
 
void stackUnder_sys (QWidget *)
 
void subtractOpaqueChildren (QRegion &rgn, const QRect &clipRect) const
 
void subtractOpaqueSiblings (QRegion &source, bool *hasDirtySiblingsAbove=0, bool alsoNonOpaque=false) const
 
void syncBackingStore ()
 
void syncBackingStore (const QRegion &region)
 
QTLWExtratopData () const
 
void unsetCursor_sys ()
 
void updateFont (const QFont &)
 Assign font to this widget, and propagate it to all children, except style sheet widgets (handled differently) and windows that don't enable window propagation. More...
 
void updateFrameStrut ()
 Computes the frame rectangle when needed. More...
 
void updateGeometry_helper (bool forceUpdate)
 
void updateIsOpaque ()
 
void updateIsTranslucent ()
 
void updateSystemBackground ()
 
void updateX11AcceptFocus ()
 
void x11UpdateIsOpaque ()
 
 ~QWidgetPrivate ()
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 

Public Variables

int curPage
 
bool fitting
 
GraphicsView * graphicsView
 
bool initialized
 
bool ownPrinter
 
QList< QGraphicsItem * > pages
 
QList< const QPicture * > pictures
 
QPrinterprinter
 
QGraphicsScenescene
 
QPrintPreviewWidget::ViewMode viewMode
 
qreal zoomFactor
 
QPrintPreviewWidget::ZoomMode zoomMode
 
- Public Variables inherited from QWidgetPrivate
QString accessibleDescription
 
QString accessibleName
 
QList< QAction * > actions
 
QPalette::ColorRole bg_role: 8
 
signed char bottomLayoutItemMargin
 
short bottommargin
 
QWidgetData data
 
QRegion dirty
 
uint dirtyOpaqueChildren: 1
 
QWExtraextra
 
QPaintEngineextraPaintEngine
 
QPalette::ColorRole fg_role: 8
 
QWidgetfocus_child
 
QWidgetfocus_next
 
QWidgetfocus_prev
 
QMap< Qt::GestureType, Qt::GestureFlags > gestureContext
 
QGraphicsEffectgraphicsEffect
 
Qt::HANDLE hd
 
uint high_attributes [4]
 
QPointer< QInputContextic
 
Qt::InputMethodHints imHints
 
uint inDirtyList: 1
 
uint inheritedFontResolveMask
 
uint inheritedPaletteResolveMask
 
uint inheritsInputMethodHints: 1
 
uint inSetParent: 1
 
uint isGLWidget: 1
 
uint isMoved: 1
 
uint isOpaque: 1
 
uint isScrolled: 1
 
QLayoutlayout
 
signed char leftLayoutItemMargin
 
short leftmargin
 
QLocale locale
 
QRegionneedsFlush
 
QRegion opaqueChildren
 
Qt::HANDLE picture
 
const QMetaObjectpolished
 
QPaintDeviceredirectDev
 
QPoint redirectOffset
 
signed char rightLayoutItemMargin
 
short rightmargin
 
QSizePolicy size_policy
 
QString statusTip
 
QString toolTip
 
signed char topLayoutItemMargin
 
short topmargin
 
uint usesDoubleBufferedGLContext: 1
 
QString whatsThis
 
QWidgetItemV2widgetItem
 
QX11Info xinfo
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 

Additional Inherited Members

- Public Types inherited from QWidgetPrivate
enum  CloseMode { CloseNoEvent, CloseWithEvent, CloseWithSpontaneousEvent }
 
enum  Direction { DirectionNorth = 0x01, DirectionEast = 0x10, DirectionSouth = 0x02, DirectionWest = 0x20 }
 
enum  DrawWidgetFlags {
  DrawAsRoot = 0x01, DrawPaintOnScreen = 0x02, DrawRecursive = 0x04, DrawInvisible = 0x08,
  DontSubtractOpaqueChildren = 0x10, DontSetCompositionMode = 0x20, DontDrawOpaqueChildren = 0x40, DontDrawNativeChildren = 0x80
}
 
- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 
- Static Public Functions inherited from QWidgetPrivate
static void adjustFlags (Qt::WindowFlags &flags, QWidget *w=0)
 
static QGraphicsProxyWidgetnearestGraphicsProxyWidget (const QWidget *origin)
 Finds the nearest widget embedded in a graphics proxy widget along the chain formed by this widget and its ancestors. More...
 
static int pointToRect (const QPoint &p, const QRect &r)
 
static QRect screenGeometry (const QWidget *widget)
 
- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 
- Static Public Variables inherited from QWidgetPrivate
static QWidgetSetallWidgets = 0
 
static int instanceCounter = 0
 
static QWidgetkeyboardGrabber = 0
 
static QWidgetMappermapper = 0
 
static int maxInstances = 0
 
static QWidgetmouseGrabber = 0
 

Detailed Description

Definition at line 178 of file qprintpreviewwidget.cpp.

Constructors and Destructors

◆ QPrintPreviewWidgetPrivate()

QPrintPreviewWidgetPrivate::QPrintPreviewWidgetPrivate ( )
inline

Functions

◆ _q_fit()

void QPrintPreviewWidgetPrivate::_q_fit ( bool  doFitting = false)

Definition at line 218 of file qprintpreviewwidget.cpp.

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();
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();
246  // fit two pages
247  if (curPage % 2)
248  target.setLeft(target.left() - target.width());
249  else
250  target.setRight(target.right() + target.width());
252  target = scene->itemsBoundingRect();
253  }
254 
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);
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 }
void moveTop(qreal pos)
Moves the rectangle vertically, leaving the rectangle&#39;s top line at the given y coordinate.
Definition: qrect.h:691
qreal right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:527
double qreal
Definition: qglobal.h:1193
void setLeft(qreal pos)
Sets the left edge of the rectangle to the given x coordinate.
Definition: qrect.h:670
QPrintPreviewWidget::ZoomMode zoomMode
int logicalDpiY() const
Definition: qpaintdevice.h:96
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
QPrintPreviewWidget::ViewMode viewMode
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
void setRight(qreal pos)
Sets the right edge of the rectangle to the given x coordinate.
Definition: qrect.h:672
#define Q_Q(Class)
Definition: qglobal.h:2483
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
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
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
The QPrintPreviewWidget class provides a widget for previewing page layouts for printer output...
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QList< QGraphicsItem * > pages
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
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
QRectF sceneBoundingRect() const
Returns the bounding rect of this item in scene coordinates, by combining sceneTransform() with bound...
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
QRectF itemsBoundingRect() const
Calculates and returns the bounding rect of all items on the scene.
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

◆ _q_updateCurrentPage()

void QPrintPreviewWidgetPrivate::_q_updateCurrentPage ( )

Definition at line 278 of file qprintpreviewwidget.cpp.

279 {
281 
283  return;
284 
285  int newPage = calcCurrentPage();
286  if (newPage != curPage) {
287  curPage = newPage;
288  emit q->previewChanged();
289  }
290 }
QPrintPreviewWidget::ViewMode viewMode
#define Q_Q(Class)
Definition: qglobal.h:2483
#define emit
Definition: qobjectdefs.h:76
The QPrintPreviewWidget class provides a widget for previewing page layouts for printer output...

◆ calcCurrentPage()

int QPrintPreviewWidgetPrivate::calcCurrentPage ( )

Definition at line 292 of file qprintpreviewwidget.cpp.

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 }
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
static const QRectF boundingRect(const QPointF *points, int pointCount)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
static int area(const QSize &s)
Definition: qicon.cpp:155

◆ generatePreview()

void QPrintPreviewWidgetPrivate::generatePreview ( )

Definition at line 391 of file qprintpreviewwidget.cpp.

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 }
void _q_fit(bool doFitting=false)
QList< const QPicture * > pictures
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
#define Q_Q(Class)
Definition: qglobal.h:2483
#define emit
Definition: qobjectdefs.h:76
The QPrintPreviewWidget class provides a widget for previewing page layouts for printer output...
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
QList< QGraphicsItem * > pages

◆ init()

void QPrintPreviewWidgetPrivate::init ( )

Definition at line 312 of file qprintpreviewwidget.cpp.

313 {
315 
316  graphicsView = new GraphicsView;
317  graphicsView->setInteractive(false);
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 
326  graphicsView->setScene(scene);
327 
329  q->setLayout(layout);
330  layout->setContentsMargins(0, 0, 0, 0);
331  layout->addWidget(graphicsView);
332 }
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
void _q_fit(bool doFitting=false)
QLayout * layout
Definition: qwidget_p.h:704
#define SLOT(a)
Definition: qobjectdefs.h:226
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...
#define Q_Q(Class)
Definition: qglobal.h:2483
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void setBackgroundBrush(const QBrush &brush)
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
The QPrintPreviewWidget class provides a widget for previewing page layouts for printer output...
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
The QVBoxLayout class lines up widgets vertically.
Definition: qboxlayout.h:149

◆ layoutPages()

void QPrintPreviewWidgetPrivate::layoutPages ( )

Definition at line 353 of file qprintpreviewwidget.cpp.

354 {
355  int numPages = pages.count();
356  if (numPages < 1)
357  return;
358 
359  int numPagePlaces = numPages;
360  int cols = 1; // singleMode and default
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  }
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  }
389 }
double qreal
Definition: qglobal.h:1193
int qCeil(qreal v)
Definition: qmath.h:63
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 ...
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QPrintPreviewWidget::ViewMode viewMode
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
void setPos(const QPointF &pos)
Sets the position of the item to pos, which is in parent coordinates.
Orientation orientation() const
Returns the orientation setting.
Definition: qprinter.cpp:1098
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
QList< QGraphicsItem * > pages
void setSceneRect(const QRectF &rect)
qreal qSqrt(qreal v)
Definition: qmath.h:205
QRectF itemsBoundingRect() const
Calculates and returns the bounding rect of all items on the scene.

◆ populateScene()

void QPrintPreviewWidgetPrivate::populateScene ( )

Definition at line 334 of file qprintpreviewwidget.cpp.

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();
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 }
PaperSize paperSize(QPrinter::PaperSize paperSize)
Definition: qpdf.cpp:905
QRect pageRect() const
Returns the page&#39;s rectangle; this is usually smaller than the paperRect() since the page normally ha...
Definition: qprinter.cpp:1800
QList< const QPicture * > pictures
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
void addItem(QGraphicsItem *item)
Adds or moves the item and all its childen to this scene.
QRect paperRect() const
Returns the paper&#39;s rectangle; this is usually larger than the pageRect().
Definition: qprinter.cpp:1814
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
void removeItem(QGraphicsItem *item)
Removes the item item and all its children from the scene.
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void clear()
Removes all items from the list.
Definition: qlist.h:764
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QList< QGraphicsItem * > pages
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319

◆ setCurrentPage()

void QPrintPreviewWidgetPrivate::setCurrentPage ( int  pageNumber)

Definition at line 412 of file qprintpreviewwidget.cpp.

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()) {
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 }
QPrintPreviewWidget::ZoomMode zoomMode
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QPointF pos() const
Returns the position of the item in parent coordinates.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
The QScrollBar widget provides a vertical or horizontal scroll bar.
Definition: qscrollbar.h:59
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
QList< QGraphicsItem * > pages

◆ setZoomFactor()

void QPrintPreviewWidgetPrivate::setZoomFactor ( qreal  zoomFactor)

Definition at line 439 of file qprintpreviewwidget.cpp.

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 }
int logicalDpiY() const
Definition: qpaintdevice.h:96
#define Q_Q(Class)
Definition: qglobal.h:2483
The QPrintPreviewWidget class provides a widget for previewing page layouts for printer output...

◆ zoom()

void QPrintPreviewWidgetPrivate::zoom ( qreal  zoom)

Definition at line 433 of file qprintpreviewwidget.cpp.

Properties

◆ curPage

int QPrintPreviewWidgetPrivate::curPage

Definition at line 205 of file qprintpreviewwidget.cpp.

◆ fitting

bool QPrintPreviewWidgetPrivate::fitting

Definition at line 215 of file qprintpreviewwidget.cpp.

◆ graphicsView

GraphicsView* QPrintPreviewWidgetPrivate::graphicsView

Definition at line 202 of file qprintpreviewwidget.cpp.

◆ initialized

bool QPrintPreviewWidgetPrivate::initialized

Definition at line 214 of file qprintpreviewwidget.cpp.

◆ ownPrinter

bool QPrintPreviewWidgetPrivate::ownPrinter

Definition at line 212 of file qprintpreviewwidget.cpp.

◆ pages

QList<QGraphicsItem *> QPrintPreviewWidgetPrivate::pages

Definition at line 207 of file qprintpreviewwidget.cpp.

◆ pictures

QList<const QPicture *> QPrintPreviewWidgetPrivate::pictures

Definition at line 206 of file qprintpreviewwidget.cpp.

◆ printer

QPrinter* QPrintPreviewWidgetPrivate::printer

Definition at line 213 of file qprintpreviewwidget.cpp.

◆ scene

QGraphicsScene* QPrintPreviewWidgetPrivate::scene

Definition at line 203 of file qprintpreviewwidget.cpp.

◆ viewMode

QPrintPreviewWidget::ViewMode QPrintPreviewWidgetPrivate::viewMode

Definition at line 209 of file qprintpreviewwidget.cpp.

◆ zoomFactor

qreal QPrintPreviewWidgetPrivate::zoomFactor

Definition at line 211 of file qprintpreviewwidget.cpp.

◆ zoomMode

QPrintPreviewWidget::ZoomMode QPrintPreviewWidgetPrivate::zoomMode

Definition at line 210 of file qprintpreviewwidget.cpp.


The documentation for this class was generated from the following file: