diff --git a/ui/data/CMakeLists.txt b/ui/data/CMakeLists.txt index 0734f1a0b..2fc16e29a 100644 --- a/ui/data/CMakeLists.txt +++ b/ui/data/CMakeLists.txt @@ -9,12 +9,12 @@ install(FILES # install annotation tool images install(FILES tool-base-okular.png - tool-highlighter-okular.png - tool-ink-okular.png + tool-highlighter-okular-colorizable.png + tool-ink-okular-colorizable.png tool-note.png - tool-note-okular.png + tool-note-okular-colorizable.png tool-note-inline.png - tool-note-inline-okular.png + tool-note-inline-okular-colorizable.png tool-stamp-okular.png DESTINATION ${DATA_INSTALL_DIR}/okular/pics) # install annotation page images diff --git a/ui/data/sources/tool-highlighter-okular-colorizable.svgz b/ui/data/sources/tool-highlighter-okular-colorizable.svgz new file mode 100644 index 000000000..6d482b90f Binary files /dev/null and b/ui/data/sources/tool-highlighter-okular-colorizable.svgz differ diff --git a/ui/data/sources/tool-ink-okular-colorizable.svgz b/ui/data/sources/tool-ink-okular-colorizable.svgz new file mode 100644 index 000000000..52c412293 Binary files /dev/null and b/ui/data/sources/tool-ink-okular-colorizable.svgz differ diff --git a/ui/data/sources/tool-note-inline-okular-colorizable.svgz b/ui/data/sources/tool-note-inline-okular-colorizable.svgz new file mode 100644 index 000000000..aecc47309 Binary files /dev/null and b/ui/data/sources/tool-note-inline-okular-colorizable.svgz differ diff --git a/ui/data/sources/tool-note-okular-colorizable.svgz b/ui/data/sources/tool-note-okular-colorizable.svgz new file mode 100644 index 000000000..328ab91c4 Binary files /dev/null and b/ui/data/sources/tool-note-okular-colorizable.svgz differ diff --git a/ui/data/tool-highlighter-okular-colorizable.png b/ui/data/tool-highlighter-okular-colorizable.png new file mode 100644 index 000000000..8e7db875f Binary files /dev/null and b/ui/data/tool-highlighter-okular-colorizable.png differ diff --git a/ui/data/tool-ink-okular-colorizable.png b/ui/data/tool-ink-okular-colorizable.png new file mode 100644 index 000000000..a79c37f0a Binary files /dev/null and b/ui/data/tool-ink-okular-colorizable.png differ diff --git a/ui/data/tool-note-inline-okular-colorizable.png b/ui/data/tool-note-inline-okular-colorizable.png new file mode 100644 index 000000000..b3f7c186f Binary files /dev/null and b/ui/data/tool-note-inline-okular-colorizable.png differ diff --git a/ui/data/tool-note-okular-colorizable.png b/ui/data/tool-note-okular-colorizable.png new file mode 100644 index 000000000..01ade5e6c Binary files /dev/null and b/ui/data/tool-note-okular-colorizable.png differ diff --git a/ui/guiutils.cpp b/ui/guiutils.cpp index 1d67d3ad7..4ae75e4b2 100644 --- a/ui/guiutils.cpp +++ b/ui/guiutils.cpp @@ -240,4 +240,43 @@ Okular::Movie* renditionMovieFromScreenAnnotation( const Okular::ScreenAnnotatio return 0; } +// from Arthur - qt4 +inline int qt_div_255(int x) { return (x + (x>>8) + 0x80) >> 8; } + +void colorizeImage( QImage & grayImage, const QColor & color, unsigned int destAlpha ) +{ + // Make sure that the image is Format_ARGB32_Premultiplied + if ( grayImage.format() != QImage::Format_ARGB32_Premultiplied ) + grayImage = grayImage.convertToFormat( QImage::Format_ARGB32_Premultiplied ); + + // iterate over all pixels changing the alpha component value + unsigned int * data = (unsigned int *)grayImage.bits(); + unsigned int pixels = grayImage.width() * grayImage.height(); + int red = color.red(), + green = color.green(), + blue = color.blue(); + + int source, sourceSat, sourceAlpha; + for( register unsigned int i = 0; i < pixels; ++i ) + { // optimize this loop keeping byte order into account + source = data[i]; + sourceSat = qRed( source ); + int newR = qt_div_255( sourceSat * red ), + newG = qt_div_255( sourceSat * green ), + newB = qt_div_255( sourceSat * blue ); + if ( (sourceAlpha = qAlpha( source )) == 255 ) + { + // use destAlpha + data[i] = qRgba( newR, newG, newB, destAlpha ); + } + else + { + // use destAlpha * sourceAlpha product + if ( destAlpha < 255 ) + sourceAlpha = qt_div_255( destAlpha * sourceAlpha ); + data[i] = qRgba( newR, newG, newB, sourceAlpha ); + } + } +} + } diff --git a/ui/guiutils.h b/ui/guiutils.h index 2ae4ab3d3..df7a6b109 100644 --- a/ui/guiutils.h +++ b/ui/guiutils.h @@ -12,6 +12,8 @@ #include +class QColor; +class QImage; class QPixmap; class QSize; class QWidget; @@ -51,6 +53,9 @@ namespace GuiUtils * a media rendition. */ Okular::Movie* renditionMovieFromScreenAnnotation( const Okular::ScreenAnnotation * annotation ); + + // colorize a gray image to the given color + void colorizeImage( QImage & image, const QColor & color, unsigned int alpha = 255 ); } diff --git a/ui/pagepainter.cpp b/ui/pagepainter.cpp index 91ae211fb..5390dae9a 100644 --- a/ui/pagepainter.cpp +++ b/ui/pagepainter.cpp @@ -720,7 +720,7 @@ void PagePainter::paintCroppedPageOnPainter( QPainter * destPainter, const Okula // use it to colorize the icon, otherwise the icon will be // "gray" if ( a->style().color().isValid() ) - colorizeImage( scaledImage, a->style().color(), opacity ); + GuiUtils::colorizeImage( scaledImage, a->style().color(), opacity ); pixmap = QPixmap::fromImage( scaledImage ); // draw the mangled image to painter @@ -926,39 +926,6 @@ void PagePainter::changeImageAlpha( QImage & image, unsigned int destAlpha ) } } -void PagePainter::colorizeImage( QImage & grayImage, const QColor & color, - unsigned int destAlpha ) -{ - // iterate over all pixels changing the alpha component value - unsigned int * data = (unsigned int *)grayImage.bits(); - unsigned int pixels = grayImage.width() * grayImage.height(); - int red = color.red(), - green = color.green(), - blue = color.blue(); - - int source, sourceSat, sourceAlpha; - for( register unsigned int i = 0; i < pixels; ++i ) - { // optimize this loop keeping byte order into account - source = data[i]; - sourceSat = qRed( source ); - int newR = qt_div_255( sourceSat * red ), - newG = qt_div_255( sourceSat * green ), - newB = qt_div_255( sourceSat * blue ); - if ( (sourceAlpha = qAlpha( source )) == 255 ) - { - // use destAlpha - data[i] = qRgba( newR, newG, newB, destAlpha ); - } - else - { - // use destAlpha * sourceAlpha product - if ( destAlpha < 255 ) - sourceAlpha = qt_div_255( destAlpha * sourceAlpha ); - data[i] = qRgba( newR, newG, newB, sourceAlpha ); - } - } -} - void PagePainter::drawShapeOnImage( QImage & image, const NormalizedPath & normPath, diff --git a/ui/pagepainter.h b/ui/pagepainter.h index 42a73130f..830c9fe49 100644 --- a/ui/pagepainter.h +++ b/ui/pagepainter.h @@ -63,10 +63,6 @@ class PagePainter // set the alpha component of the image to a given value static void changeImageAlpha( QImage & image, unsigned int alpha ); - // colorize a gray image to the given color - static void colorizeImage( QImage & image, const QColor & color, - unsigned int alpha = 255 ); - // my pretty dear raster function typedef QList< Okular::NormalizedPoint > NormalizedPath; enum RasterOperation { Normal, Multiply }; diff --git a/ui/pageviewannotator.cpp b/ui/pageviewannotator.cpp index d387e4cd8..13382edc3 100644 --- a/ui/pageviewannotator.cpp +++ b/ui/pageviewannotator.cpp @@ -36,6 +36,7 @@ #include "core/annotations.h" #include "settings.h" #include "annotationtools.h" +#include "guiutils.h" #include "pageview.h" /** @short PickPointEngine */ @@ -996,20 +997,13 @@ void PageViewAnnotator::detachAnnotation() QPixmap PageViewAnnotator::makeToolPixmap( const QDomElement &toolElement ) { QPixmap pixmap( 32, 32 ); - QString iconName; - const QString annotType = toolElement.attribute( "type" ); - if ( annotType == "note-linked" ) - iconName = "tool-note-okular"; - else if ( annotType == "note-inline" ) - iconName = "tool-note-inline-okular"; - else if ( annotType == "ink" ) - iconName = "tool-ink-okular"; - else if ( annotType == "highlight" ) - iconName = "tool-highlighter-okular"; - else if ( annotType == "stamp" ) - iconName = "tool-stamp-okular"; + if ( annotType == "stamp" ) + { + // Load static image file + pixmap.load( KStandardDirs::locate( "data", "okular/pics/tool-stamp-okular.png" ) ); + } else { // Load base pixmap. We'll draw on top of it @@ -1033,6 +1027,38 @@ QPixmap PageViewAnnotator::makeToolPixmap( const QDomElement &toolElement ) p.setPen( QPen( engineColor, 2 ) ); p.drawEllipse( 2, 7, 21, 14 ); } + else if ( annotType == "highlight" ) + { + QImage overlay( KStandardDirs::locate( "data", "okular/pics/tool-highlighter-okular-colorizable.png" ) ); + QImage colorizedOverlay = overlay; + GuiUtils::colorizeImage( colorizedOverlay, engineColor ); + + p.drawImage( QPoint(0,0), colorizedOverlay ); // Trail + p.drawImage( QPoint(0,-32), overlay ); // Text + Shadow (uncolorized) + p.drawImage( QPoint(0,-64), colorizedOverlay ); // Pen + } + else if ( annotType == "ink" ) + { + QImage overlay( KStandardDirs::locate( "data", "okular/pics/tool-ink-okular-colorizable.png" ) ); + QImage colorizedOverlay = overlay; + GuiUtils::colorizeImage( colorizedOverlay, engineColor ); + + p.drawImage( QPoint(0,0), colorizedOverlay ); // Trail + p.drawImage( QPoint(0,-32), overlay ); // Shadow (uncolorized) + p.drawImage( QPoint(0,-64), colorizedOverlay ); // Pen + } + else if ( annotType == "note-inline" ) + { + QImage overlay( KStandardDirs::locate( "data", "okular/pics/tool-note-inline-okular-colorizable.png" ) ); + GuiUtils::colorizeImage( overlay, engineColor ); + p.drawImage( QPoint(0,0), overlay ); + } + else if ( annotType == "note-linked" ) + { + QImage overlay( KStandardDirs::locate( "data", "okular/pics/tool-note-okular-colorizable.png" ) ); + GuiUtils::colorizeImage( overlay, engineColor ); + p.drawImage( QPoint(0,0), overlay ); + } else if ( annotType == "polygon" ) { QPainterPath path; @@ -1090,13 +1116,6 @@ QPixmap PageViewAnnotator::makeToolPixmap( const QDomElement &toolElement ) } } - if ( !iconName.isEmpty() ) - { - // Load static image file - const QString fileName = "okular/pics/" + iconName + ".png"; - pixmap.load( KStandardDirs::locate( "data", fileName ) ); - } - return pixmap; }