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

List:       kde-commits
Subject:    extragear/multimedia/amarok/src
From:       Jeff Mitchell <kde-dev () emailgoeshere ! com>
Date:       2007-07-01 7:22:46
Message-ID: 1183274566.630734.12514.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 682019 by mitchell:

This commit implements *true* alpha-blend fading for ContextBoxes in \
GraphicsItemFader, and it's fast too.  This means that varying backgrounds like  \
gradients and the like should correctly render.  This does mean that it won't work \
for pixmaps, so if we want to fade pixmaps we'd have to figure something  else out \
for them (although pixmaps contained in ContextBoxes should probably fade), or have \
the old method alongside.

One issue: Switching from QGraphicsTextItem to QGraphicsSimpleTextItem causes the \
title bars not to display...haven't figured out why yet.


 M  +1 -1      CMakeLists.txt  
 M  +4 -4      contextview/contextbox.cpp  
 M  +10 -2     contextview/contextbox.h  
 M  +4 -5      contextview/contextview.cpp  
 M  +23 -47    contextview/graphicsitemfader.cpp  
 M  +8 -13     contextview/graphicsitemfader.h  


--- trunk/extragear/multimedia/amarok/src/CMakeLists.txt #682018:682019
@@ -210,7 +210,7 @@
     contextview/GenericInfoBox.cpp
     contextview/graphicsitemfader.cpp
     contextview/textfader.cpp
-    contextview/introanimation.cpp
+    #    contextview/introanimation.cpp
     contextview/ContextScriptManager.cpp
     contextview/ContextObserver.cpp
     contextview/items/LyricsItem.cpp
--- trunk/extragear/multimedia/amarok/src/contextview/contextbox.cpp #682018:682019
@@ -17,7 +17,7 @@
 #include "debug.h"
 
 #include <QGraphicsItemAnimation>
-#include <QGraphicsTextItem>
+#include <QGraphicsSimpleTextItem>
 #include <QGraphicsScene>
 #include <QGraphicsSceneMouseEvent>
 #include <QRectF>
@@ -49,8 +49,8 @@
 
     m_titleBarRect = new QGraphicsRectItem( this, scene );
 
-    m_titleItem = new QGraphicsTextItem( "", m_titleBarRect, scene );
-    m_titleItem->setDefaultTextColor( QColor( 255, 255, 255 ) );
+    m_titleItem = new QGraphicsSimpleTextItem( "", m_titleBarRect );
+    m_titleItem->setBrush( QColor( 255, 255, 255 ) );
     // increase the font size for the title
     QFont font = m_titleItem->font();
     font.setPointSize( 12 );
@@ -83,7 +83,7 @@
 
 void ContextBox::setTitle( const QString &title )
 {
-    m_titleItem->setPlainText( title );
+    m_titleItem->setText( title );
     ensureTitleCentered();
 }
 
--- trunk/extragear/multimedia/amarok/src/contextview/contextbox.h #682018:682019
@@ -15,6 +15,7 @@
 #ifndef AMAROK_CONTEXTBOX_H
 #define AMAROK_CONTEXTBOX_H
 
+#include <QBrush>
 #include <QGraphicsSceneMouseEvent>
 #include <QGraphicsRectItem>
 #include <QTimeLine>
@@ -23,7 +24,10 @@
 class QGraphicsRectItem;
 class QGraphicsScene;
 class QGraphicsSceneMouseEvent;
+class QGraphicsSimpleTextItem;
+class QPainter;
 class QSize;
+class QStyleOptionGraphicsItem;
 
 namespace Context
 {
@@ -40,8 +44,11 @@
         virtual void toggleVisibility();
         virtual void ensureWidthFits( const qreal width );
 
-        virtual const QString title() { return m_titleItem->toPlainText(); }
+        virtual const QString title() { return m_titleItem->text(); }
 
+        QGraphicsRectItem* titleBarRect() { return m_titleBarRect; }
+        QGraphicsRectItem* contentRect() { return m_contentRect; }
+
     protected:
         virtual void mousePressEvent( QGraphicsSceneMouseEvent *event );
         virtual void mouseMoveEvent( QGraphicsSceneMouseEvent *event );
@@ -49,7 +56,7 @@
         void setContentRectSize( const QSizeF &sz, const bool synchroniseHeight = \
true );  void ensureTitleCentered();
 
-        QGraphicsTextItem *m_titleItem;
+        QGraphicsSimpleTextItem *m_titleItem;
         QGraphicsRectItem *m_titleBarRect;
         QGraphicsRectItem *m_contentRect;
 
@@ -57,6 +64,7 @@
         qreal m_optimumHeight;
         qreal m_animationIncrement;
         QTimeLine *m_animationTimer;
+        QBrush m_brush;
 
     protected slots:
         void visibilityTimerSlot();
--- trunk/extragear/multimedia/amarok/src/contextview/contextview.cpp #682018:682019
@@ -44,7 +44,7 @@
 
 using namespace Context;
 
-static bool enablePUD = false;
+static bool enablePUD = true;
 
 ContextView *ContextView::s_instance = 0;
 
@@ -304,9 +304,8 @@
     foreach( ContextBox* box, m_contextBoxes )
     {
         GraphicsItemFader *fader = new GraphicsItemFader( box );
-        fader->setFadeColor( palette().highlight().color() );
-        fader->setDuration( 3000 );
-        fader->setStartAlpha( 0 );
+        fader->setDuration( 1000 );
+        fader->setStartAlpha( 255 );
         fader->setTargetAlpha( 120 );
         m_pudFaders.append( fader );
     }
@@ -328,7 +327,7 @@
     foreach( GraphicsItemFader* fader, m_pudFaders )
     {
         fader->setStartAlpha( 120 );
-        fader->setTargetAlpha( 0 );
+        fader->setTargetAlpha( 255 );
     }
 
     foreach( GraphicsItemFader* fader, m_pudFaders )
--- trunk/extragear/multimedia/amarok/src/contextview/graphicsitemfader.cpp \
#682018:682019 @@ -17,6 +17,7 @@
  *   51 Franklin Street, Fifth Floor, Boston, MA  02111-1307, USA.          *
  ***************************************************************************/
 
+#include "contextbox.h"
 #include "graphicsitemfader.h"
 
 #include "debug.h"
@@ -26,33 +27,18 @@
 using namespace Context;
 
 
-GraphicsItemFader::GraphicsItemFader( QGraphicsItem * item, QGraphicsItem * parent )
+GraphicsItemFader::GraphicsItemFader( ContextBox *item )
     : QObject()
-    , QGraphicsItem( parent )
     , m_startAlpha( 0 )
     , m_targetAlpha( 255 )
     , m_fps ( 30 )
     , m_duration( 5000 )
 {
     m_contentItem = item;
-    m_itemPreviousParent = m_contentItem->parentItem();
-    m_contentItem->setParentItem( this );
-    m_contentItem->setZValue( 1 );
-    m_contentItem->setPos( 1, 1 );
 
-    m_shadeRectItem = new QGraphicsRectItem( this );
+    //m_fadeColor = QColor ( 255, 255, 255, 0 );
+    m_fadeColor = m_contentItem->brush().color();
 
-    m_width = m_contentItem->boundingRect().width() + 2;
-    m_height = m_contentItem->boundingRect().height() + 2;
-
-    m_shadeRectItem->setRect( 0, 0, m_width, m_height );
-    m_shadeRectItem->setPos( 0, 0 ); // needs a slight offset to cover frames on \
                m_contentItem
-    m_shadeRectItem->setPen( Qt::NoPen );
-    m_shadeRectItem->setZValue ( 2 );
-
-    m_fadeColor = QColor ( 255, 255, 255, 0 );
-    m_shadeRectItem->setBrush( QBrush ( m_fadeColor ) );
-
     m_timeLine = new QTimeLine( m_duration, this );
     connect( m_timeLine, SIGNAL( frameChanged( int ) ), this, SLOT( fadeSlot( int ) \
                ) );
     connect( m_timeLine, SIGNAL( finished() ), this, SLOT( fadeFinished() ) );
@@ -62,14 +48,12 @@
 {
     m_timeLine->stop();
     fadeSlot( m_animationSteps );
-    m_contentItem->setParentItem( m_itemPreviousParent );
 }
 
 void GraphicsItemFader::setStartAlpha(int alpha)
 {
     m_startAlpha = alpha;
     m_fadeColor.setAlpha( m_startAlpha );
-    m_shadeRectItem->setBrush( QBrush ( m_fadeColor ) );
 }
 
 void GraphicsItemFader::setTargetAlpha(int alpha)
@@ -87,29 +71,28 @@
     m_fps = fps;
 }
 
-QRectF Context::GraphicsItemFader::boundingRect() const
+void GraphicsItemFader::fadeSlot(int step)
 {
-    return QRect( x(), y(), m_width, m_height );
-}
+    qreal newAlpha = m_startAlpha + ( step * m_alphaStep );
+    m_fadeColor.setAlpha( (int)newAlpha );
 
+    QPen fadePen = m_contentItem->pen();
+    QColor penColor = fadePen.color();
+    penColor.setAlpha( (int)newAlpha );
+    fadePen.setColor( penColor );
+    m_contentItem->setPen( fadePen );
 
-void GraphicsItemFader::setFadeColor(const QColor & color)
-{
-    m_fadeColor = color;
-    m_fadeColor.setAlpha( m_startAlpha );
-    m_shadeRectItem->setBrush( QBrush ( m_fadeColor ) );
-}
+    QLinearGradient titleBarRectGradient(QPointF( 0, 0 ), QPointF( 0, \
m_contentItem->titleBarRect()->boundingRect().height() ) ); +    \
titleBarRectGradient.setColorAt( 0, QColor( 200, 200, 255, (int)newAlpha ) ); +    \
titleBarRectGradient.setColorAt( 1, QColor( 50, 50, 255, (int)newAlpha ) ); +    \
m_contentItem->titleBarRect()->setBrush( QBrush( titleBarRectGradient ) );  
-void GraphicsItemFader::fadeSlot(int step)
-{
-    int newAlpha = m_startAlpha + ( step * m_alphaStep );
-    m_fadeColor.setAlpha( newAlpha );
-    m_shadeRectItem->setBrush( QBrush ( m_fadeColor ) );
+    QLinearGradient contentRectGradient( QPointF( 0, 0 ), QPointF( 0, 10) );
+    contentRectGradient.setColorAt( 0, QColor( 150, 150, 150, (int)newAlpha ) );
+    contentRectGradient.setColorAt( 1, QColor( 255, 255, 255, (int)newAlpha ) );
+    m_contentItem->contentRect()->setBrush( QBrush( contentRectGradient ) );
 
-    if ( newAlpha == m_targetAlpha )
-        emit( animationComplete() );
-
-    debug() << "fading, new alpha = " << newAlpha <<  endl;
+    m_contentItem->update();
 }
 
 void GraphicsItemFader::fadeFinished()
@@ -123,10 +106,10 @@
     if( m_timeLine->state() != QTimeLine::NotRunning )
         m_timeLine->stop();
     //total number of animation steps;
-    m_animationSteps = m_fps * ( ( float ) m_duration / 1000.0 );
+    m_animationSteps = (int) ( m_fps * ( ( qreal ) m_duration / 1000.0 ) );
 
     //how much should alpha change each step
-    m_alphaStep = ( ( float ) ( m_targetAlpha - m_startAlpha ) ) / ( float ) \
m_animationSteps; +    m_alphaStep = ( ( qreal ) ( m_targetAlpha - m_startAlpha ) ) / \
( qreal ) m_animationSteps;  
     debug() << "Start fading, animationSteps = " << m_animationSteps << " over " << \
m_duration << " mseconds, alphaStep = " <<  m_alphaStep << endl;  
@@ -135,11 +118,4 @@
     m_timeLine->start();
 }
 
-void GraphicsItemFader::paint(QPainter * painter, const QStyleOptionGraphicsItem * \
                option, QWidget * widget)
-{
-    Q_UNUSED( painter );
-    Q_UNUSED( option );
-    Q_UNUSED( widget );
-}
-
 #include "graphicsitemfader.moc"
--- trunk/extragear/multimedia/amarok/src/contextview/graphicsitemfader.h \
#682018:682019 @@ -20,6 +20,8 @@
 #ifndef GRAPHICSITEMFADER_H
 #define GRAPHICSITEMFADER_H
 
+#include "contextbox.h"
+
 #include <QObject>
 #include <QGraphicsPixmapItem>
 #include <QGraphicsRectItem>
@@ -28,7 +30,6 @@
 namespace Context
 {
 
-
     /**
     A simple "widget" for the context view that provides a fading image
     Will be ported to use QGraphicsSvgItem once that successfully renders
@@ -36,24 +37,21 @@
 
 	@author Nikolaj Hald Nielsen <nhnFreespirit@gmail.com>
     */
-    class GraphicsItemFader : public QObject, public QGraphicsItem
+    class GraphicsItemFader : public QObject
     {
 
     Q_OBJECT
     public:
-        explicit GraphicsItemFader( QGraphicsItem * item, QGraphicsItem * parent = 0 \
); +        explicit GraphicsItemFader( ContextBox *item );
         ~GraphicsItemFader();
 
-        virtual QRectF boundingRect () const;
-        void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, \
                QWidget *widget );
-
         void setFadeColor( const QColor &color );
         void setStartAlpha( int alpha );
         void setTargetAlpha( int alpha );
         void setDuration( int ms );
         void setFPS( int fps );
         void startFading();
-        QGraphicsItem* contentItem() { return m_contentItem; }
+        ContextBox* contentItem() { return m_contentItem; }
 
     signals:
         void animationComplete();
@@ -63,22 +61,19 @@
         void fadeFinished();
 
     private:
-        QTimeLine * m_timeLine;
-        QGraphicsItem * m_contentItem;
-        QGraphicsRectItem * m_shadeRectItem;
-        QGraphicsItem * m_itemPreviousParent;
+        QTimeLine*  m_timeLine;
+        ContextBox* m_contentItem;
 
         QColor m_fadeColor;
         int m_startAlpha;
         int m_targetAlpha;
-        float m_alphaStep;
+        qreal m_alphaStep;
         int m_fps;
         int m_duration;
         int m_animationSteps;
         int m_width;
         int m_height;
 
-
     };
 
 }


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

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