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

List:       kde-commits
Subject:    extragear/multimedia/amarok/src/context/applets/photos
From:       Simon Esneault <simon.esneault () gmail ! com>
Date:       2009-07-12 19:24:09
Message-ID: 1247426649.255658.27997.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 995453 by sesneault:

Automatic scroll mode nearly there...


 M  +13 -6     PhotosApplet.cpp  
 M  +192 -63   PhotosScrollWidget.cpp  
 M  +13 -6     PhotosScrollWidget.h  


--- trunk/extragear/multimedia/amarok/src/context/applets/photos/PhotosApplet.cpp \
#995452:995453 @@ -74,7 +74,15 @@
     connect( m_settingsIcon, SIGNAL( activated() ), this, SLOT( \
showConfigurationInterface() ) );  
     m_widget = new PhotosScrollWidget( this );
+    // Read config and inform the engine.
+    KConfigGroup config = Amarok::config("Photos Applet");
+    m_nbPhotos = config.readEntry( "NbPhotos", "10" ).toInt();
+    m_Animation = config.readEntry( "Animation", "Interactive" );
+    dataEngine( "amarok-photos" )->query( QString( "photos:nbphotos:" ) + \
QString().setNum( m_nbPhotos ) ); +    
+    m_widget->setMode( ui_Settings.animationComboBox->currentIndex() );
 
+    
     constraintsEvent();
 
     connectSource( "photos" );
@@ -82,12 +90,8 @@
              this, SLOT( connectSource( const QString & ) ) );
 
 
-    // Read config and inform the engine.
-    KConfigGroup config = Amarok::config("Photos Applet");
-    m_nbPhotos = config.readEntry( "NbPhotos", "10" ).toInt();
-    m_Animation = config.readEntry( "Animation", "Interactive" );
-    dataEngine( "amarok-photos" )->query( QString( "photos:nbphotos:" ) + \
QString().setNum( m_nbPhotos ) );  
+
 }
 
 PhotosApplet::~PhotosApplet()
@@ -208,8 +212,11 @@
     m_nbPhotos = ui_Settings.photosSpinBox->value();
     m_Animation = ui_Settings.animationComboBox->currentText();
     config.writeEntry( "NbPhotos", m_nbPhotos );
-    config.writeEntry( "Animation", m_Animation );    
+    config.writeEntry( "Animation", m_Animation );
+
+    m_widget->setMode( ui_Settings.animationComboBox->currentIndex() );
     
+    
     dataEngine( "amarok-photos" )->query( QString( "photos:nbphotos:" ) + \
QString().setNum( m_nbPhotos ) );  }
 
--- trunk/extragear/multimedia/amarok/src/context/applets/photos/PhotosScrollWidget.cpp \
#995452:995453 @@ -26,9 +26,11 @@
 
 // QT
 #include <QGraphicsPixmapItem>
+#include <QGraphicsItem>
 #include <QGraphicsSceneHoverEvent>
 #include <QList>
 #include <QPixmap>
+#include <QTimer>
 
 #define DEBUG_PREFIX "PhotosScrollWidget"
 
@@ -40,7 +42,10 @@
     , m_margin( 5 )
     , m_scrollmax( 0 )
     , m_actualpos( 0 )
+    , m_currentPix( 0 )
+    , m_timer( 1800 )
     , m_mode( PHOTOS_MODE_INTERACTIVE )
+    , m_delta( 0 )
 {
     setAcceptHoverEvents( true );
     setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
@@ -64,40 +69,26 @@
     foreach( QGraphicsItem *it, this->childItems() )
         delete it;
 
+    m_pixmaplist.clear();
     m_currentlist.clear();
     m_scrollmax = 0;
     m_actualpos = 0;
+    m_currentPix = 0;
 }
 
 
-void PhotosScrollWidget::setModeToInteractive()
+void PhotosScrollWidget::setMode( int mode )
 {
-    m_mode = PHOTOS_MODE_INTERACTIVE;
+    m_mode = mode;
     QList < PhotosInfo * > tmp = m_currentlist;
     clear();
     setPixmapList( tmp );
     tmp.clear();
 }
-void PhotosScrollWidget::setModeToAutomatic()
-{
-    m_mode = PHOTOS_MODE_AUTOMATIC;
-    QList < PhotosInfo * > tmp = m_currentlist;
-    clear();
-    setPixmapList( tmp );
-    tmp.clear();
-}
-void PhotosScrollWidget::setModeToFading()
-{
-    m_mode = PHOTOS_MODE_FADING;
-    QList < PhotosInfo * > tmp = m_currentlist;
-    clear();
-    setPixmapList( tmp );
-    tmp.clear();
-}
 
 void PhotosScrollWidget::setPixmapList (QList < PhotosInfo * > list)
 {
-    
+    DEBUG_BLOCK
     // if the list is the same, nothing happen.
     if ( list == m_currentlist )
         return;
@@ -122,10 +113,14 @@
                     dragpix->setPos( m_actualpos, 0 );
                     dragpix->SetClickableUrl( item->urlpage );
                     dragpix->show();
-
+                    
+                    m_pixmaplist << dragpix;
+                    
                     int delta = dragpix->boundingRect().width() + m_margin;
                     m_scrollmax += delta;
                     m_actualpos += delta;
+
+  
                 }
                 break;
             }
@@ -133,21 +128,33 @@
             {
                 if ( !m_currentlist.contains( item ) )
                 {
-                    if ( !m_id ) // carefull we're animating
-                    {
-                        Plasma::Animator::self()->stopCustomAnimation( m_id );
-                        m_id = 0;
-                    }
                     DragPixmapItem *dragpix = new DragPixmapItem( this );
                     dragpix->setPixmap( The::svgHandler()->addBordersToPixmap(
-                    item->photo->scaledToHeight( (int) size().height() - 4 * \
                m_margin,  Qt::SmoothTransformation ), 5, "", true ) );
-                    dragpix->setPos( m_actualpos, 0 );
+                        item->photo->scaledToHeight( (int) size().height() - 4 * \
m_margin,  Qt::SmoothTransformation ), 5, "", true ) );  dragpix->SetClickableUrl( \
                item->urlpage );
-                    dragpix->show();
+
+                    if ( m_id == 0 ) // only pos and show if
+                    {
+                        if ( ! m_pixmaplist.empty() )
+                        {
+                            dragpix->setPos( \
m_pixmaplist.last()->boundingRect().width() + m_pixmaplist.last()->pos().x() + \
m_margin, 0 ) ; +                            dragpix->show();
+                        }
+                        else
+                        {
+                            dragpix->setPos( 0, 0 ) ;
+                            dragpix->show();
+                        }
+                    }
                     
-                    int delta = dragpix->boundingRect().width() + m_margin;
-                    m_scrollmax += delta;
-                    m_actualpos += delta;
+                    m_pixmaplist << dragpix;
+
+                    // connect the end of the animation
+                    connect( Plasma::Animator::self(), SIGNAL( \
customAnimationFinished( int ) ), SLOT( automaticAnimEnd( int ) ) ); +                \
// set a timer after and launch +                    QTimer::singleShot( m_timer, \
this, SLOT( automaticAnimBegin() ) ); +
+                    
                 }
                 break;
             }
@@ -166,6 +173,8 @@
                     dragpix->setPos( m_actualpos, 0 );
                     dragpix->SetClickableUrl( item->urlpage );
                     dragpix->show();
+
+                    m_pixmaplist << dragpix;
                     
                     int delta = dragpix->boundingRect().width() + m_margin;
                     m_scrollmax += delta;
@@ -178,55 +187,175 @@
     m_currentlist = list;
 }
 
+
+void PhotosScrollWidget::hoverEnterEvent(QGraphicsSceneHoverEvent*)
+{
+    DEBUG_BLOCK
+    switch ( m_mode )
+    {
+        case PHOTOS_MODE_INTERACTIVE :
+        {
+            break;
+        }
+        
+        case PHOTOS_MODE_AUTOMATIC :
+        {
+            Plasma::Animator::self()->stopCustomAnimation( m_id );
+            m_id = 0;
+            break;
+        }
+        
+        case PHOTOS_MODE_FADING :
+        {            
+            break;
+        }
+    }
+}
+
+
 void PhotosScrollWidget::hoverLeaveEvent(QGraphicsSceneHoverEvent*)
 {
-//    DEBUG_BLOCK
-    Plasma::Animator::self()->stopCustomAnimation( m_id );
-    m_id = 0;
+    DEBUG_BLOCK
+    switch ( m_mode )
+    {
+        case PHOTOS_MODE_INTERACTIVE :
+        {
+            Plasma::Animator::self()->stopCustomAnimation( m_id );
+            m_id = 0;
+            break;
+        }
+        
+        case PHOTOS_MODE_AUTOMATIC :
+        {
+            QTimer::singleShot( m_timer, this, SLOT( automaticAnimBegin() ) );
+            break;
+        }
+        
+        case PHOTOS_MODE_FADING :
+        {
+            break;
+        }
+    }
 }
 
 void PhotosScrollWidget::hoverMoveEvent(QGraphicsSceneHoverEvent* event)
 {
- //   DEBUG_BLOCK
-    m_speed = ( event->pos().x() - ( size().width() / 2 ) ) / size().width();
-    m_speed*=20;
-    
-    // if m_id = 0, we don't have an animator yet, let's start the animation
-    if ( !m_id )
+    DEBUG_BLOCK
+    switch ( m_mode )
+    {                
+        case PHOTOS_MODE_INTERACTIVE :
+        {
+            m_speed = ( event->pos().x() - ( size().width() / 2 ) ) / \
size().width(); +            m_speed*=20;
+            // if m_id = 0, we don't have an animator yet, let's start the animation
+            if ( !m_id )
+                m_id = Plasma::Animator::self()->customAnimation( m_scrollmax / 2, \
m_scrollmax*10, Plasma::Animator::LinearCurve, this, "animate" ); +        }
+    }
+}
+
+void
+PhotosScrollWidget::automaticAnimBegin()
+{
+    if ( m_id == 0 )
     {
-        m_id = Plasma::Animator::self()->customAnimation( m_scrollmax / 2, \
m_scrollmax*10, Plasma::Animator::LinearCurve, this, "animate" ); +        \
DEBUG_BLOCK +        if ( m_currentPix < m_pixmaplist.size() - 1 )
+        {
+            m_delta = m_pixmaplist.at( m_currentPix )->boundingRect().width() + \
m_margin; +            m_id = Plasma::Animator::self()->customAnimation( m_delta * \
10, m_delta*20, Plasma::Animator::LinearCurve, this, "animate" ); +            \
m_currentPix++; +        }
+        else if ( m_currentPix == m_pixmaplist.size() - 1 )
+        {
+            m_currentPix = 0;
+            m_actualpos = 0;
+            m_delta = m_pixmaplist.at( m_currentPix )->boundingRect().width() + \
m_margin; +            m_id = Plasma::Animator::self()->customAnimation( m_delta , \
m_delta*20, Plasma::Animator::LinearCurve, this, "animate" ); +        }
     }
 }
 
-void PhotosScrollWidget::animate( qreal anim )
+void
+PhotosScrollWidget::automaticAnimEnd( int id )
 {
-    Q_UNUSED( anim );
-
-    // If we're are near the border and still asking to go higher !
-    if ( ( ( this->childItems().first()->pos().x() + \
this->childItems().first()->boundingRect().width() + 10 ) > \
this->boundingRect().width() ) && ( m_speed < 0 ) ) +    if ( id == m_id )
     {
+        if ( m_mode != PHOTOS_MODE_AUTOMATIC )
+            return;
+        DEBUG_BLOCK
         Plasma::Animator::self()->stopCustomAnimation( m_id );
         m_id = 0;
-        return;
+        QTimer::singleShot( m_timer, this, SLOT( automaticAnimBegin() ) );
     }
-    // If we're are near the border and still asking to go down
-    if ( ( ( this->childItems().last()->pos().x() - 10 ) < 0 ) && ( m_speed > 0 ) )
-    {        
-        Plasma::Animator::self()->stopCustomAnimation( m_id );
-        m_id = 0;
-        return;
-    }
+}
 
-    int right = 0;
-    foreach( QGraphicsItem *it, this->childItems() )
+
+void PhotosScrollWidget::animate( qreal )
+{
+    DEBUG_BLOCK
+    switch ( m_mode )
     {
-        qreal x = it->pos().x() - m_speed;
-        it->setPos( x, it->pos().y() );
-        it->update();
-        if ( x > right )
-            right = x + it->boundingRect().width() + m_margin;
-    }
-    m_actualpos = right;
+        case PHOTOS_MODE_INTERACTIVE :
+        {
+            // If we're are near the border and still asking to go higher !
+            if ( ( ( this->childItems().first()->pos().x() + \
this->childItems().first()->boundingRect().width() + 10 ) > \
this->boundingRect().width() ) && ( m_speed < 0 ) ) +            {
+                Plasma::Animator::self()->stopCustomAnimation( m_id );
+                m_id = 0;
+                return;
+            }
+            // If we're are near the border and still asking to go down
+            if ( ( ( this->childItems().last()->pos().x() - 10 ) < 0 ) && ( m_speed \
> 0 ) ) +            {
+                Plasma::Animator::self()->stopCustomAnimation( m_id );
+                m_id = 0;
+                return;
+            }
+
+            int right = 0;
+            foreach( QGraphicsItem *it, this->childItems() )
+            {
+                qreal x = it->pos().x() - m_speed;
+                it->setPos( x, it->pos().y() );
+                it->update();
+                if ( x > right )
+                    right = x + it->boundingRect().width() + m_margin;
+            }
+            m_actualpos = right;
+            break;
+        }
+        case PHOTOS_MODE_AUTOMATIC :
+        {
+            if ( !m_pixmaplist.empty() )
+            {
+
+                if ( ( m_pixmaplist.at( m_currentPix - 1 )->pos().x() + \
m_pixmaplist.at( m_currentPix - 1)->boundingRect().width() + m_margin )  <= ( - \
m_margin/2 + 1)) +                {
+                    automaticAnimEnd ( m_id );
+                    return;
+                }
+                
+                m_actualpos -= 1;
+                
+                for( int a = 0 ; a < m_pixmaplist.size(); a++ )
+                {
+                    if ( a == 0 )
+                        m_pixmaplist.at( a )->setPos( m_actualpos, m_pixmaplist.at( \
a )->pos().y() ); +                    else
+                        m_pixmaplist.at( a )->setPos( m_pixmaplist.at( a - 1 \
)->pos().x() + m_pixmaplist.at( a - 1 )->boundingRect().width() + m_margin - 1, \
m_pixmaplist.at( a )->pos().y() ); +                    m_pixmaplist.at( a )->show();
+                }
+            }
+            
+       //     m_actualpos = right;    
+            break;
+        }
+        case PHOTOS_MODE_FADING :
+        {
+            break;
+        }
+    }        
 }
 
 #include "PhotosScrollWidget.moc"
--- trunk/extragear/multimedia/amarok/src/context/applets/photos/PhotosScrollWidget.h \
#995452:995453 @@ -28,6 +28,7 @@
 //forward
 class QPixmap;
 class QGraphicsSceneHoverEvent;
+class DragPixmapItem;
 namespace Plasma
 {
     class Animator;
@@ -54,14 +55,14 @@
 
         void setPixmapList (QList < PhotosInfo * > );
 
-        void setModeToInteractive();
-        void setModeToAutomatic();
-        void setModeToFading();
+        void setMode( int );
         
         void clear();
 
     public slots:
         void animate( qreal anim );
+        void automaticAnimBegin();
+        void automaticAnimEnd( int );
         
     protected:
 
@@ -70,6 +71,7 @@
         */
         virtual void hoverMoveEvent(QGraphicsSceneHoverEvent* event);
         virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
+        virtual void hoverEnterEvent(QGraphicsSceneHoverEvent* event);
  //       virtual void keyPressEvent(QKeyEvent* event);
  //       virtual void wheelEvent(QGraphicsSceneWheelEvent* event);
         
@@ -79,9 +81,14 @@
         float   m_speed;        // if negative, go to left, if positif go to right,
         int     m_margin;       // margin beetween the photos
         int     m_scrollmax;    // lenght of the whole stack
-        int     m_actualpos;    // 
-        int     m_mode;         // 
-        QList < PhotosInfo * >m_currentlist; // contain the list of the current \
PhotosItem in the widget +        int     m_actualpos;    //
+        int     m_currentPix;   // index of the current pix
+        int     m_timer;        // time in ms beetween to change
+        int     m_mode;         //
+        int     m_delta;
+        int     m_deltastart;
+        QList < PhotosInfo * >      m_currentlist; // contain the list of the \
current PhotosItem in the widget +        QList < DragPixmapItem * >  m_pixmaplist;  \
// contain the list of dragpixmap item  };
 
 #endif // PHOTOSSCROLLWIDGET_H


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

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