[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [okular/configurable-review-tools] ui: Paint some other annotation tool icons dynamically
From:       Fabio D'Urso <fabiodurso () hotmail ! it>
Date:       2012-12-28 17:35:51
Message-ID: 20121228173551.312FAA60DA () git ! kde ! org
[Download RAW message or body]

Git commit 9f41ff9d13d8763c7f45c0b54339b02197e456fd by Fabio D'Urso.
Committed on 12/06/2012 at 12:19.
Pushed by fabiod into branch 'configurable-review-tools'.

Paint some other annotation tool icons dynamically

Affected tools:
 - Note
 - Inline Note
 - Ink
 - Highlighter

Note that the Stamp tool is the only one that's left with a static icon

M  +4    -4    ui/data/CMakeLists.txt
A  +-    --    ui/data/sources/tool-highlighter-okular-colorizable.svgz
A  +-    --    ui/data/sources/tool-ink-okular-colorizable.svgz
A  +-    --    ui/data/sources/tool-note-inline-okular-colorizable.svgz
A  +-    --    ui/data/sources/tool-note-okular-colorizable.svgz
A  +-    --    ui/data/tool-highlighter-okular-colorizable.png
A  +-    --    ui/data/tool-ink-okular-colorizable.png
A  +-    --    ui/data/tool-note-inline-okular-colorizable.png
A  +-    --    ui/data/tool-note-okular-colorizable.png
M  +39   -0    ui/guiutils.cpp
M  +5    -0    ui/guiutils.h
M  +1    -34   ui/pagepainter.cpp
M  +0    -4    ui/pagepainter.h
M  +38   -19   ui/pageviewannotator.cpp

http://commits.kde.org/okular/9f41ff9d13d8763c7f45c0b54339b02197e456fd

diff --git a/ui/data/CMakeLists.txt b/ui/data/CMakeLists.txt
index 0734f1a..2fc16e2 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 0000000..6d482b9
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 0000000..52c4122
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 0000000..aecc473
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 0000000..328ab91
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 0000000..8e7db87
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 0000000..a79c37f
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 0000000..b3f7c18
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 0000000..01ade5e
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 1d67d3a..4ae75e4 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 2ae4ab3..df7a6b1 100644
--- a/ui/guiutils.h
+++ b/ui/guiutils.h
@@ -12,6 +12,8 @@
 
 #include <QtCore/QString>
 
+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 91ae211..5390dae 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 42a7313..830c9fe 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 d387e4c..13382ed 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;
 }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic