DtkWidget
DTK Widget module
载入中...
搜索中...
未找到
dprintpreviewwidget.h
1// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#ifndef DPRINTPREVIEWWIDGET_H
6#define DPRINTPREVIEWWIDGET_H
7
8#include <dtkwidget_global.h>
9#include <DGuiApplicationHelper>
10#include <DFrame>
11
12#include <QWidget>
13#include <QPainter>
14#include <QStyleOption>
15#include <QGraphicsItem>
16
17#define private protected
18#include <QPrinter>
19#undef private
20
21
22
23DWIDGET_BEGIN_NAMESPACE
24
25DGUI_USE_NAMESPACE
26
27class DPrintPreviewWidgetPrivate;
28
29class DPrinter : public QPrinter
30{
31public:
32 explicit DPrinter(PrinterMode mode = ScreenResolution);
33 ~DPrinter() {}
34
35 enum Orientation { Portrait, Landscape };
36
37 void setPreviewMode(bool isPreview);
38
39 QList<const QPicture *> getPrinterPages();
40
41private:
42};
43
44class LIBDTKWIDGETSHARED_EXPORT DPrintPreviewWidget : public DFrame
45{
46 Q_OBJECT
47public:
48 enum Imposition { // 并打
49 One, // 单页
50 OneRowTwoCol, // 一行两列
51 TwoRowTwoCol, // 两行两列
52 TwoRowThreeCol, // 两行三列
53 ThreeRowThreeCol, // 三行三列
54 FourRowFourCol // 四行四列
55 };
56 enum PageRange {
57 AllPage,
58 CurrentPage,
59 SelectPage
60 };
61 enum Order { // 并打顺序
62 L2R_T2B, // 从左到右,从上到下
63 R2L_T2B, // 从右到左,从上到下
64 T2B_L2R, // 从上到下,从左到右
65 T2B_R2L, // 从上到下,从右到左
66 Copy // 重复
67 };
68
69 enum PrintMode { // 打印模式
70 PrintToPrinter, // 打印到打印机
71 PrintToPdf, // 打印到pdf
72 PrintToImage // 另存为图片
73 };
74
75 explicit DPrintPreviewWidget(DPrinter *printer, QWidget *parent = nullptr);
76 ~DPrintPreviewWidget() override;
77
78 void setVisible(bool visible) override;
79 void setPageRange(const QVector<int> &rangePages);
80 void setPageRange(int from, int to);
81 void setPageRangeALL();
82#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0)
83 D_DECL_DEPRECATED void setReGenerate(bool generate);
84#endif
85 void setPageRangeMode(PageRange mode);
86 PageRange pageRangeMode();
87#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0)
88 D_DECL_DEPRECATED void reviewChange(bool generate);
89#endif
90 int pagesCount();
91 int currentPage();
92 bool turnPageAble();
93 void setColorMode(const DPrinter::ColorMode &colorMode);
94 void setOrientation(const DPrinter::Orientation &pageOrientation);
95 DPrinter::ColorMode getColorMode();
96 void setScale(qreal scale);
97 qreal getScale() const;
98 void updateView();
99 void updateWaterMark();
100 void refreshBegin();
101 void refreshEnd();
102 void setWaterMarkType(int type);
103 void setWaterMargImage(const QImage &image);
104 void setWaterMarkRotate(qreal rotate);
105 void setWaterMarkScale(qreal scale);
106 void setWaterMarkOpacity(qreal opacity);
107 void setConfidentialWaterMark();
108 void setDraftWaterMark();
109 void setSampleWaterMark();
110 void setCustomWaterMark(const QString &text);
111 void setTextWaterMark(const QString &text);
112 void setWaterMarkFont(const QFont &font);
113 QColor waterMarkColor() const;
114 void setWaterMarkColor(const QColor &color);
115 void setWaterMarkLayout(int layout);
116 void setImposition(Imposition im);
117 Imposition imposition() const;
118 void setOrder(Order order);
119 DPrintPreviewWidget::Order order() const;
120 void setPrintFromPath(const QString &path);
121 QString printFromPath() const;
122 void setPrintMode(PrintMode pt);
123 void setAsynPreview(int totalPage);
124 bool isAsynPreview() const;
125 void isPageByPage(int pageCopy,bool isFirst);
126 int targetPageCount(int pageCount);
127 int originPageCount();
128 QByteArray printerColorModel() const;
129
130public Q_SLOTS:
131 void updatePreview();
132 void turnFront();
133 void turnBack();
134 void turnBegin();
135 void turnEnd();
136 void setCurrentPage(int page);
137 void print(bool isSavedPicture = false);
138 void themeTypeChanged(DGuiApplicationHelper::ColorType themeType);
139
140Q_SIGNALS:
141 void paintRequested(DPrinter *printer);
142 void paintRequested(DPrinter *printer, const QVector<int> &pageRange);
143 void previewChanged();
144 void currentPageChanged(int page);
145 void totalPages(int);
146 void pagesCountChanged(int pages);
147
148private:
149 void timerEvent(QTimerEvent *event) override;
150 void setCurrentTargetPage(int page);
151
152 D_DECLARE_PRIVATE(DPrintPreviewWidget)
153 friend class ContentItem;
154};
155
156DWIDGET_END_NAMESPACE
157
158#endif // DPRINTPREVIEWWIDGET_H
Definition dprintpreviewwidget_p.h:61
继承自QFrame类, 支持设置边框圆角,背景画刷功能
Definition dframe.h:18
Definition dprintpreviewwidget.h:45
Definition dprintpreviewwidget.h:30