From kget Thu Apr 23 20:57:35 2009 From: Fabian Henze Date: Thu, 23 Apr 2009 20:57:35 +0000 To: kget Subject: Re: [Kget] [PATCH] KGet Tray Icon and its Overlay Message-Id: <200904232257.37473.flyser42 () gmx ! de> X-MARC-Message: https://marc.info/?l=kget&m=124052031628043 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--Boundary-00=_BZN8JpI0Pmj2OTf" --Boundary-00=_BZN8JpI0Pmj2OTf Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Sorry I forgot to attach the actual patch, so here it comes... -- Fabian 'Flyser' Henze --Boundary-00=_BZN8JpI0Pmj2OTf Content-Type: text/x-patch; charset="UTF-8"; name="kget-stop-blinking.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="kget-stop-blinking.diff" --- 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-23 21:45:39.000000000 +0200 @@ -34,16 +34,15 @@ */ Tray::Tray(MainWindow * parent) : KSystemTrayIcon(parent), - blinkTimer( 0 ), grayedIcon( 0 ), alternateIcon( 0 ), - overlay( 0 ), - overlayVisible( false ), + playOverlay( 0 ), + playOverlayVisible( false ), m_running( 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 +70,11 @@ // 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 +// delete overlay; // deleting overlay is wrong - it's either playOverlay or stopOverlay } // filter middle mouse clicks to ask scheduler to paste URL @@ -107,26 +104,9 @@ m_running = running; 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 - paintIcon( 50, true ); - } - else - { - overlay = stopOverlay; - blinkTimer->start( 1500 ); // start 'hide' timer + playOverlayVisible = running; +// if(running) paintIcon( 50, true ); - } } bool Tray::isDownloading() @@ -134,23 +114,6 @@ return m_running; } -// slot executed every 1s: toggle icon pixmap -void Tray::slotTimeout() -{ - if ( overlay == playOverlay ) - { - overlayVisible = !overlayVisible; - paintIcon( 50/*mergeLevel*/, true ); - } - else if( overlay == stopOverlay ) - { - overlay = 0; - blinkTimer->stop(); - paintIcon( -1, true ); - overlayVisible = false; - } -} - void Tray::paintIcon( int mergePixels, bool force ) { // skip redrawing the same pixmap @@ -203,15 +166,15 @@ void Tray::blendOverlay( QPixmap * sourcePixmap ) { - if ( !overlayVisible || !overlay || overlay->isNull() ) + if ( !playOverlayVisible || !playOverlay || playOverlay->isNull() ) return setIcon( *sourcePixmap ); // here comes the tricky part.. 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 @@ -224,7 +187,7 @@ // blend the overlay image over the cropped rectangle QImage blendedImage = sourceCropped.toImage(); - QImage overlayImage = overlay->toImage(); + QImage overlayImage = playOverlay->toImage(); KIconEffect::overlay( blendedImage, overlayImage ); sourceCropped = QPixmap().fromImage( blendedImage ); --- 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-23 20:53:54.000000000 +0200 @@ -50,17 +50,14 @@ */ void blendOverlay( QPixmap * sourcePixmap ); - QTimer *blinkTimer; QPixmap *baseIcon, *grayedIcon, *alternateIcon; - QPixmap *playOverlay, *stopOverlay; - QPixmap *overlay; //!< The current overlay (may be NULL) + QPixmap *playOverlay; bool iconOn; - bool overlayVisible; + bool playOverlayVisible; bool m_running; private slots: void slotActivated( QSystemTrayIcon::ActivationReason reason ); - void slotTimeout(); }; #endif --Boundary-00=_BZN8JpI0Pmj2OTf Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Kget mailing list Kget@kde.org https://mail.kde.org/mailman/listinfo/kget --Boundary-00=_BZN8JpI0Pmj2OTf--