mirror of
https://invent.kde.org/graphics/okular
synced 2024-09-12 20:51:17 +00:00
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
This commit is contained in:
parent
ef4e1d7ab3
commit
9f41ff9d13
|
@ -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
|
||||
|
|
BIN
ui/data/sources/tool-highlighter-okular-colorizable.svgz
Normal file
BIN
ui/data/sources/tool-highlighter-okular-colorizable.svgz
Normal file
Binary file not shown.
BIN
ui/data/sources/tool-ink-okular-colorizable.svgz
Normal file
BIN
ui/data/sources/tool-ink-okular-colorizable.svgz
Normal file
Binary file not shown.
BIN
ui/data/sources/tool-note-inline-okular-colorizable.svgz
Normal file
BIN
ui/data/sources/tool-note-inline-okular-colorizable.svgz
Normal file
Binary file not shown.
BIN
ui/data/sources/tool-note-okular-colorizable.svgz
Normal file
BIN
ui/data/sources/tool-note-okular-colorizable.svgz
Normal file
Binary file not shown.
BIN
ui/data/tool-highlighter-okular-colorizable.png
Normal file
BIN
ui/data/tool-highlighter-okular-colorizable.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
BIN
ui/data/tool-ink-okular-colorizable.png
Normal file
BIN
ui/data/tool-ink-okular-colorizable.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
BIN
ui/data/tool-note-inline-okular-colorizable.png
Normal file
BIN
ui/data/tool-note-inline-okular-colorizable.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 515 B |
BIN
ui/data/tool-note-okular-colorizable.png
Normal file
BIN
ui/data/tool-note-okular-colorizable.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 670 B |
|
@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue