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;
249 enum RefreshMode { RefreshImmediately,
254 void populateScene();
255 void updatePreview();
256 void generatePreview();
258 void print(
bool printAsPicture =
false);
259 void updatePageByPagePrintVector(QVector<int> &pageVector, QList<const QPicture *> &pictures)
const;
260 void asynPrint(
const QPointF &leftTop,
const QRect &pageRect,
const QVector<int> &pageVector);
261 void syncPrint(
const QPointF &leftTop,
const QRect &pageRect,
const QVector<int> &pageVector);
262 void printAsImage(
const QSize &paperSize, QVector<int> &pageVector);
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#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0)
273 D_DECL_DEPRECATED
void impositionPages();
275 int impositionPages(DPrintPreviewWidget::Imposition im);
276 QImage generateWaterMarkImage()
const;
277 PrintOptions printerOptions();
280 void generatePreviewPicture();
281 void calculateNumberUpPage();
282 void calculateNumberPagePosition();
284 void updateNumberUpContent();
285 QVector<int> requestPages(
int page);
286 void releaseImpositionData();
288 void displayWaterMarkItem();
289 void calculateNumberPageScale();
290 void calculateCurrentNumberPage();
291 QByteArray foundColorModelByCups()
const;
293 inline void setCurrentPageNumber(
int page)
295 currentPageNumber = page;
299 QGraphicsScene *scene;
301 QList<QPicture> targetPictures;
302 QList<const QPicture *> pictures;
303 QList<QGraphicsItem *> pages;
304 QGraphicsRectItem *background;
306 QVector<int> pageRange;
307 int currentPageNumber = 0;
308 DPrinter::ColorMode colorMode;
309 DPrintPreviewWidget::Imposition imposition;
310 DPrintPreviewWidget::Order order;
312 DPrintPreviewWidget::PageRange pageRangeMode = DPrintPreviewWidget::AllPage;
313#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0)
314 D_DECL_DEPRECATED
bool reviewChanged =
true;
317 RefreshMode refreshMode;
319 QString printFromPath;
320 DPrintPreviewWidget::PrintMode printMode;
322 QVector<int> previewPages;
323 bool asynPreviewNeedUpdate;
324 int asynPreviewTotalPage;
325 int pageCopyCount = 0;
330 QBasicTimer updateTimer;
338 NumberItem(QVector<int> _pageNumberVector, QVector<QPointF> _numberPointVector, QRect _pageRect)
339 : numberVector(_pageNumberVector)
340 , numberPointVector(_numberPointVector)
342 brect = QRectF(QPointF(0, 0), QSizeF(_pageRect.size()));
343 setCacheMode(DeviceCoordinateCache);
344 setPos(_pageRect.topLeft());
347 inline void setPageNumbers(
const QVector<int> &pageNumber)
349 numberVector = pageNumber;
352 inline void setNumberPositon(
const QVector<QPointF> &numberPos)
354 numberPointVector = numberPos;
357 QRectF boundingRect()
const override
362 void setRect(
const QRectF &rect)
364 setPos(rect.topLeft());
365 brect = QRectF(QPointF(0, 0), QSizeF(rect.size()));
368 void paint(QPainter *painter,
const QStyleOptionGraphicsItem *item, QWidget *widget)
override;
372 QVector<int> numberVector;
373 QVector<QPointF> numberPointVector;
377 WaterMark::Layout layout;
378 WaterMark::Type type;
389 QVector<QPair<int, const QPicture *>> previewPictures;
390 QVector<QPointF> paintPoints;
394 QPointF pageStartPoint;
395 QList<WaterMark *> waterList;
398 QGraphicsRectItem *waterParentItem;
399 bool needRecreateWater;
407 pageStartPoint = QPointF(0, 0);
410 QVector<QPointF> updatePositions(
const qreal &scale)
412#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
413 QRectF pageRect = parent->previewPrinter->pageLayout().paintRectPixels(parent->previewPrinter->resolution());
415 QRectF pageRect = parent->previewPrinter->pageRect();
417 QVector<QPointF> posList;
418 QPointF startP(0, 0);
422 topLeft = QPointF(0, 0);
423 if ((parent->imposition == DPrintPreviewWidget::OneRowTwoCol) || (parent->imposition == DPrintPreviewWidget::TwoRowThreeCol)) {
424 topLeft.setY(pageStartPoint.y() * (scale - 1.0));
427 topLeft.setX(pageRect.width() * (1.0 - scale) / 2.0);
428 topLeft.setY((NUMBERUP_SCALE_RATIO * rowCount - NUMBERUP_SPACE_SCALE_RATIO) * pageRect.height() * scaleRatio * (1.0 - scale) / 2.0);
431 switch (parent->order) {
432 case DPrintPreviewWidget::Copy:
433 case DPrintPreviewWidget::L2R_T2B: {
434 startP = pageStartPoint + topLeft;
435 for (
int i = 0; i < rowCount; ++i) {
436 for (
int j = 0; j < columnCount; ++j) {
437 posList.append(startP + QPointF(NUMBERUP_SCALE_RATIO * j * pageRect.width(), NUMBERUP_SCALE_RATIO * i * pageRect.height()) * scaleRatio * scale);
442 case DPrintPreviewWidget::R2L_T2B: {
443 qreal expanding = scale > 1 ? pageRect.width() * (scale - 1) : 0;
444 startP = pageStartPoint - QPointF(topLeft.x() - expanding - pageRect.width(), -topLeft.y());
445 for (
int i = 0; i < rowCount; ++i) {
446 for (
int j = 0; j < columnCount; ++j) {
447 posList.append(startP - QPointF((NUMBERUP_SCALE_RATIO * j + 1) * pageRect.width(), -(NUMBERUP_SCALE_RATIO * i) * pageRect.height()) * scaleRatio * scale);
451 case DPrintPreviewWidget::T2B_L2R: {
452 startP = pageStartPoint + topLeft;
453 for (
int i = 0; i < columnCount; ++i) {
454 for (
int j = 0; j < rowCount; ++j) {
455 posList.append(startP + QPointF(NUMBERUP_SCALE_RATIO * i * pageRect.width(), NUMBERUP_SCALE_RATIO * j * pageRect.height()) * scaleRatio * scale);
459 case DPrintPreviewWidget::T2B_R2L: {
460 qreal expanding = scale > 1 ? pageRect.width() * (scale - 1) : 0;
461 startP = pageStartPoint - QPointF(topLeft.x() - expanding - pageRect.width(), -topLeft.y());
462 for (
int i = 0; i < columnCount; ++i) {
463 for (
int j = 0; j < rowCount; ++j) {
464 posList.append(startP - QPointF((NUMBERUP_SCALE_RATIO * i + 1) * pageRect.width(), -(NUMBERUP_SCALE_RATIO * j) * pageRect.height()) * scaleRatio * scale);
473 void setWaterMarksScale(qreal scale)
475 if (waterList.isEmpty())
477#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
478 QRectF pageRect = parent->previewPrinter->pageLayout().paintRectPixels(parent->previewPrinter->resolution());
480 QRectF pageRect = parent->previewPrinter->pageRect();
482 QMargins pageMargins = parent->previewPrinter->pageLayout().marginsPixels(parent->previewPrinter->resolution());
483 const QVector<QPointF> &posList = updatePositions(scale);
485 for (
int c = 0; c < waterList.count(); ++c) {
486 WaterMark *item = waterList.at(c);
487 item->setBoundingRect(QRectF(QPointF(pageMargins.left(), pageMargins.top()) + posList.at(c), pageRect.size() * scaleRatio * scale));
492 numberItem->update();
495 void setWaterMarkOriginProperties(WaterMark *wm)
497 if (!wm || !waterProperty)
500 wm->type = waterProperty->type;
501 wm->layout = waterProperty->layout;
502 wm->mScaleFactor = waterProperty->scale;
503 wm->color = waterProperty->color;
504 wm->text = waterProperty->text;
505 wm->sourceImage = waterProperty->sourceImage;
506 wm->graySourceImage = waterProperty->grayImage;
507 wm->font = waterProperty->font;
508 wm->setRotation(waterProperty->rotation);
509 wm->setOpacity(waterProperty->opacity);
512 void copyWaterMarkProperties()
516 if (!parent->waterMark && waterList.isEmpty())
520 if (waterList.isEmpty()) {
521 wm = parent->waterMark;
523 wm = waterList.first();
527 waterProperty =
new WaterMarkProperty;
529 waterProperty->type = wm->type;
530 waterProperty->layout = wm->layout;
531 waterProperty->rotation = wm->rotation();
532 waterProperty->scale = wm->mScaleFactor;
533 waterProperty->opacity = wm->opacity();
534 waterProperty->color = wm->color;
535 waterProperty->text = wm->text;
536 waterProperty->sourceImage = wm->sourceImage;
537 waterProperty->grayImage = wm->graySourceImage;
538 waterProperty->font = wm->font;
541 void updateWaterMarks()
543 if (waterList.isEmpty())
546 for (
auto *item : qAsConst(waterList))
551 void setWaterMarkProperty(T outFunction)
553 if (waterList.isEmpty())
556 auto *firstWm = waterList.first();
557 outFunction(firstWm);
559 for (
auto *item : qAsConst(waterList)) {
564 item->type = firstWm->type;
565 item->layout = firstWm->layout;
566 item->mScaleFactor = firstWm->mScaleFactor;
567 item->color = firstWm->color;
568 item->text = firstWm->text;
569 item->sourceImage = firstWm->sourceImage;
570 item->graySourceImage = firstWm->graySourceImage;
571 item->font = firstWm->font;
572 item->setRotation(firstWm->rotation());
573 item->setOpacity(firstWm->opacity());
577 NumberUpData(DPrintPreviewWidgetPrivate *parent)
583 , pageStartPoint(0, 0)
584 , waterProperty(nullptr)
585 , numberItem(nullptr)
586 , waterParentItem(nullptr)
587 , needRecreateWater(false)
594 delete waterProperty;
596 delete waterParentItem;