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

List:       kde-commits
Subject:    KDE/kdebase/workspace/libs/plasmagenericshell
From:       Aaron J. Seigo <aseigo () kde ! org>
Date:       2010-11-19 4:02:17
Message-ID: 20101119040217.5B9D3AC8A0 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1198594 by aseigo:

animate the transitions between the backgrounds; ++elegance. now to figure out why \
sometimes the layout doesn't lay the items out in the first place.


 M  +69 -16    abstracticon.cpp  
 M  +11 -0     abstracticon.h  


--- trunk/KDE/kdebase/workspace/libs/plasmagenericshell/abstracticon.cpp \
#1198593:1198594 @@ -26,6 +26,7 @@
 #include <QDebug>
 #include <QFontMetrics>
 #include <QGraphicsSceneMouseEvent>
+#include <QPropertyAnimation>
 #include <QStyleOptionGraphicsItem>
 #include <QPainter>
 
@@ -44,15 +45,18 @@
 AbstractIcon::AbstractIcon(QGraphicsItem *parent)
     : QGraphicsWidget(parent),
       m_background(new Plasma::FrameSvg(this)),
+      m_backgroundFadeAnim(0),
+      m_backgroundPrefix("normal"),
       m_iconHeight(DEFAULT_ICON_SIZE),
       m_maxSize(maximumSize()),
+      m_backgroundAlpha(1),
       m_selected(false),
       m_hovered(false)
 {
     setCacheMode(DeviceCoordinateCache);
     setAcceptHoverEvents(true);
+    m_background->setCacheAllRenderedFrames(true);
     m_background->setImagePath("widgets/tasks");
-    m_background->setElementPrefix("normal");
 }
 
 AbstractIcon::~AbstractIcon()
@@ -128,18 +132,24 @@
 void AbstractIcon::hoverEnterEvent(QGraphicsSceneHoverEvent *)
 {
     m_hovered = true;
+
+    m_backgroundPrefix = "hover";
+    m_oldBackgroundPrefix = m_selected ? "focus" : "normal";
+
     emit hoverEnter(this);
-    QMimeData *data = mimeData();
-    if (data && !data->formats().isEmpty()) {
+
+    fadeBackground(150);
     }
-    update();
-}
 
 void AbstractIcon::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
 {
     m_hovered = false;
     emit hoverLeave(this);
-    update();
+
+    m_backgroundPrefix = m_selected ? "focus" : "normal";
+    m_oldBackgroundPrefix = "hover";
+
+    fadeBackground(250);
 }
 
 void AbstractIcon::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
@@ -195,9 +205,18 @@
 {
     if (m_selected != selected) {
         m_selected = selected;
-        update();
+
+        if (m_selected) {
+            m_backgroundPrefix = "focus";
+            m_oldBackgroundPrefix = m_hovered ? "hover" : "normal";
+        } else {
+            m_backgroundPrefix = m_hovered ? "hover" : "normal";
+            m_oldBackgroundPrefix = "focus";
     }
+
+        fadeBackground(150);
 }
+}
 
 bool AbstractIcon::isSelected() const
 {
@@ -227,20 +246,24 @@
 
 void AbstractIcon::paintBackground(QPainter *painter, const QStyleOptionGraphicsItem \
*option, QWidget *)  {
-    if (m_hovered) {
-        m_background->setElementPrefix("hover");
+    if (!option->rect.isValid()) {
+        return;
+    }
 
-    } else if (m_selected) {
-        m_background->setElementPrefix("focus");
+    if (!m_backgroundFadeAnim || m_backgroundFadeAnim->state() != \
QAbstractAnimation::Running) { +        \
m_background->setElementPrefix(m_backgroundPrefix); +        \
m_background->paintFrame(painter); +        return;
+    }
 
-    } else {
-        m_background->setElementPrefix("normal");
+    m_background->setElementPrefix(m_oldBackgroundPrefix);
+    QPixmap bg = m_background->framePixmap();
 
+    m_background->setElementPrefix(m_backgroundPrefix);
+    bg = Plasma::PaintUtils::transition(bg, m_background->framePixmap(), \
m_backgroundAlpha); +    painter->drawPixmap(option->exposedRect, bg, \
option->exposedRect);  }
 
-    m_background->paintFrame(painter, option->rect, option->rect);
-}
-
 void AbstractIcon::paintForeground(QPainter *painter, const QStyleOptionGraphicsItem \
*, QWidget *)  {
     const QRectF rect = contentsRect();
@@ -268,6 +291,36 @@
     painter->drawText(textRect, flags, m_name);
 }
 
+qreal AbstractIcon::backgroundFadeAlpha() const
+{
+    return m_backgroundAlpha;
+}
+
+void AbstractIcon::setBackgroundFadeAlpha(qreal progress)
+{
+    m_backgroundAlpha = progress;
+    update();
+}
+
+void AbstractIcon::fadeBackground(int duration)
+{
+    if (m_oldBackgroundPrefix.isEmpty()) {
+        update();
+    } else {
+        if (!m_backgroundFadeAnim) {
+            m_backgroundFadeAnim = new QPropertyAnimation(this);
+            m_backgroundFadeAnim->setEasingCurve(QEasingCurve::InQuad);
+            m_backgroundFadeAnim->setPropertyName("backgroundFadeAlpha");
+            m_backgroundFadeAnim->setTargetObject(this);
+            m_backgroundFadeAnim->setStartValue(0);
+            m_backgroundFadeAnim->setEndValue(1);
+        }
+
+        m_backgroundFadeAnim->setDuration(duration);
+        m_backgroundFadeAnim->start();
+    }
+}
+
 } // namespace Plasma
 
 
--- trunk/KDE/kdebase/workspace/libs/plasmagenericshell/abstracticon.h \
#1198593:1198594 @@ -24,6 +24,8 @@
 #include <QGraphicsWidget>
 #include "plasmagenericshell_export.h"
 
+class QPropertyAnimation;
+
 namespace Plasma {
 
 class FrameSvg;
@@ -31,6 +33,7 @@
 class PLASMAGENERICSHELL_EXPORT AbstractIcon : public QGraphicsWidget
 {
     Q_OBJECT
+    Q_PROPERTY(qreal backgroundFadeAlpha READ backgroundFadeAlpha WRITE \
setBackgroundFadeAlpha)  
     public:
         explicit AbstractIcon(QGraphicsItem *parent = 0);
@@ -88,10 +91,18 @@
         void setDraggable(bool draggable);
 
     private:
+        qreal backgroundFadeAlpha() const;
+        void setBackgroundFadeAlpha(qreal progress);
+        void fadeBackground(int duration);
+
         Plasma::FrameSvg *m_background;
+        QPropertyAnimation *m_backgroundFadeAnim;
+        QString m_backgroundPrefix;
+        QString m_oldBackgroundPrefix;
         QString m_name;
         int m_iconHeight;
         QSizeF m_maxSize;
+        qreal m_backgroundAlpha;
         bool m_selected : 1;
         bool m_hovered : 1;
 };


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

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