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

List:       kde-commits
Subject:    playground/base/plasma/applets/tasks
From:       Robert Knight <robertknight () gmail ! com>
Date:       2007-08-01 3:26:50
Message-ID: 1185938810.211738.19391.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 694910 by knight:

Correct the fade out animation timing.  Use KColorScheme to get hover background \
colour.  Better margins around items.  Draw group title.

 M  +77 -33    tasks.cpp  
 M  +13 -2     tasks.h  


--- trunk/playground/base/plasma/applets/tasks/tasks.cpp #694909:694910
@@ -22,6 +22,8 @@
 #include "tasks.h"
 
 // KDE
+#include <KColorScheme>
+#include <KGlobalSettings>
 #include <KIcon>
 #include <KIconLoader>
 
@@ -37,8 +39,13 @@
  : Plasma::Applet(parent,arguments)
 {
     _rootTaskGroup = new TaskGroupItem(this);
-    _rootTaskGroup->setBorderStyle( TaskGroupItem::CaptionBorder );
 
+    // testing
+        _rootTaskGroup->setBorderStyle( TaskGroupItem::CaptionBorder );
+        _rootTaskGroup->setColor( QColor(207,255,204) );
+        _rootTaskGroup->setTitle( "Root Group" );
+
+
     prepareGeometryChange();
 
     // add representations of existing running tasks
@@ -137,6 +144,7 @@
 {
     setAcceptsHoverEvents(true);
     _fadeTimer = new QTimeLine();
+    _fadeTimer->setCurveShape(QTimeLine::LinearCurve);
 
     connect( _fadeTimer , SIGNAL(valueChanged(qreal)) ,
             this , SLOT(animationUpdate()) );
@@ -156,10 +164,11 @@
 QRectF AbstractTaskItem::boundingRect() const
 {
     QRectF rect = iconRect() | textRect(); 
-    rect.adjust( -TaskItemMargin,
-                 -TaskItemMargin,
-                 TaskItemMargin,
-                 TaskItemMargin );
+    rect.adjust( -TaskItemHorizontalMargin,
+                 -TaskItemVerticalMargin,
+                 TaskItemHorizontalMargin,
+                 TaskItemVerticalMargin );
+
     return rect; 
 }
 void AbstractTaskItem::finished()
@@ -173,19 +182,26 @@
 }
 void AbstractTaskItem::hoverEnterEvent( QGraphicsSceneHoverEvent* )
 {
+    const int FadeInDuration = 200;
+
     _fadeTimer->setDirection(QTimeLine::Forward);
-    _fadeTimer->setDuration(500);
+    _fadeTimer->setDuration(FadeInDuration);
 
     if ( _fadeTimer->state() != QTimeLine::Running )
         _fadeTimer->start();
 }
 void AbstractTaskItem::hoverLeaveEvent( QGraphicsSceneHoverEvent* )
 {
+    const int FadeOutDuration = 300;
+
     _fadeTimer->setDirection(QTimeLine::Backward);
-    _fadeTimer->setDuration(1000);
+    _fadeTimer->setDuration(FadeOutDuration);
 
     if ( _fadeTimer->state() != QTimeLine::Running )
+    {
+        _fadeTimer->setCurrentTime(FadeOutDuration);
         _fadeTimer->start();
+    }
 }
 
 void AbstractTaskItem::setIcon(const QIcon& icon)
@@ -195,6 +211,8 @@
 }
 void AbstractTaskItem::drawBackground(QPainter* painter, const \
QStyleOptionGraphicsItem* option, QWidget* )  {
+    KColorScheme colorScheme;
+
     if ( option->state & QStyle::State_MouseOver 
          || _fadeTimer->state() == QTimeLine::Running )
     {
@@ -202,8 +220,8 @@
                                   boundingRect().bottomLeft() );
 
    
-        QColor startColor = Qt::white;
-        QColor endColor = Qt::white;
+        QColor startColor = \
colorScheme.background(KColorScheme::NormalBackground).color(); +        QColor \
endColor = colorScheme.background(KColorScheme::NormalBackground).color();  
         const qreal pressedAlpha = 0.2;
         const qreal hoverAlpha = 0.4;
@@ -215,14 +233,7 @@
         else
             alpha = hoverAlpha;
       
-#if 0 
-        // foward direction goes 3x as fast
-        // as backwards direction
-        if ( _fadeTimer->direction() == QTimeLine::Forward )
-            alpha *= qMin(1.0,_fadeTimer->currentValue() * 3);
-        else
-#endif
-            alpha *= _fadeTimer->currentValue();
+        alpha *= _fadeTimer->currentValue();
 
         startColor.setAlphaF(alpha);
         endColor.setAlphaF(startColor.alphaF()+0.1);
@@ -232,7 +243,7 @@
 
         painter->setPen(QPen(Qt::NoPen));
         painter->setBrush(background);
-        painter->drawRoundRect(option->rect);
+        painter->drawRoundRect(option->rect,15,70);
     }
 }
 QRectF AbstractTaskItem::iconRect() const
@@ -320,11 +331,19 @@
     }
 
     _boundingRect = childrenBoundingRect().adjusted(-GroupBorderWidth,
-                                           -GroupBorderWidth,
-                                           GroupBorderWidth,
-                                           0);
+                                                    -titleHeight(),
+                                                    GroupBorderWidth,
+                                                    0);
 }
-
+qreal TaskGroupItem::titleHeight() 
+{
+    QFontMetrics titleFontMetrics(titleFont());
+    return titleFontMetrics.height();
+}
+QFont TaskGroupItem::titleFont()
+{
+    return KGlobalSettings::smallestReadableFont();
+}
 QRectF TaskGroupItem::boundingRect() const
 {
     return _boundingRect;
@@ -337,6 +356,9 @@
 {
     return _color;
 }
+void TaskGroupItem::setTitle(const QString& title) { _title = title; }
+QString TaskGroupItem::title() const { return _title; }
+
 void TaskGroupItem::setBorderStyle( BorderStyle style )
 {
     _borderStyle = style;
@@ -350,27 +372,49 @@
 {
     painter->setRenderHint(QPainter::Antialiasing);
 
-    drawBorder(painter,option->rect);    
+    // draw group border
+    // adjust area slightly to get a sharp border with anti-aliasing enabled
+    drawBorder(painter,QRectF(option->rect).adjusted(0.5,0.5,-0.5,-0.5));    
 }
 
-void TaskGroupItem::drawBorder(QPainter* painter , const QRect& area)
+void TaskGroupItem::drawBorder(QPainter* painter , const QRectF& area)
 {
+    QFont smallFont = KGlobalSettings::smallestReadableFont();
+    QFontMetrics smallFontMetrics(smallFont);
+
     if ( _borderStyle == CaptionBorder )
     {
-         const int titleHeight = 10;
-         const int cornerSize = 5;
+         const QRectF titleArea(area.top(),area.left(),area.width(),titleHeight());
+   //      const int cornerSize = 5;
 
-         QPainterPath borderPath(area.topLeft() + QPoint(0,titleHeight));
-         borderPath.quadTo( area.topLeft() , area.topLeft() + QPoint(cornerSize,0) \
                );
-         borderPath.lineTo( area.topRight() - QPoint(cornerSize,0) );
-         borderPath.quadTo( area.topRight() , area.topRight() + \
QPoint(0,titleHeight) ); + #if 0
+         QPainterPath borderPath(area.topLeft() + QPointF(0,titleSize));
+         borderPath.quadTo( area.topLeft() , area.topLeft() + QPointF(cornerSize,0) \
); +         borderPath.lineTo( area.topRight() - QPointF(cornerSize,0) );
+         borderPath.quadTo( area.topRight() , area.topRight() + QPointF(0,titleSize) \
);  borderPath.lineTo( area.bottomRight() );
          borderPath.lineTo( area.bottomLeft() );
-         borderPath.lineTo( area.topLeft() + QPoint(0,titleHeight) );
-         borderPath.lineTo( area.topRight() + QPoint(0,titleHeight) );
+         borderPath.lineTo( area.topLeft() + QPointF(0,titleSize) );
+         borderPath.lineTo( area.topRight() + QPointF(0,titleSize) );
 
-         painter->setBrush( QColor(255,0,0) );
+         
          painter->drawPath(borderPath);
+#endif
+
+         if ( _color.isValid() )
+            painter->setBrush( _color );
+       
+
+         painter->drawRect( area );
+
+         painter->setBrush( QColor(Qt::white) );
+         painter->drawRect( titleArea );
+
+         // draw caption
+         QFontMetricsF titleFontMetrics(titleFont());
+         painter->drawText( area.topLeft() + 
+                            QPointF(0,titleArea.height() - \
titleFontMetrics.descent()) +                            , _title );
     }
 }
 
--- trunk/playground/base/plasma/applets/tasks/tasks.h #694909:694910
@@ -225,7 +225,8 @@
     // distance (in pixels) between a task's icon and its text
     static const int IconTextSpacing = 4;
 
-    static const int TaskItemMargin = 4;
+    static const int TaskItemHorizontalMargin = 4;
+    static const int TaskItemVerticalMargin = 4;
 };
 
 /**     
@@ -317,6 +318,12 @@
     /** Returns the color of the group.  See setColor() */
     QColor color() const;
 
+    /**  Sets the group's title. */
+    void setTitle(const QString& title);
+
+    /** Returns the group's title. */
+    QString title() const;
+
     /** 
      * This enum describes the available methods for laying out 
      * tasks in the group.
@@ -350,12 +357,16 @@
 
 
 private:
-    void drawBorder(QPainter* painter , const QRect& area);
+    void drawBorder(QPainter* painter , const QRectF& area);
+    
+    static qreal titleHeight() ;
+    static QFont titleFont() ;
 
     QRectF _boundingRect;
     TaskLayout _taskLayout;
     BorderStyle _borderStyle;
     QColor _color;
+    QString _title;
 
     static const int GroupBorderWidth = 16;
 };


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

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