1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QPRINTPREVIEWWIDGET_H
5#define QPRINTPREVIEWWIDGET_H
6
7#include <QtPrintSupport/qtprintsupportglobal.h>
8#include <QtWidgets/qwidget.h>
9#include <QtPrintSupport/qprinter.h>
10
11QT_REQUIRE_CONFIG(printpreviewwidget);
12
13QT_BEGIN_NAMESPACE
14
15
16class QPrintPreviewWidgetPrivate;
17
18class Q_PRINTSUPPORT_EXPORT QPrintPreviewWidget : public QWidget
19{
20 Q_OBJECT
21 Q_DECLARE_PRIVATE(QPrintPreviewWidget)
22public:
23
24 enum ViewMode {
25 SinglePageView,
26 FacingPagesView,
27 AllPagesView
28 };
29
30 enum ZoomMode {
31 CustomZoom,
32 FitToWidth,
33 FitInView
34 };
35
36 explicit QPrintPreviewWidget(QPrinter *printer, QWidget *parent = nullptr,
37 Qt::WindowFlags flags = Qt::WindowFlags());
38 explicit QPrintPreviewWidget(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags());
39 ~QPrintPreviewWidget();
40
41 qreal zoomFactor() const;
42 QPageLayout::Orientation orientation() const;
43 ViewMode viewMode() const;
44 ZoomMode zoomMode() const;
45 int currentPage() const;
46 int pageCount() const;
47 void setVisible(bool visible) override;
48
49public Q_SLOTS:
50 void print();
51
52 void zoomIn(qreal zoom = 1.1);
53 void zoomOut(qreal zoom = 1.1);
54 void setZoomFactor(qreal zoomFactor);
55 void setOrientation(QPageLayout::Orientation orientation);
56 void setViewMode(ViewMode viewMode);
57 void setZoomMode(ZoomMode zoomMode);
58 void setCurrentPage(int pageNumber);
59
60 void fitToWidth();
61 void fitInView();
62 void setLandscapeOrientation();
63 void setPortraitOrientation();
64 void setSinglePageViewMode();
65 void setFacingPagesViewMode();
66 void setAllPagesViewMode();
67
68 void updatePreview();
69
70Q_SIGNALS:
71 void paintRequested(QPrinter *printer);
72 void previewChanged();
73
74private:
75 Q_PRIVATE_SLOT(d_func(), void _q_fit())
76 Q_PRIVATE_SLOT(d_func(), void _q_updateCurrentPage())
77};
78
79QT_END_NAMESPACE
80
81#endif // QPRINTPREVIEWWIDGET_H
82

source code of qtbase/src/printsupport/widgets/qprintpreviewwidget.h