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

List:       kde-commits
Subject:    playground/utils/rsibreak/src
From:       Bram Schoenmakers <bramschoenmakers () kde ! nl>
Date:       2006-03-31 22:00:45
Message-ID: 1143842445.577836.28771.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 525134 by bram:

Show colors on startup, when there's nothing known about the previous big/tiny break. \
But it can happen that colors in tooltip and statistics dialog are out of sync, \
though.



 M  +13 -17    rsiglobals.cpp  
 M  +2 -2      rsiglobals.h  
 M  +13 -5     rsistats.cpp  
 M  +4 -2      rsitooltip.cpp  


--- trunk/playground/utils/rsibreak/src/rsiglobals.cpp #525133:525134
@@ -120,30 +120,26 @@
     }
 }
 
-QColor RSIGlobals::getTinyBreakColor() const
+QColor RSIGlobals::getTinyBreakColor( int secsToBreak ) const
 {
     int minimized = m_intervals["tiny_minimized"];
-    QDateTime dt = m_stats->getStat( LAST_TINY_BREAK ).toDateTime();
-    if ( dt.isValid() )
-    {
-        double v = 100 * dt.secsTo( QDateTime::currentDateTime() ) / \
                (double)minimized;
-        return QColor ( (int)(2.55 * v), (int)(160 - 1.60 * v), 0 );
-    }
+    double v = 100 * secsToBreak / (double)minimized;
 
-    return KGlobalSettings::textColor();
+    v = v > 100 ? 100 : v;
+    v = v < 0 ? 0 : v;
+
+    return QColor ( (int)(255 - 2.55 * v), (int)(1.60 * v), 0 );
 }
 
-QColor RSIGlobals::getBigBreakColor() const
+QColor RSIGlobals::getBigBreakColor( int secsToBreak ) const
 {
-    int minimized = m_intervals["big_minimized"];
-    QDateTime dt = m_stats->getStat( LAST_BIG_BREAK ).toDateTime();
-    if ( dt.isValid() )
-    {
-        double v = 100 * dt.secsTo( QDateTime::currentDateTime() ) / \
                (double)minimized;
-        return QColor ( (int)(2.55 * v), (int)(160 - 1.60 * v), 0 );
-    }
+    int minimized = m_intervals["tiny_minimized"];
+    double v = 100 * secsToBreak / (double)minimized;
 
-    return KGlobalSettings::textColor();
+    v = v > 100 ? 100 : v;
+    v = v < 0 ? 0 : v;
+
+    return QColor ( (int)(255 - 2.55 * v), (int)(1.60 * v), 0 );
 }
 
 #include "rsiglobals.moc"
--- trunk/playground/utils/rsibreak/src/rsiglobals.h #525133:525134
@@ -100,13 +100,13 @@
      * This function returns a color ranging from green to red.
      * The more red, the more the user needs a tiny break.
      */
-    QColor getTinyBreakColor() const;
+    QColor getTinyBreakColor(int secsToBreak ) const;
 
     /**
      * This function returns a color ranging from green to red.
      * The more red, the more the user needs a tiny break.
      */
-    QColor getBigBreakColor() const;
+    QColor getBigBreakColor(int secsToBreak ) const;
 
   public slots:
     /**
--- trunk/playground/utils/rsibreak/src/rsistats.cpp #525133:525134
@@ -240,7 +240,11 @@
 
         case LAST_BIG_BREAK_COLOR:
         {
-            QColor c = RSIGlobals::instance()->getBigBreakColor();
+            QDateTime dt( m_statistics[ LAST_BIG_BREAK ].getValue().toDateTime() );
+            if ( !dt.isValid() )
+              dt = QDateTime::currentDateTime();
+            int left = RSIGlobals::instance()->intervals()["big_minimized"] - \
dt.secsTo( QDateTime::currentDateTime() ); +            QColor c = \
                RSIGlobals::instance()->getBigBreakColor( left );
             m_statistics[ LAST_BIG_BREAK \
].getDescription()->setPaletteForegroundColor( c );  m_labels[ LAST_BIG_BREAK \
]->setPaletteForegroundColor( c );  break;
@@ -248,10 +252,14 @@
 
         case LAST_TINY_BREAK_COLOR:
         {
-            QColor c = RSIGlobals::instance()->getTinyBreakColor();
-            m_statistics[ LAST_TINY_BREAK \
                ].getDescription()->setPaletteForegroundColor( c );
-            m_labels[ LAST_TINY_BREAK ]->setPaletteForegroundColor( c );
-            break;
+           QDateTime dt( m_statistics[ LAST_TINY_BREAK ].getValue().toDateTime() );
+           if ( !dt.isValid() )
+             dt = QDateTime::currentDateTime();
+           int left = RSIGlobals::instance()->intervals()["tiny_minimized"] - \
dt.secsTo( QDateTime::currentDateTime() ); +           QColor c = \
RSIGlobals::instance()->getTinyBreakColor( left ); +           m_statistics[ \
LAST_TINY_BREAK ].getDescription()->setPaletteForegroundColor( c ); +           \
m_labels[ LAST_TINY_BREAK ]->setPaletteForegroundColor( c ); +           break;
         }
 
         default: ;// nada
--- trunk/playground/utils/rsibreak/src/rsitooltip.cpp #525133:525134
@@ -62,8 +62,10 @@
         setText( i18n("Suspended") );
     else
     {
-        mTinyLeft->setPaletteForegroundColor( \
                RSIGlobals::instance()->getTinyBreakColor() );
-        mBigLeft->setPaletteForegroundColor( \
RSIGlobals::instance()->getBigBreakColor() ); +        \
mTinyLeft->setPaletteForegroundColor( RSIGlobals::instance()-> +            \
getTinyBreakColor( tiny_left ) ); +        mBigLeft->setPaletteForegroundColor( \
RSIGlobals::instance()-> +            getBigBreakColor( big_left ) );
 
         // Only add the line for the tiny break when there is not
         // a big break planned at the same time.


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

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