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

List:       kde-commits
Subject:    extragear/utils/rsibreak/src
From:       Aurélien Gâteau <agateau () kde ! org>
Date:       2011-04-03 22:06:01
Message-ID: 20110403220601.6B5F1AC8D1 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1226999 by gateau:

Ported tooltip

 M  +2 -1      rsidock.cpp  
 M  +32 -54    rsitooltip.cpp  
 M  +9 -20     rsitooltip.h  
 M  +2 -8      rsiwidget.cpp  


--- trunk/extragear/utils/rsibreak/src/rsidock.cpp #1226998:1226999
@@ -44,7 +44,8 @@
     setStatus(Active);
 
     const KAboutData* aboutData = KGlobal::mainComponent().aboutData();
-    setTitle( aboutData->appName() );
+    setTitle( aboutData->programName() );
+    setToolTipTitle( aboutData->programName() );
 
     m_help = new KHelpMenu( 0, aboutData );
 
--- trunk/extragear/utils/rsibreak/src/rsitooltip.cpp #1226998:1226999
@@ -22,83 +22,61 @@
 #include "rsistats.h"
 
 #include <KLocale>
-#include <KHBox>
-#include <KVBox>
+#include <KStatusNotifierItem>
 
-RSIToolTip::RSIToolTip( QWidget *parent, QSystemTrayIcon* icon )
-        : QWidget( parent ), m_icon( icon ), m_suspended( false )
-{
-    m_popup = new PassivePopup( parent );
-    m_popup->setTimeout( 4 * 1000 );
+#include <QTextDocument>
 
-    KHBox *hbox = new KHBox( m_popup );
-    hbox->setSpacing( 10 );
-
-    mIcon = new QLabel( hbox );
-    mIcon->resize( 32, 32 );
-
-    KVBox *vbox = new KVBox( hbox );
-    vbox->setSpacing( 5 );
-    new QLabel( "<qt><strong>RSIBreak</strong></qt>", vbox );
-    mTinyLeft = new QLabel( vbox );
-    mBigLeft = new QLabel( vbox );
-
-    m_popup->setView( hbox );
+RSIToolTip::RSIToolTip( QWidget *parent, KStatusNotifierItem* item )
+        : QObject( parent ), m_item( item ), m_suspended( false )
+{
 }
 
 RSIToolTip::~RSIToolTip() {}
 
+static QString colorizedText( const QString& text, const QColor& color )
+{
+    return QString("<font color='%1'>&#9679;</font> %2")
+        .arg(color.name())
+        .arg(Qt::escape(text))
+        ;
+}
+
 void RSIToolTip::setCounters( int tiny_left, int big_left )
 {
     if ( m_suspended )
-        setText( i18n( "Suspended" ) );
+        m_item->setToolTipSubTitle( i18n( "Suspended" ) );
     else {
-        QColor c = RSIGlobals::instance()->getTinyBreakColor( tiny_left );
-        QPalette normal;
-        normal.setColor( QPalette::Inactive, QPalette::WindowText, c );
-        mTinyLeft->setPalette( normal );
+        QColor tinyColor = RSIGlobals::instance()->getTinyBreakColor( tiny_left );
+        RSIGlobals::instance()->stats()->setColor( LAST_TINY_BREAK, tinyColor );
 
-        RSIGlobals::instance()->stats()->setColor( LAST_TINY_BREAK, c );
+        QColor bigColor = RSIGlobals::instance()-> getBigBreakColor( big_left );
+        RSIGlobals::instance()->stats()->setColor( LAST_BIG_BREAK, bigColor );
 
-        c = RSIGlobals::instance()-> getBigBreakColor( big_left );
-        normal.setColor( QPalette::Inactive, QPalette::WindowText, c );
-        mBigLeft->setPalette( normal );
-        RSIGlobals::instance()->stats()->setColor( LAST_BIG_BREAK, c );
-
         // Only add the line for the tiny break when there is not
         // a big break planned at the same time.
+
+        QStringList lines;
         if ( tiny_left != big_left ) {
             QString formattedText = RSIGlobals::instance()->formatSeconds( tiny_left \
);  if ( !formattedText.isNull() ) {
-                mTinyLeft->setText( i18n( "%1 remaining until next short break",
-                                          formattedText ) );
-            } else // minutes = 0 and seconds = 0, remove the old text.
-                mTinyLeft->clear();
-        } else // tiny_left eq. big_left, remove this line.
-            mTinyLeft->clear();
+                lines << colorizedText(
+                    i18n( "%1 remaining until next short break", formattedText ),
+                    tinyColor
+                    );
+            }
+        }
 
         // do the same for the big break
         if ( big_left > 0 )
-            mBigLeft->setText( i18n( "%1 remaining until next long break",
-                                     RSIGlobals::instance()->formatSeconds( big_left \
                ) ) );
-        else // minutes = 0 and seconds = 0, remove the old text.
-            mBigLeft->clear();
+            lines << colorizedText(
+                i18n( "%1 remaining until next long break",
+                    RSIGlobals::instance()->formatSeconds( big_left ) ),
+                bigColor
+                );
+        m_item->setToolTipSubTitle(lines.join("<br>"));
     }
 }
 
-void RSIToolTip::setText( const QString &text )
-{
-    QPalette normal;
-    mTinyLeft->setPalette( normal );
-    mTinyLeft->setText( text );
-    mBigLeft->clear();
-}
-
-void RSIToolTip::setPixmap( const QPixmap &pix )
-{
-    mIcon->setPixmap( pix );
-}
-
 void RSIToolTip::setSuspended( bool b )
 {
     m_suspended = b;
--- trunk/extragear/utils/rsibreak/src/rsitooltip.h #1226998:1226999
@@ -20,45 +20,34 @@
 #ifndef RSITOOLTIP_H
 #define RSITOOLTIP_H
 
-#include "passivepopup.h"
-#include <QPixmap>
-#include <QLabel>
+#include <QObject>
 
+class KStatusNotifierItem;
+
+class QPixmap;
+
 /**
  * @class RSIToolTip
  * This frame is shown as a tooltip, when the user hovers the
  * mouse above the docker's icon.
  * @author Bram Schoenmakers <bramschoenmakers@kde.nl>
  */
-class RSIToolTip : public QWidget
+class RSIToolTip : public QObject
 {
     Q_OBJECT
 public:
-    explicit RSIToolTip( QWidget *parent, QSystemTrayIcon* );
+    explicit RSIToolTip( QWidget *parent, KStatusNotifierItem* icon );
     ~RSIToolTip();
 
 public slots:
     void setCounters( int, int );
-    /** Sets the pixmap for the tooltip. */
-    void setPixmap( const QPixmap & );
     /** Sets the tooltip to suspended or unsuspended depending on the parameter. */
     void setSuspended( bool );
     /** Sets the tooltip to @param text */
-    void setText( const QString &text );
-    void setTimeout( int i ) {
-        m_popup->setTimeout( i );
-    };
-    void showToolTip() {
-        m_popup->show();
-    };
+    //void setText( const QString &text );
 
-
 private:
-    QLabel *mTinyLeft;
-    QLabel *mBigLeft;
-    QLabel *mIcon;
-    PassivePopup *m_popup;
-    QSystemTrayIcon *m_icon;
+    KStatusNotifierItem *m_item;
 
     bool m_suspended;
 };
--- trunk/extragear/utils/rsibreak/src/rsiwidget.cpp #1226998:1226999
@@ -62,10 +62,7 @@
     QDBusConnection dbus = QDBusConnection::sessionBus();
     dbus.registerObject( "/rsibreak", this );
 
-#warning FIXME
-    m_tooltip = 0;
-    //m_tooltip = new RSIToolTip( 0, m_tray );
-    //connect( m_tray, SIGNAL( showToolTip() ), m_tooltip, SLOT( showToolTip() ) );
+    m_tooltip = new RSIToolTip( 0, m_tray );
 
     m_relaxpopup = new RSIRelaxPopup( 0 );
     connect( m_relaxpopup, SIGNAL( lock() ), SLOT( slotLock() ) );
@@ -159,10 +156,8 @@
 
     if ( newIcon != m_currentIcon ) {
         m_tray->setIconByName( newIcon );
-
-        QPixmap toolPixmap = KIconLoader::global()->loadIcon( newIcon, \
KIconLoader::Desktop ); +        m_tray->setToolTipIconByName( newIcon );
         m_currentIcon = newIcon;
-        //m_tooltip->setPixmap( toolPixmap );
     }
 }
 
@@ -226,7 +221,6 @@
     connect( m_timer, SIGNAL( updateIdleAvg( double ) ), SLOT( updateIdleAvg( double \
                ) ), Qt::QueuedConnection );
     connect( m_timer, SIGNAL( minimize() ), SLOT( minimize() ),  \
                Qt::QueuedConnection );
     connect( m_timer, SIGNAL( relax( int, bool ) ), m_relaxpopup, SLOT( relax( int, \
                bool ) ), Qt::QueuedConnection );
-    connect( m_timer, SIGNAL( relax( int, bool ) ), m_tooltip, SLOT( hide() ), \
                Qt::QueuedConnection );
     connect( m_timer, SIGNAL( tinyBreakSkipped() ), SLOT( tinyBreakSkipped() ), \
                Qt::QueuedConnection );
     connect( m_timer, SIGNAL( bigBreakSkipped() ), SLOT( bigBreakSkipped() ), \
Qt::QueuedConnection );  


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

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