| Line | Source Code | Coverage |
|---|
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | namespace { | - |
| 8 | class PageItem : public QGraphicsItem | - |
| 9 | { | - |
| 10 | public: | - |
| 11 | PageItem(int _pageNum, const QPicture* _pagePicture, QSize _paperSize, QRect _pageRect) | - |
| 12 | : pageNum(_pageNum), pagePicture(_pagePicture), | - |
| 13 | paperSize(_paperSize), pageRect(_pageRect) | - |
| 14 | { | - |
| 15 | qreal border = qMax(paperSize.height(), paperSize.width()) / 25; | - |
| 16 | brect = QRectF(QPointF(-border, -border), | - |
| 17 | QSizeF(paperSize)+QSizeF(2*border, 2*border)); | - |
| 18 | setCacheMode(DeviceCoordinateCache); | - |
| 19 | } | 0 |
| 20 | | - |
| 21 | inline QRectF boundingRect() const | - |
| 22 | { return brect; } never executed: return brect; | 0 |
| 23 | | - |
| 24 | inline int pageNumber() const | - |
| 25 | { return pageNum; } never executed: return pageNum; | 0 |
| 26 | | - |
| 27 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *item, QWidget *widget); | - |
| 28 | | - |
| 29 | private: | - |
| 30 | int pageNum; | - |
| 31 | const QPicture* pagePicture; | - |
| 32 | QSize paperSize; | - |
| 33 | QRect pageRect; | - |
| 34 | QRectF brect; | - |
| 35 | }; | - |
| 36 | | - |
| 37 | void PageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | - |
| 38 | { | - |
| 39 | (void)widget;; | - |
| 40 | QRectF paperRect(0,0, paperSize.width(), paperSize.height()); | - |
| 41 | | - |
| 42 | | - |
| 43 | painter->setClipRect(option->exposedRect); | - |
| 44 | qreal shWidth = paperRect.width()/100; | - |
| 45 | QRectF rshadow(paperRect.topRight() + QPointF(0, shWidth), | - |
| 46 | paperRect.bottomRight() + QPointF(shWidth, 0)); | - |
| 47 | QLinearGradient rgrad(rshadow.topLeft(), rshadow.topRight()); | - |
| 48 | rgrad.setColorAt(0.0, QColor(0,0,0,255)); | - |
| 49 | rgrad.setColorAt(1.0, QColor(0,0,0,0)); | - |
| 50 | painter->fillRect(rshadow, QBrush(rgrad)); | - |
| 51 | QRectF bshadow(paperRect.bottomLeft() + QPointF(shWidth, 0), | - |
| 52 | paperRect.bottomRight() + QPointF(0, shWidth)); | - |
| 53 | QLinearGradient bgrad(bshadow.topLeft(), bshadow.bottomLeft()); | - |
| 54 | bgrad.setColorAt(0.0, QColor(0,0,0,255)); | - |
| 55 | bgrad.setColorAt(1.0, QColor(0,0,0,0)); | - |
| 56 | painter->fillRect(bshadow, QBrush(bgrad)); | - |
| 57 | QRectF cshadow(paperRect.bottomRight(), | - |
| 58 | paperRect.bottomRight() + QPointF(shWidth, shWidth)); | - |
| 59 | QRadialGradient cgrad(cshadow.topLeft(), shWidth, cshadow.topLeft()); | - |
| 60 | cgrad.setColorAt(0.0, QColor(0,0,0,255)); | - |
| 61 | cgrad.setColorAt(1.0, QColor(0,0,0,0)); | - |
| 62 | painter->fillRect(cshadow, QBrush(cgrad)); | - |
| 63 | | - |
| 64 | painter->setClipRect(paperRect & option->exposedRect); | - |
| 65 | painter->fillRect(paperRect, Qt::white); | - |
| 66 | if (!pagePicture) never evaluated: !pagePicture | 0 |
| 67 | return; | 0 |
| 68 | painter->drawPicture(pageRect.topLeft(), *pagePicture); | - |
| 69 | | - |
| 70 | | - |
| 71 | QPainterPath path; | - |
| 72 | path.addRect(paperRect); | - |
| 73 | path.addRect(pageRect); | - |
| 74 | painter->setPen(QPen(Qt::NoPen)); | - |
| 75 | painter->setBrush(QColor(255, 255, 255, 180)); | - |
| 76 | painter->drawPath(path); | - |
| 77 | } | 0 |
| 78 | | - |
| 79 | class GraphicsView : public QGraphicsView | - |
| 80 | { | - |
| 81 | public: template <typename T> inline void qt_check_for_QOBJECT_macro(const T &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; } static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); static inline QString tr(const char *s, const char *c = 0, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = 0, int n = -1) { return staticMetaObject.tr(s, c, n); } virtual int qt_metacall(QMetaObject::Call, int, void **); private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); struct QPrivateSignal {}; | - |
| 82 | public: | - |
| 83 | GraphicsView(QWidget* parent = 0) | - |
| 84 | : QGraphicsView(parent) | - |
| 85 | { | - |
| 86 | | - |
| 87 | | - |
| 88 | | - |
| 89 | } | 0 |
| 90 | public: | - |
| 91 | void resized(); | - |
| 92 | | - |
| 93 | protected: | - |
| 94 | void resizeEvent(QResizeEvent* e) | - |
| 95 | { | - |
| 96 | QGraphicsView::resizeEvent(e); | - |
| 97 | resized(); | - |
| 98 | } | 0 |
| 99 | | - |
| 100 | void showEvent(QShowEvent* e) | - |
| 101 | { | - |
| 102 | QGraphicsView::showEvent(e); | - |
| 103 | resized(); | - |
| 104 | } | 0 |
| 105 | }; | - |
| 106 | | - |
| 107 | } | - |
| 108 | | - |
| 109 | class QPrintPreviewWidgetPrivate : public QWidgetPrivate | - |
| 110 | { | - |
| 111 | inline QPrintPreviewWidget* q_func() { return static_cast<QPrintPreviewWidget *>(q_ptr); } inline const QPrintPreviewWidget* q_func() const { return static_cast<const QPrintPreviewWidget *>(q_ptr); } friend class QPrintPreviewWidget; | - |
| 112 | public: | - |
| 113 | QPrintPreviewWidgetPrivate() | - |
| 114 | : scene(0), curPage(1), | - |
| 115 | viewMode(QPrintPreviewWidget::SinglePageView), | - |
| 116 | zoomMode(QPrintPreviewWidget::FitInView), | - |
| 117 | zoomFactor(1), initialized(false), fitting(true) | - |
| 118 | {} | 0 |
| 119 | | - |
| 120 | | - |
| 121 | void _q_fit(bool doFitting = false); | - |
| 122 | void _q_updateCurrentPage(); | - |
| 123 | | - |
| 124 | void init(); | - |
| 125 | void populateScene(); | - |
| 126 | void layoutPages(); | - |
| 127 | void generatePreview(); | - |
| 128 | void setCurrentPage(int pageNumber); | - |
| 129 | void zoom(qreal zoom); | - |
| 130 | void setZoomFactor(qreal zoomFactor); | - |
| 131 | int calcCurrentPage(); | - |
| 132 | | - |
| 133 | GraphicsView *graphicsView; | - |
| 134 | QGraphicsScene *scene; | - |
| 135 | | - |
| 136 | int curPage; | - |
| 137 | QList<const QPicture *> pictures; | - |
| 138 | QList<QGraphicsItem *> pages; | - |
| 139 | | - |
| 140 | QPrintPreviewWidget::ViewMode viewMode; | - |
| 141 | QPrintPreviewWidget::ZoomMode zoomMode; | - |
| 142 | qreal zoomFactor; | - |
| 143 | bool ownPrinter; | - |
| 144 | QPrinter* printer; | - |
| 145 | bool initialized; | - |
| 146 | bool fitting; | - |
| 147 | }; | - |
| 148 | | - |
| 149 | void QPrintPreviewWidgetPrivate::_q_fit(bool doFitting) | - |
| 150 | { | - |
| 151 | QPrintPreviewWidget * const q = q_func(); | - |
| 152 | | - |
| 153 | if (curPage < 1 || curPage > pages.count()) never evaluated: curPage < 1 never evaluated: curPage > pages.count() | 0 |
| 154 | return; | 0 |
| 155 | | - |
| 156 | if (!doFitting && !fitting) never evaluated: !doFitting never evaluated: !fitting | 0 |
| 157 | return; | 0 |
| 158 | | - |
| 159 | if (doFitting && fitting) { never evaluated: doFitting | 0 |
| 160 | QRect viewRect = graphicsView->viewport()->rect(); | - |
| 161 | if (zoomMode == QPrintPreviewWidget::FitInView) { never evaluated: zoomMode == QPrintPreviewWidget::FitInView | 0 |
| 162 | QList<QGraphicsItem*> containedItems = graphicsView->items(viewRect, Qt::ContainsItemBoundingRect); | - |
| 163 | for (QForeachContainer<__typeof__(containedItems)> _container_(containedItems); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QGraphicsItem* item = *_container_.i;; __extension__ ({--_container_.brk; break;})) { | - |
| 164 | PageItem* pg = static_cast<PageItem*>(item); | - |
| 165 | if (pg->pageNumber() == curPage) never evaluated: pg->pageNumber() == curPage | 0 |
| 166 | return; | 0 |
| 167 | } | 0 |
| 168 | } | 0 |
| 169 | | - |
| 170 | int newPage = calcCurrentPage(); | - |
| 171 | if (newPage != curPage) never evaluated: newPage != curPage | 0 |
| 172 | curPage = newPage; never executed: curPage = newPage; | 0 |
| 173 | } | 0 |
| 174 | | - |
| 175 | QRectF target = pages.at(curPage-1)->sceneBoundingRect(); | - |
| 176 | if (viewMode == QPrintPreviewWidget::FacingPagesView) { never evaluated: viewMode == QPrintPreviewWidget::FacingPagesView | 0 |
| 177 | | - |
| 178 | if (curPage % 2) never evaluated: curPage % 2 | 0 |
| 179 | target.setLeft(target.left() - target.width()); never executed: target.setLeft(target.left() - target.width()); | 0 |
| 180 | else | - |
| 181 | target.setRight(target.right() + target.width()); never executed: target.setRight(target.right() + target.width()); | 0 |
| 182 | } else if (viewMode == QPrintPreviewWidget::AllPagesView) { never evaluated: viewMode == QPrintPreviewWidget::AllPagesView | 0 |
| 183 | target = scene->itemsBoundingRect(); | - |
| 184 | } | 0 |
| 185 | | - |
| 186 | if (zoomMode == QPrintPreviewWidget::FitToWidth) { never evaluated: zoomMode == QPrintPreviewWidget::FitToWidth | 0 |
| 187 | QTransform t; | - |
| 188 | qreal scale = graphicsView->viewport()->width() / target.width(); | - |
| 189 | t.scale(scale, scale); | - |
| 190 | graphicsView->setTransform(t); | - |
| 191 | if (doFitting && fitting) { never evaluated: doFitting | 0 |
| 192 | QRectF viewSceneRect = graphicsView->viewportTransform().mapRect(graphicsView->viewport()->rect()); | - |
| 193 | viewSceneRect.moveTop(target.top()); | - |
| 194 | graphicsView->ensureVisible(viewSceneRect); | - |
| 195 | } | 0 |
| 196 | } else { | 0 |
| 197 | graphicsView->fitInView(target, Qt::KeepAspectRatio); | - |
| 198 | if (zoomMode == QPrintPreviewWidget::FitInView) { never evaluated: zoomMode == QPrintPreviewWidget::FitInView | 0 |
| 199 | int step = qRound(graphicsView->matrix().mapRect(target).height()); | - |
| 200 | graphicsView->verticalScrollBar()->setSingleStep(step); | - |
| 201 | graphicsView->verticalScrollBar()->setPageStep(step); | - |
| 202 | } | 0 |
| 203 | } | 0 |
| 204 | | - |
| 205 | zoomFactor = graphicsView->transform().m11() * (float(printer->logicalDpiY()) / q->logicalDpiY()); | - |
| 206 | q->previewChanged(); | - |
| 207 | } | 0 |
| 208 | | - |
| 209 | void QPrintPreviewWidgetPrivate::_q_updateCurrentPage() | - |
| 210 | { | - |
| 211 | QPrintPreviewWidget * const q = q_func(); | - |
| 212 | | - |
| 213 | if (viewMode == QPrintPreviewWidget::AllPagesView) never evaluated: viewMode == QPrintPreviewWidget::AllPagesView | 0 |
| 214 | return; | 0 |
| 215 | | - |
| 216 | int newPage = calcCurrentPage(); | - |
| 217 | if (newPage != curPage) { never evaluated: newPage != curPage | 0 |
| 218 | curPage = newPage; | - |
| 219 | q->previewChanged(); | - |
| 220 | } | 0 |
| 221 | } | 0 |
| 222 | | - |
| 223 | int QPrintPreviewWidgetPrivate::calcCurrentPage() | - |
| 224 | { | - |
| 225 | int maxArea = 0; | - |
| 226 | int newPage = curPage; | - |
| 227 | QRect viewRect = graphicsView->viewport()->rect(); | - |
| 228 | QList<QGraphicsItem*> items = graphicsView->items(viewRect); | - |
| 229 | for (int i=0; i<items.size(); ++i) { never evaluated: i<items.size() | 0 |
| 230 | PageItem* pg = static_cast<PageItem*>(items.at(i)); | - |
| 231 | QRect overlap = graphicsView->mapFromScene(pg->sceneBoundingRect()).boundingRect() & viewRect; | - |
| 232 | int area = overlap.width() * overlap.height(); | - |
| 233 | if (area > maxArea) { never evaluated: area > maxArea | 0 |
| 234 | maxArea = area; | - |
| 235 | newPage = pg->pageNumber(); | - |
| 236 | } else if (area == maxArea && pg->pageNumber() < newPage) { never evaluated: area == maxArea never evaluated: pg->pageNumber() < newPage | 0 |
| 237 | newPage = pg->pageNumber(); | - |
| 238 | } | 0 |
| 239 | } | - |
| 240 | return newPage; never executed: return newPage; | 0 |
| 241 | } | - |
| 242 | | - |
| 243 | void QPrintPreviewWidgetPrivate::init() | - |
| 244 | { | - |
| 245 | QPrintPreviewWidget * const q = q_func(); | - |
| 246 | | - |
| 247 | graphicsView = new GraphicsView; | - |
| 248 | graphicsView->setInteractive(false); | - |
| 249 | graphicsView->setDragMode(QGraphicsView::ScrollHandDrag); | - |
| 250 | graphicsView->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate); | - |
| 251 | QObject::connect(graphicsView->verticalScrollBar(), "2""valueChanged(int)", | - |
| 252 | q, "1""_q_updateCurrentPage()"); | - |
| 253 | QObject::connect(graphicsView, "2""resized()", q, "1""_q_fit()"); | - |
| 254 | | - |
| 255 | scene = new QGraphicsScene(graphicsView); | - |
| 256 | scene->setBackgroundBrush(Qt::gray); | - |
| 257 | graphicsView->setScene(scene); | - |
| 258 | | - |
| 259 | QVBoxLayout *layout = new QVBoxLayout; | - |
| 260 | q->setLayout(layout); | - |
| 261 | layout->setContentsMargins(0, 0, 0, 0); | - |
| 262 | layout->addWidget(graphicsView); | - |
| 263 | } | 0 |
| 264 | | - |
| 265 | void QPrintPreviewWidgetPrivate::populateScene() | - |
| 266 | { | - |
| 267 | | - |
| 268 | for (int i = 0; i < pages.size(); i++) never evaluated: i < pages.size() | 0 |
| 269 | scene->removeItem(pages.at(i)); never executed: scene->removeItem(pages.at(i)); | 0 |
| 270 | qDeleteAll(pages); | - |
| 271 | pages.clear(); | - |
| 272 | | - |
| 273 | int numPages = pictures.count(); | - |
| 274 | QSize paperSize = printer->paperRect().size(); | - |
| 275 | QRect pageRect = printer->pageRect(); | - |
| 276 | | - |
| 277 | for (int i = 0; i < numPages; i++) { never evaluated: i < numPages | 0 |
| 278 | PageItem* item = new PageItem(i+1, pictures.at(i), paperSize, pageRect); | - |
| 279 | scene->addItem(item); | - |
| 280 | pages.append(item); | - |
| 281 | } | 0 |
| 282 | } | 0 |
| 283 | | - |
| 284 | void QPrintPreviewWidgetPrivate::layoutPages() | - |
| 285 | { | - |
| 286 | int numPages = pages.count(); | - |
| 287 | if (numPages < 1) never evaluated: numPages < 1 | 0 |
| 288 | return; | 0 |
| 289 | | - |
| 290 | int numPagePlaces = numPages; | - |
| 291 | int cols = 1; | - |
| 292 | if (viewMode == QPrintPreviewWidget::AllPagesView) { never evaluated: viewMode == QPrintPreviewWidget::AllPagesView | 0 |
| 293 | if (printer->orientation() == QPrinter::Portrait) never evaluated: printer->orientation() == QPrinter::Portrait | 0 |
| 294 | cols = qCeil(qSqrt((float) numPages)); never executed: cols = qCeil(qSqrt((float) numPages)); | 0 |
| 295 | else | - |
| 296 | cols = qFloor(qSqrt((float) numPages)); never executed: cols = qFloor(qSqrt((float) numPages)); | 0 |
| 297 | cols += cols % 2; | - |
| 298 | } | 0 |
| 299 | else if (viewMode == QPrintPreviewWidget::FacingPagesView) { never evaluated: viewMode == QPrintPreviewWidget::FacingPagesView | 0 |
| 300 | cols = 2; | - |
| 301 | numPagePlaces += 1; | - |
| 302 | } | 0 |
| 303 | int rows = qCeil(qreal(numPagePlaces) / cols); | - |
| 304 | | - |
| 305 | qreal itemWidth = pages.at(0)->boundingRect().width(); | - |
| 306 | qreal itemHeight = pages.at(0)->boundingRect().height(); | - |
| 307 | int pageNum = 1; | - |
| 308 | for (int i = 0; i < rows && pageNum <= numPages; i++) { never evaluated: i < rows never evaluated: pageNum <= numPages | 0 |
| 309 | for (int j = 0; j < cols && pageNum <= numPages; j++) { never evaluated: j < cols never evaluated: pageNum <= numPages | 0 |
| 310 | if (!i && !j && viewMode == QPrintPreviewWidget::FacingPagesView) { never evaluated: viewMode == QPrintPreviewWidget::FacingPagesView | 0 |
| 311 | | - |
| 312 | continue; never executed: continue; | 0 |
| 313 | } else { | - |
| 314 | pages.at(pageNum-1)->setPos(QPointF(j*itemWidth, i*itemHeight)); | - |
| 315 | pageNum++; | - |
| 316 | } | 0 |
| 317 | } | - |
| 318 | } | 0 |
| 319 | scene->setSceneRect(scene->itemsBoundingRect()); | - |
| 320 | } | 0 |
| 321 | | - |
| 322 | void QPrintPreviewWidgetPrivate::generatePreview() | - |
| 323 | { | - |
| 324 | | - |
| 325 | | - |
| 326 | | - |
| 327 | | - |
| 328 | | - |
| 329 | | - |
| 330 | QPrintPreviewWidget * const q = q_func(); | - |
| 331 | printer->d_func()->setPreviewMode(true); | - |
| 332 | q->paintRequested(printer); | - |
| 333 | printer->d_func()->setPreviewMode(false); | - |
| 334 | pictures = printer->d_func()->previewPages(); | - |
| 335 | populateScene(); | - |
| 336 | layoutPages(); | - |
| 337 | curPage = qBound(1, curPage, pages.count()); | - |
| 338 | if (fitting) | 0 |
| 339 | _q_fit(); never executed: _q_fit(); | 0 |
| 340 | q->previewChanged(); | - |
| 341 | } | 0 |
| 342 | | - |
| 343 | void QPrintPreviewWidgetPrivate::setCurrentPage(int pageNumber) | - |
| 344 | { | - |
| 345 | if (pageNumber < 1 || pageNumber > pages.count()) never evaluated: pageNumber < 1 never evaluated: pageNumber > pages.count() | 0 |
| 346 | return; | 0 |
| 347 | | - |
| 348 | int lastPage = curPage; | - |
| 349 | curPage = pageNumber; | - |
| 350 | | - |
| 351 | if (lastPage != curPage && lastPage > 0 && lastPage <= pages.count()) { never evaluated: lastPage != curPage never evaluated: lastPage > 0 never evaluated: lastPage <= pages.count() | 0 |
| 352 | if (zoomMode != QPrintPreviewWidget::FitInView) { never evaluated: zoomMode != QPrintPreviewWidget::FitInView | 0 |
| 353 | QScrollBar *hsc = graphicsView->horizontalScrollBar(); | - |
| 354 | QScrollBar *vsc = graphicsView->verticalScrollBar(); | - |
| 355 | QPointF pt = graphicsView->transform().map(pages.at(curPage-1)->pos()); | - |
| 356 | vsc->setValue(int(pt.y()) - 10); | - |
| 357 | hsc->setValue(int(pt.x()) - 10); | - |
| 358 | } else { | 0 |
| 359 | graphicsView->centerOn(pages.at(curPage-1)); | - |
| 360 | } | 0 |
| 361 | } | - |
| 362 | } | 0 |
| 363 | | - |
| 364 | void QPrintPreviewWidgetPrivate::zoom(qreal zoom) | - |
| 365 | { | - |
| 366 | zoomFactor *= zoom; | - |
| 367 | graphicsView->scale(zoom, zoom); | - |
| 368 | } | 0 |
| 369 | | - |
| 370 | void QPrintPreviewWidgetPrivate::setZoomFactor(qreal _zoomFactor) | - |
| 371 | { | - |
| 372 | QPrintPreviewWidget * const q = q_func(); | - |
| 373 | zoomFactor = _zoomFactor; | - |
| 374 | graphicsView->resetTransform(); | - |
| 375 | int dpi_y = q->logicalDpiY(); | - |
| 376 | int printer_dpi_y = printer->logicalDpiY(); | - |
| 377 | graphicsView->scale(zoomFactor*(dpi_y/float(printer_dpi_y)), | - |
| 378 | zoomFactor*(dpi_y/float(printer_dpi_y))); | - |
| 379 | } | 0 |
| 380 | QPrintPreviewWidget::QPrintPreviewWidget(QPrinter *printer, QWidget *parent, Qt::WindowFlags flags) | - |
| 381 | : QWidget(*new QPrintPreviewWidgetPrivate, parent, flags) | - |
| 382 | { | - |
| 383 | QPrintPreviewWidgetPrivate * const d = d_func(); | - |
| 384 | d->printer = printer; | - |
| 385 | d->ownPrinter = false; | - |
| 386 | d->init(); | - |
| 387 | } | 0 |
| 388 | QPrintPreviewWidget::QPrintPreviewWidget(QWidget *parent, Qt::WindowFlags flags) | - |
| 389 | : QWidget(*new QPrintPreviewWidgetPrivate, parent, flags) | - |
| 390 | { | - |
| 391 | QPrintPreviewWidgetPrivate * const d = d_func(); | - |
| 392 | d->printer = new QPrinter; | - |
| 393 | d->ownPrinter = true; | - |
| 394 | d->init(); | - |
| 395 | } | 0 |
| 396 | | - |
| 397 | | - |
| 398 | | - |
| 399 | | - |
| 400 | | - |
| 401 | QPrintPreviewWidget::~QPrintPreviewWidget() | - |
| 402 | { | - |
| 403 | QPrintPreviewWidgetPrivate * const d = d_func(); | - |
| 404 | if (d->ownPrinter) never evaluated: d->ownPrinter | 0 |
| 405 | delete d->printer; never executed: delete d->printer; | 0 |
| 406 | } | 0 |
| 407 | | - |
| 408 | | - |
| 409 | | - |
| 410 | | - |
| 411 | QPrintPreviewWidget::ViewMode QPrintPreviewWidget::viewMode() const | - |
| 412 | { | - |
| 413 | const QPrintPreviewWidgetPrivate * const d = d_func(); | - |
| 414 | return d->viewMode; never executed: return d->viewMode; | 0 |
| 415 | } | - |
| 416 | | - |
| 417 | | - |
| 418 | | - |
| 419 | | - |
| 420 | | - |
| 421 | void QPrintPreviewWidget::setViewMode(ViewMode mode) | - |
| 422 | { | - |
| 423 | QPrintPreviewWidgetPrivate * const d = d_func(); | - |
| 424 | d->viewMode = mode; | - |
| 425 | d->layoutPages(); | - |
| 426 | if (d->viewMode == AllPagesView) { never evaluated: d->viewMode == AllPagesView | 0 |
| 427 | d->graphicsView->fitInView(d->scene->itemsBoundingRect(), Qt::KeepAspectRatio); | - |
| 428 | d->fitting = false; | - |
| 429 | d->zoomMode = QPrintPreviewWidget::CustomZoom; | - |
| 430 | d->zoomFactor = d->graphicsView->transform().m11() * (float(d->printer->logicalDpiY()) / logicalDpiY()); | - |
| 431 | previewChanged(); | - |
| 432 | } else { | 0 |
| 433 | d->fitting = true; | - |
| 434 | d->_q_fit(); | - |
| 435 | } | 0 |
| 436 | } | - |
| 437 | | - |
| 438 | | - |
| 439 | | - |
| 440 | | - |
| 441 | | - |
| 442 | QPrinter::Orientation QPrintPreviewWidget::orientation() const | - |
| 443 | { | - |
| 444 | const QPrintPreviewWidgetPrivate * const d = d_func(); | - |
| 445 | return d->printer->orientation(); never executed: return d->printer->orientation(); | 0 |
| 446 | } | - |
| 447 | | - |
| 448 | | - |
| 449 | | - |
| 450 | | - |
| 451 | | - |
| 452 | void QPrintPreviewWidget::setOrientation(QPrinter::Orientation orientation) | - |
| 453 | { | - |
| 454 | QPrintPreviewWidgetPrivate * const d = d_func(); | - |
| 455 | d->printer->setOrientation(orientation); | - |
| 456 | d->generatePreview(); | - |
| 457 | } | 0 |
| 458 | | - |
| 459 | | - |
| 460 | | - |
| 461 | | - |
| 462 | void QPrintPreviewWidget::print() | - |
| 463 | { | - |
| 464 | QPrintPreviewWidgetPrivate * const d = d_func(); | - |
| 465 | | - |
| 466 | paintRequested(d->printer); | - |
| 467 | } | 0 |
| 468 | | - |
| 469 | | - |
| 470 | | - |
| 471 | | - |
| 472 | | - |
| 473 | void QPrintPreviewWidget::zoomIn(qreal factor) | - |
| 474 | { | - |
| 475 | QPrintPreviewWidgetPrivate * const d = d_func(); | - |
| 476 | d->fitting = false; | - |
| 477 | d->zoomMode = QPrintPreviewWidget::CustomZoom; | - |
| 478 | d->zoom(factor); | - |
| 479 | } | 0 |
| 480 | | - |
| 481 | | - |
| 482 | | - |
| 483 | | - |
| 484 | | - |
| 485 | void QPrintPreviewWidget::zoomOut(qreal factor) | - |
| 486 | { | - |
| 487 | QPrintPreviewWidgetPrivate * const d = d_func(); | - |
| 488 | d->fitting = false; | - |
| 489 | d->zoomMode = QPrintPreviewWidget::CustomZoom; | - |
| 490 | d->zoom(1/factor); | - |
| 491 | } | 0 |
| 492 | | - |
| 493 | | - |
| 494 | | - |
| 495 | | - |
| 496 | qreal QPrintPreviewWidget::zoomFactor() const | - |
| 497 | { | - |
| 498 | const QPrintPreviewWidgetPrivate * const d = d_func(); | - |
| 499 | return d->zoomFactor; never executed: return d->zoomFactor; | 0 |
| 500 | } | - |
| 501 | void QPrintPreviewWidget::setZoomFactor(qreal factor) | - |
| 502 | { | - |
| 503 | QPrintPreviewWidgetPrivate * const d = d_func(); | - |
| 504 | d->fitting = false; | - |
| 505 | d->zoomMode = QPrintPreviewWidget::CustomZoom; | - |
| 506 | d->setZoomFactor(factor); | - |
| 507 | } | 0 |
| 508 | | - |
| 509 | | - |
| 510 | | - |
| 511 | | - |
| 512 | | - |
| 513 | int QPrintPreviewWidget::pageCount() const | - |
| 514 | { | - |
| 515 | const QPrintPreviewWidgetPrivate * const d = d_func(); | - |
| 516 | return d->pages.size(); never executed: return d->pages.size(); | 0 |
| 517 | } | - |
| 518 | | - |
| 519 | | - |
| 520 | | - |
| 521 | | - |
| 522 | int QPrintPreviewWidget::currentPage() const | - |
| 523 | { | - |
| 524 | const QPrintPreviewWidgetPrivate * const d = d_func(); | - |
| 525 | return d->curPage; never executed: return d->curPage; | 0 |
| 526 | } | - |
| 527 | | - |
| 528 | | - |
| 529 | | - |
| 530 | | - |
| 531 | | - |
| 532 | void QPrintPreviewWidget::setCurrentPage(int page) | - |
| 533 | { | - |
| 534 | QPrintPreviewWidgetPrivate * const d = d_func(); | - |
| 535 | d->setCurrentPage(page); | - |
| 536 | } | 0 |
| 537 | | - |
| 538 | | - |
| 539 | | - |
| 540 | | - |
| 541 | | - |
| 542 | void QPrintPreviewWidget::fitToWidth() | - |
| 543 | { | - |
| 544 | setZoomMode(FitToWidth); | - |
| 545 | } | 0 |
| 546 | | - |
| 547 | | - |
| 548 | | - |
| 549 | | - |
| 550 | | - |
| 551 | void QPrintPreviewWidget::fitInView() | - |
| 552 | { | - |
| 553 | setZoomMode(FitInView); | - |
| 554 | } | 0 |
| 555 | | - |
| 556 | | - |
| 557 | | - |
| 558 | | - |
| 559 | | - |
| 560 | | - |
| 561 | void QPrintPreviewWidget::setZoomMode(QPrintPreviewWidget::ZoomMode zoomMode) | - |
| 562 | { | - |
| 563 | QPrintPreviewWidgetPrivate * const d = d_func(); | - |
| 564 | d->zoomMode = zoomMode; | - |
| 565 | if (d->zoomMode == FitInView || d->zoomMode == FitToWidth) { never evaluated: d->zoomMode == FitInView never evaluated: d->zoomMode == FitToWidth | 0 |
| 566 | d->fitting = true; | - |
| 567 | d->_q_fit(true); | - |
| 568 | } else { | 0 |
| 569 | d->fitting = false; | - |
| 570 | } | 0 |
| 571 | } | - |
| 572 | | - |
| 573 | | - |
| 574 | | - |
| 575 | | - |
| 576 | | - |
| 577 | | - |
| 578 | QPrintPreviewWidget::ZoomMode QPrintPreviewWidget::zoomMode() const | - |
| 579 | { | - |
| 580 | const QPrintPreviewWidgetPrivate * const d = d_func(); | - |
| 581 | return d->zoomMode; never executed: return d->zoomMode; | 0 |
| 582 | } | - |
| 583 | | - |
| 584 | | - |
| 585 | | - |
| 586 | | - |
| 587 | | - |
| 588 | void QPrintPreviewWidget::setLandscapeOrientation() | - |
| 589 | { | - |
| 590 | setOrientation(QPrinter::Landscape); | - |
| 591 | } | 0 |
| 592 | | - |
| 593 | | - |
| 594 | | - |
| 595 | | - |
| 596 | | - |
| 597 | void QPrintPreviewWidget::setPortraitOrientation() | - |
| 598 | { | - |
| 599 | setOrientation(QPrinter::Portrait); | - |
| 600 | } | 0 |
| 601 | | - |
| 602 | | - |
| 603 | | - |
| 604 | | - |
| 605 | | - |
| 606 | void QPrintPreviewWidget::setSinglePageViewMode() | - |
| 607 | { | - |
| 608 | setViewMode(SinglePageView); | - |
| 609 | } | 0 |
| 610 | | - |
| 611 | | - |
| 612 | | - |
| 613 | | - |
| 614 | | - |
| 615 | void QPrintPreviewWidget::setFacingPagesViewMode() | - |
| 616 | { | - |
| 617 | setViewMode(FacingPagesView); | - |
| 618 | } | 0 |
| 619 | | - |
| 620 | | - |
| 621 | | - |
| 622 | | - |
| 623 | | - |
| 624 | void QPrintPreviewWidget::setAllPagesViewMode() | - |
| 625 | { | - |
| 626 | setViewMode(AllPagesView); | - |
| 627 | } | 0 |
| 628 | | - |
| 629 | | - |
| 630 | | - |
| 631 | | - |
| 632 | | - |
| 633 | | - |
| 634 | void QPrintPreviewWidget::updatePreview() | - |
| 635 | { | - |
| 636 | QPrintPreviewWidgetPrivate * const d = d_func(); | - |
| 637 | d->initialized = true; | - |
| 638 | d->generatePreview(); | - |
| 639 | d->graphicsView->updateGeometry(); | - |
| 640 | } | 0 |
| 641 | | - |
| 642 | | - |
| 643 | | - |
| 644 | void QPrintPreviewWidget::setVisible(bool visible) | - |
| 645 | { | - |
| 646 | QPrintPreviewWidgetPrivate * const d = d_func(); | - |
| 647 | if (visible && !d->initialized) never evaluated: !d->initialized | 0 |
| 648 | updatePreview(); never executed: updatePreview(); | 0 |
| 649 | QWidget::setVisible(visible); | - |
| 650 | } | 0 |
| 651 | | - |
| 652 | | - |
| 653 | | - |
| | |