[vlc-commits] commit: Qt4: rework coverflow to use playlist model for art (Ilkka Ollakka )

git at videolan.org git at videolan.org
Sun Oct 31 12:06:57 CET 2010


vlc | branch: master | Ilkka Ollakka <ileoo at videolan.org> | Sun Oct 31 13:06:44 2010 +0200| [9c42dd144294eef79efb12b91f85dd3f3ccd2079] | committer: Ilkka Ollakka 

Qt4: rework coverflow to use playlist model for art

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9c42dd144294eef79efb12b91f85dd3f3ccd2079
---

 modules/gui/qt4/components/playlist/views.cpp |   25 +++----
 modules/gui/qt4/components/playlist/views.hpp |    4 +-
 modules/gui/qt4/util/pictureflow.cpp          |   93 ++----------------------
 modules/gui/qt4/util/pictureflow.hpp          |   35 +---------
 4 files changed, 23 insertions(+), 134 deletions(-)

diff --git a/modules/gui/qt4/components/playlist/views.cpp b/modules/gui/qt4/components/playlist/views.cpp
index 5d014e5..3b40a94 100644
--- a/modules/gui/qt4/components/playlist/views.cpp
+++ b/modules/gui/qt4/components/playlist/views.cpp
@@ -377,13 +377,12 @@ PicFlowView::PicFlowView( PLModel *p_model, QWidget *parent ) : QAbstractItemVie
 {
     QHBoxLayout *layout = new QHBoxLayout( this );
     layout->setMargin( 0 );
-    picFlow = new PictureFlow( this );
+    picFlow = new PictureFlow( this, p_model );
     picFlow->setSlideSize(QSize(128,128));
     layout->addWidget( picFlow );
     setSelectionMode( QAbstractItemView::SingleSelection );
     setModel( p_model );
 
-    //CONNECT( picFlow, centerIndexChanged(int), this, playItem(int) );
 }
 
 int PicFlowView::horizontalOffset() const
@@ -405,9 +404,9 @@ void PicFlowView::scrollTo(const QModelIndex &index, QAbstractItemView::ScrollHi
 {
      int currentIndex = picFlow->centerIndex();
      if( qAbs( currentIndex - index.row()) > 100 )
-        picFlow->setCenterIndex( index.row()-1);
+        picFlow->setCenterIndex( index.row());
      else
-        picFlow->showSlide( index.row()-1 );
+        picFlow->showSlide( index.row() );
 }
 
 QModelIndex PicFlowView::indexAt(const QPoint &) const
@@ -441,20 +440,18 @@ void PicFlowView::setSelection(const QRect &, QFlags<QItemSelectionModel::Select
     // No selection possible
 }
 
-void PicFlowView::rowsInserted(const QModelIndex &parent, int start, int end)
+void PicFlowView::dataChanged( const QModelIndex &topLeft, const QModelIndex &bottomRight )
 {
-    for( int i = start; i <= end; i++ )
+    int currentIndex = picFlow->centerIndex();
+    for(int i = topLeft.row(); i<=bottomRight.row(); i++ )
     {
-        const QModelIndex index = model()->index( i, 0, parent );
-        if( !index.isValid() )
+        if( i-5 <= currentIndex &&
+            i+5 >= currentIndex )
+        {
+            picFlow->render();
             return;
-
-        /* FIXME, this returns no art, so far */
-        QPixmap pix = PLModel::getArtPixmap( index, QSize(128,128) );
-        picFlow->addSlide(pix);
+        }
     }
-
-    picFlow->render();
 }
 
 void PicFlowView::playItem( int i_item )
diff --git a/modules/gui/qt4/components/playlist/views.hpp b/modules/gui/qt4/components/playlist/views.hpp
index b9313aa..88c0d43 100644
--- a/modules/gui/qt4/components/playlist/views.hpp
+++ b/modules/gui/qt4/components/playlist/views.hpp
@@ -116,8 +116,8 @@ protected:
 private:
     PictureFlow *picFlow;
 
-protected slots:
-    void rowsInserted ( const QModelIndex & parent, int start, int end );
+public slots:
+    void dataChanged( const QModelIndex &, const QModelIndex &);
 private slots:
     void playItem( int );
 };
diff --git a/modules/gui/qt4/util/pictureflow.cpp b/modules/gui/qt4/util/pictureflow.cpp
index 0bc83b8..82f08db 100644
--- a/modules/gui/qt4/util/pictureflow.cpp
+++ b/modules/gui/qt4/util/pictureflow.cpp
@@ -42,6 +42,7 @@
 #include <QTimer>
 #include <QVector>
 #include <QWidget>
+#include "../components/playlist/playlist_model.hpp" /* getArtPixmap etc */
 
 // for fixed-point arithmetic, we need minimum 32-bit long
 // long long (64-bit) might be useful for multiplication and division
@@ -136,13 +137,13 @@ public:
     int slideWidth;
     int slideHeight;
     PictureFlow::ReflectionEffect reflectionEffect;
-    QVector<QImage*> slideImages;
 
     int angle;
     int spacing;
     PFreal offsetX;
     PFreal offsetY;
 
+    PLModel *model;
     SlideInfo centerSlide;
     QVector<SlideInfo> leftSlides;
     QVector<SlideInfo> rightSlides;
@@ -214,8 +215,6 @@ PictureFlowState::PictureFlowState():
 
 PictureFlowState::~PictureFlowState()
 {
-    for (int i = 0; i < (int)slideImages.count(); i++)
-        delete slideImages[i];
 }
 
 // readjust the settings, call this when slide dimension is changed
@@ -594,40 +593,13 @@ QImage* PictureFlowSoftwareRenderer::surface(int slideIndex)
         return 0;
     if (slideIndex < 0)
         return 0;
-    if (slideIndex >= (int)state->slideImages.count())
+    if (slideIndex >= (int)state->model->rowCount())
         return 0;
 
     int key = slideIndex;
 
-    QImage* img = state->slideImages.at(slideIndex);
-    bool empty = img ? img->isNull() : true;
-    if (empty) {
-        surfaceCache.remove(key);
-        imageHash.remove(slideIndex);
-        if (!blankSurface) {
-            int sw = state->slideWidth;
-            int sh = state->slideHeight;
-
-            QImage img = QImage(sw, sh, QImage::Format_RGB32);
-
-            QPainter painter(&img);
-            QPoint p1(sw*4 / 10, 0);
-            QPoint p2(sw*6 / 10, sh);
-            QLinearGradient linearGrad(p1, p2);
-            linearGrad.setColorAt(0, Qt::black);
-            linearGrad.setColorAt(1, Qt::white);
-            painter.setBrush(linearGrad);
-            painter.fillRect(0, 0, sw, sh, QBrush(linearGrad));
-
-            painter.setPen(QPen(QColor(64, 64, 64), 4));
-            painter.setBrush(QBrush());
-            painter.drawRect(2, 2, sw - 3, sh - 3);
-            painter.end();
-
-            blankSurface = prepareSurface(&img, sw, sh, bgcolor, state->reflectionEffect);
-        }
-        return blankSurface;
-    }
+    QImage* img = new QImage(PLModel::getArtPixmap( state->model->index( slideIndex, 0, QModelIndex() ),
+                                         QSize( state->slideWidth, state->slideHeight ) ).toImage());
 
     bool exist = imageHash.contains(slideIndex);
     if (exist)
@@ -796,11 +768,12 @@ public:
 };
 
 
-PictureFlow::PictureFlow(QWidget* parent): QWidget(parent)
+PictureFlow::PictureFlow(QWidget* parent, PLModel* _p_model): QWidget(parent)
 {
     d = new PictureFlowPrivate;
 
     d->state = new PictureFlowState;
+    d->state->model = _p_model;
     d->state->reset();
     d->state->reposition();
 
@@ -830,7 +803,7 @@ PictureFlow::~PictureFlow()
 
 int PictureFlow::slideCount() const
 {
-    return d->state->slideImages.count();
+    return d->state->model->rowCount();
 }
 
 QColor PictureFlow::backgroundColor() const
@@ -868,51 +841,6 @@ void PictureFlow::setReflectionEffect(ReflectionEffect effect)
     triggerRender();
 }
 
-QImage PictureFlow::slide(int index) const
-{
-    QImage* i = 0;
-    if ((index >= 0) && (index < slideCount()))
-        i = d->state->slideImages[index];
-    return i ? QImage(*i) : QImage();
-}
-
-void PictureFlow::addSlide(const QImage& image)
-{
-    int c = d->state->slideImages.count();
-    d->state->slideImages.resize(c + 1);
-    d->state->slideImages[c] = new QImage(image);
-    triggerRender();
-}
-
-void PictureFlow::addSlide(const QPixmap& pixmap)
-{
-    addSlide(pixmap.toImage());
-}
-
-void PictureFlow::removeSlide(int index)
-{
-    int c = d->state->slideImages.count();
-    if (index >= 0 && index < c) {
-        d->state->slideImages.remove(index);
-        triggerRender();
-    }
-}
-
-void PictureFlow::setSlide(int index, const QImage& image)
-{
-    if ((index >= 0) && (index < slideCount())) {
-        QImage* i = image.isNull() ? 0 : new QImage(image);
-        delete d->state->slideImages[index];
-        d->state->slideImages[index] = i;
-        triggerRender();
-    }
-}
-
-void PictureFlow::setSlide(int index, const QPixmap& pixmap)
-{
-    setSlide(index, pixmap.toImage());
-}
-
 int PictureFlow::centerIndex() const
 {
     return d->state->centerIndex;
@@ -930,11 +858,6 @@ void PictureFlow::setCenterIndex(int index)
 
 void PictureFlow::clear()
 {
-    int c = d->state->slideImages.count();
-    for (int i = 0; i < c; i++)
-        delete d->state->slideImages[i];
-    d->state->slideImages.resize(0);
-
     d->state->reset();
     triggerRender();
 }
diff --git a/modules/gui/qt4/util/pictureflow.hpp b/modules/gui/qt4/util/pictureflow.hpp
index 7c6f47b..d30dddc 100644
--- a/modules/gui/qt4/util/pictureflow.hpp
+++ b/modules/gui/qt4/util/pictureflow.hpp
@@ -29,6 +29,7 @@
 #define PICTUREFLOW_H
 
 #include <qwidget.h>
+#include "../components/playlist/playlist_model.hpp" /* getArtPixmap etc */
 
 class PictureFlowPrivate;
 
@@ -62,7 +63,7 @@ public:
     /*!
       Creates a new PictureFlow widget.
     */
-    PictureFlow(QWidget* parent = 0);
+    PictureFlow(QWidget* parent = 0, PLModel *model = 0);
 
     /*!
       Destroys the widget.
@@ -95,11 +96,6 @@ public:
     int slideCount() const;
 
     /*!
-      Returns QImage of specified slide.
-    */
-    QImage slide(int index) const;
-
-    /*!
       Returns the index of slide currently shown in the middle of the viewport.
     */
     int centerIndex() const;
@@ -118,33 +114,6 @@ public:
 public slots:
 
     /*!
-      Adds a new slide.
-    */
-    void addSlide(const QImage& image);
-
-    /*!
-      Adds a new slide.
-    */
-    void addSlide(const QPixmap& pixmap);
-
-    /*!
-      Removes an existing slide.
-    */
-    void removeSlide(int index);
-
-    /*!
-      Sets an image for specified slide. If the slide already exists,
-      it will be replaced.
-    */
-    void setSlide(int index, const QImage& image);
-
-    /*!
-      Sets a pixmap for specified slide. If the slide already exists,
-      it will be replaced.
-    */
-    void setSlide(int index, const QPixmap& pixmap);
-
-    /*!
       Sets slide to be shown in the middle of the viewport. No animation
       effect will be produced, unlike using showSlide.
     */



More information about the vlc-commits mailing list