@ -33,6 +33,7 @@
# include <kdebug.h>
# include <qpainter.h>
# include <qbitmap.h>
# include <qtooltip.h>
# include <qwidgetlist.h>
# include <qobjectlist.h>
@ -65,8 +66,7 @@ KMSystemTray::KMSystemTray(QWidget *parent, const char *name)
kdDebug ( 5006 ) < < " Initting systray " < < endl ;
mDefaultIcon = loadIcon ( " kmail " ) ;
mTransparentIcon = loadIcon ( " kmail " ) ;
KIconEffect : : semiTransparent ( mTransparentIcon ) ;
mLightIconImage = loadIcon ( " kmaillight " ) . convertToImage ( ) ;
setPixmap ( mDefaultIcon ) ;
@ -163,20 +163,42 @@ void KMSystemTray::updateCount()
countFont . setPointSizeFloat ( countFontSize ) ;
}
QPixmap bg ( oldPixmapWidth , oldPixmapHeight ) ;
bg . fill ( this , 0 , 0 ) ;
/** Overlay count on transparent icon */
QPainter p ( & bg ) ;
p . drawPixmap ( 0 , 0 , mTransparentIcon ) ;
p . setFont ( countFont ) ;
p . setPen ( Qt : : blue ) ;
p . drawText ( pixmap ( ) - > rect ( ) , Qt : : AlignCenter , countString ) ;
setPixmap ( bg ) ;
// Create an image which represents the number of unread messages
// and which has a transparent background.
// Unfortunately this required the following twisted code because for some
// reason text that is drawn on a transparent pixmap is invisible
// (apparently the alpha channel isn't changed when the text is drawn).
// Therefore I have to draw the text on a solid background and then remove
// the background by making it transparent with QPixmap::setMask. This
// involves the slow createHeuristicMask() function (from the API docs:
// "This function is slow because it involves transformation to a QImage,
// non-trivial computations and a transformation back to a QBitmap."). Then
// I have to convert the resulting QPixmap to a QImage in order to overlay
// the light KMail icon with the number (because KIconEffect::overlay only
// works with QImage). Finally the resulting QImage has to be converted
// back to a QPixmap.
// That's a lot of work for overlaying the KMail icon with the number of
// unread messages, but every other approach I tried failed miserably.
// IK, 2003-09-22
QPixmap numberPixmap ( oldPixmapWidth , oldPixmapHeight ) ;
numberPixmap . fill ( Qt : : white ) ;
QPainter p ( & numberPixmap ) ;
p . setFont ( countFont ) ;
p . setPen ( Qt : : blue ) ;
p . drawText ( numberPixmap . rect ( ) , Qt : : AlignCenter , countString ) ;
numberPixmap . setMask ( numberPixmap . createHeuristicMask ( ) ) ;
QImage numberImage = numberPixmap . convertToImage ( ) ;
// Overlay the light KMail icon with the number image
QImage iconWithNumberImage = mLightIconImage . copy ( ) ;
KIconEffect : : overlay ( iconWithNumberImage , numberImage ) ;
QPixmap iconWithNumber ;
iconWithNumber . convertFromImage ( iconWithNumberImage ) ;
setPixmap ( iconWithNumber ) ;
} else
{
setPixmap ( mDefaultIcon ) ;
setPixmap ( mDefaultIcon ) ;
}
}