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

List:       kget
Subject:    Re: [Kget] [PATCH] KGet Tray Icon and its Overlay
From:       Fabian Henze <flyser42 () gmx ! de>
Date:       2009-04-25 22:11:33
Message-ID: 200904260011.34003.flyser42 () gmx ! de
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]

[Attachment #6 (multipart/alternative)]


On Saturday 25th April 2009 16:45:15 UTC, I wrote:
> Yeah, I noticed that too today. I also found that Tray::blendOverlay() is a
> bit long winded (I think I will publish an updated patch later that day).
> However I still don't understand what Tray::paintIcon() does in detail (or
> rather why it does some things).

Hi, Here comes the updated version of the patch, it fixes the above issue and 
removes some unnecessary code parts.
I hope we can agree on this version :-)

-- Fabian Henze

[Attachment #9 (text/html)]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" \
"http://www.w3.org/TR/REC-html40/strict.dtd"><html><head><meta name="qrichtext" \
content="1" /><style type="text/css">p, li { white-space: pre-wrap; \
}</style></head><body style=" font-family:'DejaVu Sans'; font-size:10pt; \
font-weight:400; font-style:normal;">On Saturday 25th April 2009 16:45:15 UTC, I \
wrote:<br> &gt; Yeah, I noticed that too today. I also found that \
Tray::blendOverlay() is a<br> &gt; bit long winded (I think I will publish an updated \
patch later that day).<br> &gt; However I still don't understand what \
Tray::paintIcon() does in detail (or<br> &gt; rather why it does some things).<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"><br></p>Hi, Here comes the updated version of the patch, it fixes \
the above issue and removes some unnecessary code parts.<br> I hope we can agree on \
this version :-)<br> <p style="-qt-paragraph-type:empty; margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"><br></p>-- Fabian Henze</p></body></html>


["kget-tray-stop-blinking-v2.diff" (text/x-patch)]

--- kdenetwork-4.2.2/kget/ui/tray.h	2008-01-05 00:59:18.000000000 +0100
+++ kdenetwork-4.2.2/kget/ui/tray.h	2009-04-25 20:22:42.000000000 +0200
@@ -18,7 +18,6 @@
 
 class MainWindow;
 class KGet;
-class QTimer;
 class QPixmap;
 
 /**
@@ -50,17 +49,13 @@
      */
     void blendOverlay( QPixmap * sourcePixmap );
 
-    QTimer *blinkTimer;
     QPixmap *baseIcon, *grayedIcon, *alternateIcon;
-    QPixmap *playOverlay, *stopOverlay;
-    QPixmap *overlay;   //!< The current overlay (may be NULL)
-    bool iconOn;
-    bool overlayVisible;
-    bool m_running;
+    QPixmap *playOverlay;
+//  bool iconOn;
+    bool m_downloading;
 
 private slots:
     void slotActivated( QSystemTrayIcon::ActivationReason reason );
-    void slotTimeout();
 };
 
 #endif
--- kdenetwork-4.2.2/kget/ui/tray.cpp	2008-12-21 21:20:46.000000000 +0100
+++ kdenetwork-4.2.2/kget/ui/tray.cpp	2009-04-25 20:20:08.000000000 +0200
@@ -23,7 +23,6 @@
 #include <kmenu.h>
 #include <kdebug.h>
 
-#include <QTimer>
 #include <QPainter>
 #include <QLabel>
 #include <QClipboard>
@@ -34,16 +33,14 @@
   */
 Tray::Tray(MainWindow * parent)
     : KSystemTrayIcon(parent),
-      blinkTimer( 0 ),
       grayedIcon( 0 ),
       alternateIcon( 0 ),
-      overlay( 0 ),
-      overlayVisible( false ),
-      m_running( false )
+      playOverlay( 0 ),
+      m_downloading( false )
 {
     baseIcon = new QPixmap( KSystemTrayIcon::loadIcon("kget").pixmap(22) );
-    playOverlay = new QPixmap( SmallIcon( "media-playback-start" ) );
-    stopOverlay = new QPixmap( SmallIcon( "media-playback-pause" ) );
+    // 12x12 pixel overlay looks fine, amarok uses 10x10
+    playOverlay = new QPixmap( SmallIcon( "media-playback-start", 12 ) );
 
     paintIcon();
 
@@ -71,13 +68,10 @@
 // dtor: delete internal classes
 Tray::~Tray()
 {
-    delete blinkTimer;
     delete baseIcon;
     delete grayedIcon;
     delete alternateIcon;
     delete playOverlay;
-    delete stopOverlay;
-//    delete overlay;   // deleting overlay is wrong - it's either playOverlay or stopOverlay
 }
 
 // filter middle mouse clicks to ask scheduler to paste URL
@@ -98,57 +92,25 @@
     }*/
 }
 
-// display blinking icon when downloading
-void Tray::setDownloading( bool running )
+// display a play icon when downloading
+void Tray::setDownloading( bool downloading )
 {
-    if (running == m_running)
+    if (downloading == m_downloading)
         return;
 
-    m_running = running;
+    m_downloading = downloading;
     kDebug(5001) << "Tray::setDownloading";
 
-    if(!blinkTimer)
-    {
-        blinkTimer = new QTimer;
-        connect( blinkTimer, SIGNAL( timeout() ), this, SLOT( slotTimeout() ) );
-    }
-
-    overlayVisible = true;
-
-    if(running)
-    {
-        overlay = playOverlay;
-        blinkTimer->start( 1500 );  // start 'blink' timer
+    if (downloading)
         paintIcon( 50, true );
-    }
     else
-    {
-        overlay = stopOverlay;
-        blinkTimer->start( 1500 );  // start 'hide' timer
-        paintIcon( 50, true );
-    }
-}
+        paintIcon( -1, true );
 
-bool Tray::isDownloading()
-{
-    return m_running;
 }
 
-// slot executed every 1s: toggle icon pixmap
-void Tray::slotTimeout()
+bool Tray::isDownloading()
 {
-    if ( overlay == playOverlay )
-    {
-        overlayVisible = !overlayVisible;
-        paintIcon( 50/*mergeLevel*/, true );
-    }
-    else if( overlay == stopOverlay )
-    {
-        overlay = 0;
-        blinkTimer->stop();
-        paintIcon( -1, true );
-        overlayVisible = false;
-    }
+    return m_downloading;
 }
 
 void Tray::paintIcon( int mergePixels, bool force )
@@ -203,35 +165,20 @@
 
 void Tray::blendOverlay( QPixmap * sourcePixmap )
 {
-    if ( !overlayVisible || !overlay || overlay->isNull() )
+    if ( !m_downloading || !playOverlay || playOverlay->isNull() )
         return setIcon( *sourcePixmap );
 
-    // here comes the tricky part.. no kdefx functions are helping here.. :-(
+    // no kdefx functions are helping here.. :-(
     // we have to blend pixmaps with different sizes (blending will be done in
-    // the bottom-left corner of source pixmap with a smaller overlay pixmap)
-    int opW = overlay->width(),
-        opH = overlay->height(),
-        opX = 1,
+    // the bottom-right corner of source pixmap with a smaller overlay pixmap)
+    int opW = playOverlay->width(),
+        opH = playOverlay->height(),
+        opX = sourcePixmap->width() - opW,
         opY = sourcePixmap->height() - opH;
 
-    // get the rectangle where blending will take place 
-    QPixmap sourceCropped( opW, opH );
-    sourceCropped.fill(Qt::transparent);
-    QPainter paint;
-    paint.begin( &sourceCropped );
-    paint.drawPixmap( 0, 0, *sourcePixmap, opX, opY, opW,opH );
-    paint.end();
-
-    // blend the overlay image over the cropped rectangle
-    QImage blendedImage = sourceCropped.toImage();
-    QImage overlayImage = overlay->toImage();
-    KIconEffect::overlay( blendedImage, overlayImage );
-    sourceCropped = QPixmap().fromImage( blendedImage );
-
-    // put back the blended rectangle to the original image
     QPixmap sourcePixmapCopy = *sourcePixmap;
-    paint.begin( &sourcePixmapCopy );
-    paint.drawPixmap( opX, opY, sourceCropped, 0, 0, opW,opH );
+    QPainter paint( &sourcePixmapCopy );
+    paint.drawPixmap( opX, opY, *playOverlay );
     paint.end();
 
     setIcon( sourcePixmapCopy );

["signature.asc" (application/pgp-signature)]

_______________________________________________
Kget mailing list
Kget@kde.org
https://mail.kde.org/mailman/listinfo/kget


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

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