summaryrefslogtreecommitdiffstats
path: root/src/printsupport/widgets/qprintpreviewwidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/printsupport/widgets/qprintpreviewwidget.cpp')
-rw-r--r--src/printsupport/widgets/qprintpreviewwidget.cpp65
1 files changed, 17 insertions, 48 deletions
diff --git a/src/printsupport/widgets/qprintpreviewwidget.cpp b/src/printsupport/widgets/qprintpreviewwidget.cpp
index 46d93c315e..637eb42505 100644
--- a/src/printsupport/widgets/qprintpreviewwidget.cpp
+++ b/src/printsupport/widgets/qprintpreviewwidget.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qprintpreviewwidget.h"
#include "private/qwidget_p.h"
@@ -50,7 +14,7 @@
QT_BEGIN_NAMESPACE
-namespace {
+namespace QtPrivate {
class PageItem : public QGraphicsItem
{
public:
@@ -61,7 +25,6 @@ public:
qreal border = qMax(paperSize.height(), paperSize.width()) / 25;
brect = QRectF(QPointF(-border, -border),
QSizeF(paperSize)+QSizeF(2*border, 2*border));
- setCacheMode(DeviceCoordinateCache);
}
QRectF boundingRect() const override
@@ -172,7 +135,10 @@ protected:
}
};
-} // anonymous namespace
+} // namespace QtPrivate
+
+using GraphicsView = QtPrivate::GraphicsView;
+using PageItem = QtPrivate::PageItem;
class QPrintPreviewWidgetPrivate : public QWidgetPrivate
{
@@ -218,7 +184,7 @@ void QPrintPreviewWidgetPrivate::_q_fit(bool doFitting)
{
Q_Q(QPrintPreviewWidget);
- if (curPage < 1 || curPage > pages.count())
+ if (curPage < 1 || curPage > pages.size())
return;
if (!doFitting && !fitting)
@@ -332,7 +298,7 @@ void QPrintPreviewWidgetPrivate::init()
void QPrintPreviewWidgetPrivate::populateScene()
{
// remove old pages
- for (auto *page : qAsConst(pages))
+ for (auto *page : std::as_const(pages))
scene->removeItem(page);
qDeleteAll(pages);
pages.clear();
@@ -341,7 +307,7 @@ void QPrintPreviewWidgetPrivate::populateScene()
QRect pageRect = printer->pageLayout().paintRectPixels(printer->resolution());
int page = 1;
- for (auto *picture : qAsConst(pictures)) {
+ for (auto *picture : std::as_const(pictures)) {
PageItem* item = new PageItem(page++, picture, paperSize, pageRect);
scene->addItem(item);
pages.append(item);
@@ -350,7 +316,7 @@ void QPrintPreviewWidgetPrivate::populateScene()
void QPrintPreviewWidgetPrivate::layoutPages()
{
- int numPages = pages.count();
+ int numPages = pages.size();
if (numPages < 1)
return;
@@ -395,13 +361,16 @@ void QPrintPreviewWidgetPrivate::generatePreview()
//### emit paintRequested() until the user changes some parameter
Q_Q(QPrintPreviewWidget);
+ // Avoid previewing a preview
+ if (printer->d_func()->previewMode())
+ return;
printer->d_func()->setPreviewMode(true);
emit q->paintRequested(printer);
printer->d_func()->setPreviewMode(false);
pictures = printer->d_func()->previewPages();
populateScene(); // i.e. setPreviewPrintedPictures() e.l.
layoutPages();
- curPage = qBound(1, curPage, pages.count());
+ curPage = pages.size() > 0 ? qBound(1, curPage, pages.size()) : 1;
if (fitting)
_q_fit();
emit q->previewChanged();
@@ -409,13 +378,13 @@ void QPrintPreviewWidgetPrivate::generatePreview()
void QPrintPreviewWidgetPrivate::setCurrentPage(int pageNumber)
{
- if (pageNumber < 1 || pageNumber > pages.count())
+ if (pageNumber < 1 || pageNumber > pages.size())
return;
int lastPage = curPage;
curPage = pageNumber;
- if (lastPage != curPage && lastPage > 0 && lastPage <= pages.count()) {
+ if (lastPage != curPage && lastPage > 0 && lastPage <= pages.size()) {
if (zoomMode != QPrintPreviewWidget::FitInView) {
QScrollBar *hsc = graphicsView->horizontalScrollBar();
QScrollBar *vsc = graphicsView->verticalScrollBar();