From 72a2300befa492099026cc3eac5983622f1599f9 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 28 Sep 2021 16:10:55 +0300 Subject: [PATCH] Crop watermark if doesn't fit on page. --- src/app/puzzle/vptilefactory.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/app/puzzle/vptilefactory.cpp b/src/app/puzzle/vptilefactory.cpp index 12c3eebb3..a9e2a9444 100644 --- a/src/app/puzzle/vptilefactory.cpp +++ b/src/app/puzzle/vptilefactory.cpp @@ -659,16 +659,19 @@ void VPTileFactory::PaintWatermarkImage(QPainter *painter, const QRectF &img, co painter->save(); painter->setOpacity(watermarkData.opacity/100.); + QRect imagePosition(0, 0, watermark.width(), watermark.height()); + imagePosition.translate(img.center().toPoint() - imagePosition.center()); + if (watermark.width() < img.width() && watermark.height() < img.height()) { - QRect imagePosition(0, 0, watermark.width(), watermark.height()); - imagePosition.translate(img.center().toPoint() - imagePosition.center()); - painter->drawPixmap(imagePosition, watermark); } else { - painter->drawPixmap(img.toRect(), watermark); + QRect croppedRect = imagePosition.intersected(img.toRect()); + QPixmap cropped = watermark.copy(croppedRect.translated(-imagePosition.x(), -imagePosition.y())); + + painter->drawPixmap(croppedRect, cropped); } painter->restore();