From 389c7b0235fe762cda799ad4ce8bfbe710bef210 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Fri, 7 Aug 2020 00:35:00 +0200 Subject: [PATCH 1/2] PagePainter: Don't draw Arrow/Line annotations with multipyl Otherwise they will be transparent when they shouldn't BUGS: 425075 --- ui/pagepainter.cpp | 18 +++++++++--------- ui/pagepainter.h | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ui/pagepainter.cpp b/ui/pagepainter.cpp index 641f5e69d..dab6a4f07 100644 --- a/ui/pagepainter.cpp +++ b/ui/pagepainter.cpp @@ -1105,14 +1105,14 @@ void LineAnnotPainter::draw(QImage &image) const void LineAnnotPainter::drawMainLine(QImage &image) const { // draw the line as normalized path into image - PagePainter::drawShapeOnImage(image, transformPath(la->transformedLinePoints(), toNormalizedImage), la->lineClosed(), linePen, fillBrush, pageScale, PagePainter::Multiply); + PagePainter::drawShapeOnImage(image, transformPath(la->transformedLinePoints(), toNormalizedImage), la->lineClosed(), linePen, fillBrush, pageScale); } void LineAnnotPainter::drawShortenedLine(double mainSegmentLength, double size, QImage &image, const QTransform &toNormalizedPage) const { const QTransform combinedTransform {toNormalizedPage * toNormalizedImage}; const QList path {{shortenForArrow(size, la->lineStartStyle()), 0}, {mainSegmentLength - shortenForArrow(size, la->lineEndStyle()), 0}}; - PagePainter::drawShapeOnImage(image, transformPath(path, combinedTransform), la->lineClosed(), linePen, fillBrush, pageScale, PagePainter::Multiply); + PagePainter::drawShapeOnImage(image, transformPath(path, combinedTransform), la->lineClosed(), linePen, fillBrush, pageScale); } void LineAnnotPainter::drawLineEnds(double mainSegmentLength, double size, QImage &image, const QTransform &transform) const @@ -1189,7 +1189,7 @@ void LineAnnotPainter::drawLineEndArrow(double xEndPos, double size, double flip {xEndPos, 0}, {xEndPos - size * flipX, -size / 2.}, }; - PagePainter::drawShapeOnImage(image, transformPath(path, combinedTransform), close, linePen, fillBrush, pageScale, PagePainter::Multiply); + PagePainter::drawShapeOnImage(image, transformPath(path, combinedTransform), close, linePen, fillBrush, pageScale); } void LineAnnotPainter::drawLineEndButt(double xEndPos, double size, const QTransform &toNormalizedPage, QImage &image) const @@ -1200,7 +1200,7 @@ void LineAnnotPainter::drawLineEndButt(double xEndPos, double size, const QTrans {xEndPos, halfSize}, {xEndPos, -halfSize}, }; - PagePainter::drawShapeOnImage(image, transformPath(path, combinedTransform), true, linePen, fillBrush, pageScale, PagePainter::Multiply); + PagePainter::drawShapeOnImage(image, transformPath(path, combinedTransform), true, linePen, fillBrush, pageScale); } void LineAnnotPainter::drawLineEndCircle(double xEndPos, double size, const QTransform &toNormalizedPage, QImage &image) const @@ -1216,21 +1216,21 @@ void LineAnnotPainter::drawLineEndCircle(double xEndPos, double size, const QTra }; /* then transform bounding rect with toNormalizedImage */ - PagePainter::drawEllipseOnImage(image, transformPath(path, toNormalizedImage), linePen, fillBrush, pageScale, PagePainter::Multiply); + PagePainter::drawEllipseOnImage(image, transformPath(path, toNormalizedImage), linePen, fillBrush, pageScale); } void LineAnnotPainter::drawLineEndSquare(double xEndPos, double size, const QTransform &toNormalizedPage, QImage &image) const { const QTransform combinedTransform {toNormalizedPage * toNormalizedImage}; const QList path {{xEndPos, size / 2.}, {xEndPos - size, size / 2.}, {xEndPos - size, -size / 2.}, {xEndPos, -size / 2.}}; - PagePainter::drawShapeOnImage(image, transformPath(path, combinedTransform), true, linePen, fillBrush, pageScale, PagePainter::Multiply); + PagePainter::drawShapeOnImage(image, transformPath(path, combinedTransform), true, linePen, fillBrush, pageScale); } void LineAnnotPainter::drawLineEndDiamond(double xEndPos, double size, const QTransform &toNormalizedPage, QImage &image) const { const QTransform combinedTransform {toNormalizedPage * toNormalizedImage}; const QList path {{xEndPos, 0}, {xEndPos - size / 2., size / 2.}, {xEndPos - size, 0}, {xEndPos - size / 2., -size / 2.}}; - PagePainter::drawShapeOnImage(image, transformPath(path, combinedTransform), true, linePen, fillBrush, pageScale, PagePainter::Multiply); + PagePainter::drawShapeOnImage(image, transformPath(path, combinedTransform), true, linePen, fillBrush, pageScale); } void LineAnnotPainter::drawLineEndSlash(double xEndPos, double size, const QTransform &toNormalizedPage, QImage &image) const @@ -1242,7 +1242,7 @@ void LineAnnotPainter::drawLineEndSlash(double xEndPos, double size, const QTran {xEndPos - xOffset, halfSize}, {xEndPos + xOffset, -halfSize}, }; - PagePainter::drawShapeOnImage(image, transformPath(path, combinedTransform), true, linePen, fillBrush, pageScale, PagePainter::Multiply); + PagePainter::drawShapeOnImage(image, transformPath(path, combinedTransform), true, linePen, fillBrush, pageScale); } void LineAnnotPainter::drawLeaderLine(double xEndPos, QImage &image, const QTransform &toNormalizedPage) const @@ -1262,7 +1262,7 @@ void LineAnnotPainter::drawLeaderLine(double xEndPos, QImage &image, const QTran path.append({xEndPos, 0}); } } - PagePainter::drawShapeOnImage(image, transformPath(path, combinedTransform), false, linePen, fillBrush, pageScale, PagePainter::Multiply); + PagePainter::drawShapeOnImage(image, transformPath(path, combinedTransform), false, linePen, fillBrush, pageScale); } double LineAnnotPainter::shortenForArrow(double size, Okular::LineAnnotation::TermStyle endStyle) diff --git a/ui/pagepainter.h b/ui/pagepainter.h index 6ee868d5a..58bfd0564 100644 --- a/ui/pagepainter.h +++ b/ui/pagepainter.h @@ -91,7 +91,7 @@ private: static void drawShapeOnImage(QImage &image, const NormalizedPath &normPath, bool closeShape, const QPen &pen, const QBrush &brush = QBrush(), double penWidthMultiplier = 1.0, RasterOperation op = Normal // float antiAliasRadius = 1.0 ); - static void drawEllipseOnImage(QImage &image, const NormalizedPath &rect, const QPen &pen, const QBrush &brush, double penWidthMultiplier, RasterOperation op); + static void drawEllipseOnImage(QImage &image, const NormalizedPath &rect, const QPen &pen, const QBrush &brush, double penWidthMultiplier, RasterOperation op = Normal); friend class LineAnnotPainter; }; From 1c7c7275e1fc38f304d03589e034a550e45e4c3f Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Fri, 7 Aug 2020 00:36:29 +0200 Subject: [PATCH 2/2] buildPen: honor annotation opacity Otherwise changing the opacity of lines/arrows does nothing --- ui/pagepainter.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ui/pagepainter.cpp b/ui/pagepainter.cpp index dab6a4f07..4159981bc 100644 --- a/ui/pagepainter.cpp +++ b/ui/pagepainter.cpp @@ -43,7 +43,9 @@ Q_GLOBAL_STATIC_WITH_ARGS(QPixmap, busyPixmap, (KIconLoader::global()->loadIcon( inline QPen buildPen(const Okular::Annotation *ann, double width, const QColor &color) { - QPen p(QBrush(color), width, ann->style().lineStyle() == Okular::Annotation::Dashed ? Qt::DashLine : Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin); + QColor c = color; + c.setAlphaF(ann->style().opacity()); + QPen p(QBrush(c), width, ann->style().lineStyle() == Okular::Annotation::Dashed ? Qt::DashLine : Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin); return p; }