From 2b4bfa777bdce34def39ebe18138da864d17ddec Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Mon, 7 Apr 2008 00:14:29 +0000 Subject: [PATCH] improve a bit the drawing of geom annotations: - no more use a temporary image - do nothing if there is nothing to draw (0-width border, and no inner color) svn path=/trunk/KDE/kdegraphics/okular/; revision=794229 --- ui/pagepainter.cpp | 50 ++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/ui/pagepainter.cpp b/ui/pagepainter.cpp index 660f518a3..ef95babe6 100644 --- a/ui/pagepainter.cpp +++ b/ui/pagepainter.cpp @@ -585,31 +585,37 @@ void PagePainter::paintPageOnPainter( QPainter * destPainter, const Okular::Page else if ( type == Okular::Annotation::AGeom ) { Okular::GeomAnnotation * geom = (Okular::GeomAnnotation *)a; - QImage shape( annotBoundary.size(), QImage::Format_ARGB32 ); - shape.fill( qRgba( 0, 0, 0, 0 ) ); - // width is already divided by two - double width = geom->style().width() * Okular::Utils::dpiX() / ( 72.0 * 2.0 ) * scaledWidth / page->width(); - QPainter p( &shape ); - p.setPen( QPen( QBrush( acolor ), width * 2, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin ) ); - QRectF r( .0, .0, annotBoundary.width(), annotBoundary.height() ); - r.adjust( width, width, -width, -width ); - if ( geom->geometricalType() == Okular::GeomAnnotation::InscribedSquare ) - p.drawRect( r ); - else - p.drawEllipse( r ); - if ( geom->geometricalInnerColor().isValid() ) + // check whether there's anything to draw + if ( geom->style().width() || geom->geometricalInnerColor().isValid() ) { - p.setPen( Qt::NoPen ); - const QColor color = geom->geometricalInnerColor(); - p.setBrush( QColor( color.red(), color.green(), color.blue(), opacity ) ); + mixedPainter->save(); + const double width = geom->style().width() * Okular::Utils::dpiX() / ( 72.0 * 2.0 ) * scaledWidth / page->width(); + QRectF r( .0, .0, annotBoundary.width(), annotBoundary.height() ); r.adjust( width, width, -width, -width ); - if ( geom->geometricalType() == Okular::GeomAnnotation::InscribedSquare ) - p.drawRect( r ); - else - p.drawEllipse( r ); + r.translate( annotBoundary.topLeft() ); + if ( geom->geometricalInnerColor().isValid() ) + { + r.adjust( width, width, -width, -width ); + const QColor color = geom->geometricalInnerColor(); + mixedPainter->setPen( Qt::NoPen ); + mixedPainter->setBrush( QColor( color.red(), color.green(), color.blue(), opacity ) ); + if ( geom->geometricalType() == Okular::GeomAnnotation::InscribedSquare ) + mixedPainter->drawRect( r ); + else + mixedPainter->drawEllipse( r ); + r.adjust( -width, -width, width, width ); + } + if ( geom->style().width() ) // need to check the original size here.. + { + mixedPainter->setPen( QPen( QBrush( acolor ), width * 2, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin ) ); + mixedPainter->setBrush( Qt::NoBrush ); + if ( geom->geometricalType() == Okular::GeomAnnotation::InscribedSquare ) + mixedPainter->drawRect( r ); + else + mixedPainter->drawEllipse( r ); + } + mixedPainter->restore(); } - p.end(); - mixedPainter->drawImage( annotBoundary.topLeft(), shape ); } // draw extents rectangle