5#ifndef DPRINTPREVIEWWIDGET_P_H
6#define DPRINTPREVIEWWIDGET_P_H
8#include <dprintpreviewwidget.h>
13#include <QGraphicsScene>
14#include <QGraphicsView>
20DWIDGET_BEGIN_NAMESPACE
22#define PREVIEW_WIDGET_MARGIN_RATIO 50
23#define PREVIEW_ENLARGE_RATIO 1.25
24#define PREVIEW_NARROW_RATIO 0.8
25#define PREVIEW_SCALEBUTTON_MARGIN 10
26#define PREVIEW_WATER_COUNT_WIDTH 28
27#define PREVIEW_WATER_COUNT_HEIGHT 20
28#define PREVIEW_WATER_COUNT_SPACE 10
29#define NUMBERUP_SCALE_RATIO 1.05
30#define NUMBERUP_SPACE_SCALE_RATIO 0.05
39 void resetScale(
bool autoReset =
true);
45 void mousePressEvent(QMouseEvent *e)
override;
46 void mouseReleaseEvent(QMouseEvent *e)
override;
47 void wheelEvent(QWheelEvent *e)
override;
48 void resizeEvent(QResizeEvent *e)
override;
49 void showEvent(QShowEvent *e)
override;
50 void changeEvent(
QEvent *e)
override;
53 void onThemeTypeChanged(DGuiApplicationHelper::ColorType themeType);
63 ContentItem(
const QPicture *_pagePicture,
QRect _pageRect, QGraphicsItem *parent =
nullptr)
64 : QGraphicsItem(parent)
65 , pagePicture(_pagePicture)
69 setCacheMode(DeviceCoordinateCache);
70 setPos(pageRect.topLeft());
73 QRectF boundingRect()
const override
78 void setRect(
const QRectF &rect)
84 void paint(QPainter *painter,
const QStyleOptionGraphicsItem *item, QWidget *widget)
override;
85 void updateGrayContent();
86 void drawNumberUpPictures(QPainter *painter);
89 QPicture grayscalePaint(
const QPicture &picture);
90 QImage imageGrayscale(
const QImage *origin);
93 const QPicture *pagePicture;
111 WaterMark(QGraphicsItem *parent =
nullptr)
112 : QGraphicsItem(parent)
118 inline void setType(Type t)
122 inline Type getType()
const
126 inline void setLayoutType(Layout l)
130 inline void setScaleFactor(qreal scale)
132 mScaleFactor = scale;
134 void setImage(
const QImage &img);
135 inline void setText(
const QString str)
140 inline void setFont(
const QFont &f)
144 inline QFont getFont()
const
148 inline void setColor(
const QColor &c)
152 inline QColor getColor()
const
156 inline void setBoundingRect(
const QRectF &rect)
158 qreal rotate = rotation();
161 brectPolygon = mapToScene(brect);
162 qreal width = brect.width();
163 qreal height = brect.height();
165 qreal maxDis = qSqrt(qPow(width, 2) + qPow(height, 2));
166 twoPolygon = mapToScene(
QRectF(
QPointF(brect.center().x() - maxDis / 2, brect.center().y() - maxDis / 2),
QSizeF(maxDis, maxDis)));
167 setTransformOriginPoint(brect.center());
170 QRectF boundingRect()
const override
172 return mapToScene(brect.toRect()).boundingRect();
174 inline QPolygonF itemMaxPolygon()
const
178 void paint(QPainter *painter,
const QStyleOptionGraphicsItem *item, QWidget *widget)
override;
179 void updatePicture(QPainter *painter,
bool isPreview);
181 void setNumberUpScale(
const qreal &value);
184 QPainterPath itemClipPath()
const;
190 QImage graySourceImage;
193 qreal mScaleFactor = 1.0;
194 QGraphicsTextItem textItem;
198 qreal numberUpScale = 1;
200 QPolygonF brectPolygon;
201 QPolygonF twoPolygon;
208 PageItem(
int _pageNum,
const QPicture *_pagePicture,
QSize _paperSize,
QRect _pageRect)
210 , pagePicture(_pagePicture)
211 , paperSize(_paperSize)
212 , pageRect(_pageRect)
213 , content(
new ContentItem(_pagePicture, _pageRect,
this))
215 qreal border = qMax(paperSize.height(), paperSize.width()) / PREVIEW_WIDGET_MARGIN_RATIO;
218 setCacheMode(DeviceCoordinateCache);
221 QRectF boundingRect()
const override
226 inline int pageNumber()
const
231 void paint(QPainter *painter,
const QStyleOptionGraphicsItem *item, QWidget *widget)
override;
233 void setVisible(
bool isVisible);
237 const QPicture *pagePicture;
249 enum RefreshMode { RefreshImmediately,
254 void populateScene();
255 void updatePreview();
256 void generatePreview();
258 void print(
bool printAsPicture =
false);
263 void printSinglePageDrawUtil(QPainter *painter,
const QSize &translateSize,
const QPointF &leftTop,
const QImage &waterImage,
const QPicture *picture);
264 void printMultiPageDrawUtil(QPainter *painter,
const QPointF &leftTop,
const QImage &waterImage);
266 void setPageRangeAll();
267 void setCurrentPage(
int page);
269 int targetPage(
int page);
270 int index2page(
int index);
271 int page2index(
int page);
272 D_DECL_DEPRECATED
void impositionPages();
273 int impositionPages(DPrintPreviewWidget::Imposition im);
274 QImage generateWaterMarkImage()
const;
278 void generatePreviewPicture();
279 void calculateNumberUpPage();
280 void calculateNumberPagePosition();
282 void updateNumberUpContent();
284 void releaseImpositionData();
286 void displayWaterMarkItem();
287 void calculateNumberPageScale();
288 void calculateCurrentNumberPage();
291 inline void setCurrentPageNumber(
int page)
293 currentPageNumber = page;
297 QGraphicsScene *scene;
302 QGraphicsRectItem *background;
305 int currentPageNumber = 0;
306 DPrinter::ColorMode colorMode;
307 DPrintPreviewWidget::Imposition imposition;
308 DPrintPreviewWidget::Order order;
310 DPrintPreviewWidget::PageRange pageRangeMode = DPrintPreviewWidget::AllPage;
311 D_DECL_DEPRECATED
bool reviewChanged =
true;
314 RefreshMode refreshMode;
317 DPrintPreviewWidget::PrintMode printMode;
320 bool asynPreviewNeedUpdate;
321 int asynPreviewTotalPage;
322 int pageCopyCount = 0;
336 : numberVector(_pageNumberVector)
337 , numberPointVector(_numberPointVector)
340 setCacheMode(DeviceCoordinateCache);
344 inline void setPageNumbers(
const QVector<int> &pageNumber)
346 numberVector = pageNumber;
351 numberPointVector = numberPos;
354 QRectF boundingRect()
const override
359 void setRect(
const QRectF &rect)
365 void paint(QPainter *painter,
const QStyleOptionGraphicsItem *item, QWidget *widget)
override;
374 WaterMark::Layout layout;
375 WaterMark::Type type;
395 QGraphicsRectItem *waterParentItem;
396 bool needRecreateWater;
404 pageStartPoint =
QPointF(0, 0);
409 QRectF pageRect = parent->previewPrinter->pageRect();
416 if ((parent->imposition == DPrintPreviewWidget::OneRowTwoCol) || (parent->imposition == DPrintPreviewWidget::TwoRowThreeCol)) {
417 topLeft.
setY(pageStartPoint.
y() * (scale - 1.0));
420 topLeft.
setX(pageRect.
width() * (1.0 - scale) / 2.0);
421 topLeft.
setY((NUMBERUP_SCALE_RATIO * rowCount - NUMBERUP_SPACE_SCALE_RATIO) * pageRect.
height() * scaleRatio * (1.0 - scale) / 2.0);
424 switch (parent->order) {
425 case DPrintPreviewWidget::Copy:
426 case DPrintPreviewWidget::L2R_T2B: {
427 startP = pageStartPoint + topLeft;
428 for (
int i = 0; i < rowCount; ++i) {
429 for (
int j = 0; j < columnCount; ++j) {
430 posList.
append(startP +
QPointF(NUMBERUP_SCALE_RATIO * j * pageRect.
width(), NUMBERUP_SCALE_RATIO * i * pageRect.
height()) * scaleRatio * scale);
435 case DPrintPreviewWidget::R2L_T2B: {
436 qreal expanding = scale > 1 ? pageRect.
width() * (scale - 1) : 0;
437 startP = pageStartPoint -
QPointF(topLeft.x() - expanding - pageRect.
width(), -topLeft.y());
438 for (
int i = 0; i < rowCount; ++i) {
439 for (
int j = 0; j < columnCount; ++j) {
440 posList.
append(startP -
QPointF((NUMBERUP_SCALE_RATIO * j + 1) * pageRect.
width(), -(NUMBERUP_SCALE_RATIO * i) * pageRect.
height()) * scaleRatio * scale);
444 case DPrintPreviewWidget::T2B_L2R: {
445 startP = pageStartPoint + topLeft;
446 for (
int i = 0; i < columnCount; ++i) {
447 for (
int j = 0; j < rowCount; ++j) {
448 posList.
append(startP +
QPointF(NUMBERUP_SCALE_RATIO * i * pageRect.
width(), NUMBERUP_SCALE_RATIO * j * pageRect.
height()) * scaleRatio * scale);
452 case DPrintPreviewWidget::T2B_R2L: {
453 qreal expanding = scale > 1 ? pageRect.
width() * (scale - 1) : 0;
454 startP = pageStartPoint -
QPointF(topLeft.x() - expanding - pageRect.
width(), -topLeft.y());
455 for (
int i = 0; i < columnCount; ++i) {
456 for (
int j = 0; j < rowCount; ++j) {
457 posList.
append(startP -
QPointF((NUMBERUP_SCALE_RATIO * i + 1) * pageRect.
width(), -(NUMBERUP_SCALE_RATIO * j) * pageRect.
height()) * scaleRatio * scale);
466 void setWaterMarksScale(qreal scale)
471 QRectF pageRect = parent->previewPrinter->pageRect();
472 QMargins pageMargins = parent->previewPrinter->pageLayout().marginsPixels(parent->previewPrinter->resolution());
475 for (
int c = 0; c < waterList.
count(); ++c) {
476 WaterMark *item = waterList.
at(c);
477 item->setBoundingRect(
QRectF(
QPointF(pageMargins.
left(), pageMargins.
top()) + posList.
at(c), pageRect.
size() * scaleRatio * scale));
482 numberItem->update();
485 void setWaterMarkOriginProperties(WaterMark *wm)
487 if (!wm || !waterProperty)
490 wm->type = waterProperty->type;
491 wm->layout = waterProperty->layout;
492 wm->mScaleFactor = waterProperty->scale;
493 wm->color = waterProperty->color;
494 wm->text = waterProperty->text;
495 wm->sourceImage = waterProperty->sourceImage;
496 wm->graySourceImage = waterProperty->grayImage;
497 wm->font = waterProperty->font;
498 wm->setRotation(waterProperty->rotation);
499 wm->setOpacity(waterProperty->opacity);
502 void copyWaterMarkProperties()
506 if (!parent->waterMark && waterList.
isEmpty())
511 wm = parent->waterMark;
513 wm = waterList.
first();
517 waterProperty =
new WaterMarkProperty;
519 waterProperty->type = wm->type;
520 waterProperty->layout = wm->layout;
521 waterProperty->rotation = wm->rotation();
522 waterProperty->scale = wm->mScaleFactor;
523 waterProperty->opacity = wm->opacity();
524 waterProperty->color = wm->color;
525 waterProperty->text = wm->text;
526 waterProperty->sourceImage = wm->sourceImage;
527 waterProperty->grayImage = wm->graySourceImage;
528 waterProperty->font = wm->font;
531 void updateWaterMarks()
536 for (
auto *item : qAsConst(waterList))
541 void setWaterMarkProperty(T outFunction)
546 auto *firstWm = waterList.
first();
547 outFunction(firstWm);
549 for (
auto *item : qAsConst(waterList)) {
554 item->type = firstWm->type;
555 item->layout = firstWm->layout;
556 item->mScaleFactor = firstWm->mScaleFactor;
557 item->color = firstWm->color;
558 item->text = firstWm->text;
559 item->sourceImage = firstWm->sourceImage;
560 item->graySourceImage = firstWm->graySourceImage;
561 item->font = firstWm->font;
562 item->setRotation(firstWm->rotation());
563 item->setOpacity(firstWm->opacity());
567 NumberUpData(DPrintPreviewWidgetPrivate *parent)
573 , pageStartPoint(0, 0)
574 , waterProperty(nullptr)
575 , numberItem(nullptr)
576 , waterParentItem(nullptr)
577 , needRecreateWater(false)
584 delete waterProperty;
586 delete waterParentItem;
591Q_DECLARE_TYPEINFO(DTK_WIDGET_NAMESPACE::DPrintPreviewWidgetPrivate::NumberUpData::WaterMarkProperty, Q_PRIMITIVE_TYPE);
Definition: dprintpreviewwidget_p.h:61
Definition: dprintpreviewwidget_p.h:206
const T & at(int i) const const
int count(const T &value) const const
bool isEmpty() const const
QPoint topLeft() const const
qreal height() const const
QSizeF size() const const
QPointF topLeft() const const
qreal width() const const
void append(const T &value)
const T & at(int i) const const