Commit 9c42dd14 authored by Ilkka Ollakka's avatar Ilkka Ollakka

Qt4: rework coverflow to use playlist model for art

parent fbeedd2d
...@@ -377,13 +377,12 @@ PicFlowView::PicFlowView( PLModel *p_model, QWidget *parent ) : QAbstractItemVie ...@@ -377,13 +377,12 @@ PicFlowView::PicFlowView( PLModel *p_model, QWidget *parent ) : QAbstractItemVie
{ {
QHBoxLayout *layout = new QHBoxLayout( this ); QHBoxLayout *layout = new QHBoxLayout( this );
layout->setMargin( 0 ); layout->setMargin( 0 );
picFlow = new PictureFlow( this ); picFlow = new PictureFlow( this, p_model );
picFlow->setSlideSize(QSize(128,128)); picFlow->setSlideSize(QSize(128,128));
layout->addWidget( picFlow ); layout->addWidget( picFlow );
setSelectionMode( QAbstractItemView::SingleSelection ); setSelectionMode( QAbstractItemView::SingleSelection );
setModel( p_model ); setModel( p_model );
//CONNECT( picFlow, centerIndexChanged(int), this, playItem(int) );
} }
int PicFlowView::horizontalOffset() const int PicFlowView::horizontalOffset() const
...@@ -405,9 +404,9 @@ void PicFlowView::scrollTo(const QModelIndex &index, QAbstractItemView::ScrollHi ...@@ -405,9 +404,9 @@ void PicFlowView::scrollTo(const QModelIndex &index, QAbstractItemView::ScrollHi
{ {
int currentIndex = picFlow->centerIndex(); int currentIndex = picFlow->centerIndex();
if( qAbs( currentIndex - index.row()) > 100 ) if( qAbs( currentIndex - index.row()) > 100 )
picFlow->setCenterIndex( index.row()-1); picFlow->setCenterIndex( index.row());
else else
picFlow->showSlide( index.row()-1 ); picFlow->showSlide( index.row() );
} }
QModelIndex PicFlowView::indexAt(const QPoint &) const QModelIndex PicFlowView::indexAt(const QPoint &) const
...@@ -441,20 +440,18 @@ void PicFlowView::setSelection(const QRect &, QFlags<QItemSelectionModel::Select ...@@ -441,20 +440,18 @@ void PicFlowView::setSelection(const QRect &, QFlags<QItemSelectionModel::Select
// No selection possible // 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++ )
{
if( i-5 <= currentIndex &&
i+5 >= currentIndex )
{ {
const QModelIndex index = model()->index( i, 0, parent ); picFlow->render();
if( !index.isValid() )
return; 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 ) void PicFlowView::playItem( int i_item )
......
...@@ -116,8 +116,8 @@ protected: ...@@ -116,8 +116,8 @@ protected:
private: private:
PictureFlow *picFlow; PictureFlow *picFlow;
protected slots: public slots:
void rowsInserted ( const QModelIndex & parent, int start, int end ); void dataChanged( const QModelIndex &, const QModelIndex &);
private slots: private slots:
void playItem( int ); void playItem( int );
}; };
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include <QTimer> #include <QTimer>
#include <QVector> #include <QVector>
#include <QWidget> #include <QWidget>
#include "../components/playlist/playlist_model.hpp" /* getArtPixmap etc */
// for fixed-point arithmetic, we need minimum 32-bit long // for fixed-point arithmetic, we need minimum 32-bit long
// long long (64-bit) might be useful for multiplication and division // long long (64-bit) might be useful for multiplication and division
...@@ -136,13 +137,13 @@ public: ...@@ -136,13 +137,13 @@ public:
int slideWidth; int slideWidth;
int slideHeight; int slideHeight;
PictureFlow::ReflectionEffect reflectionEffect; PictureFlow::ReflectionEffect reflectionEffect;
QVector<QImage*> slideImages;
int angle; int angle;
int spacing; int spacing;
PFreal offsetX; PFreal offsetX;
PFreal offsetY; PFreal offsetY;
PLModel *model;
SlideInfo centerSlide; SlideInfo centerSlide;
QVector<SlideInfo> leftSlides; QVector<SlideInfo> leftSlides;
QVector<SlideInfo> rightSlides; QVector<SlideInfo> rightSlides;
...@@ -214,8 +215,6 @@ PictureFlowState::PictureFlowState(): ...@@ -214,8 +215,6 @@ PictureFlowState::PictureFlowState():
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 // readjust the settings, call this when slide dimension is changed
...@@ -594,40 +593,13 @@ QImage* PictureFlowSoftwareRenderer::surface(int slideIndex) ...@@ -594,40 +593,13 @@ QImage* PictureFlowSoftwareRenderer::surface(int slideIndex)
return 0; return 0;
if (slideIndex < 0) if (slideIndex < 0)
return 0; return 0;
if (slideIndex >= (int)state->slideImages.count()) if (slideIndex >= (int)state->model->rowCount())
return 0; return 0;
int key = slideIndex; int key = slideIndex;
QImage* img = state->slideImages.at(slideIndex); QImage* img = new QImage(PLModel::getArtPixmap( state->model->index( slideIndex, 0, QModelIndex() ),
bool empty = img ? img->isNull() : true; QSize( state->slideWidth, state->slideHeight ) ).toImage());
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;
}
bool exist = imageHash.contains(slideIndex); bool exist = imageHash.contains(slideIndex);
if (exist) if (exist)
...@@ -796,11 +768,12 @@ public: ...@@ -796,11 +768,12 @@ public:
}; };
PictureFlow::PictureFlow(QWidget* parent): QWidget(parent) PictureFlow::PictureFlow(QWidget* parent, PLModel* _p_model): QWidget(parent)
{ {
d = new PictureFlowPrivate; d = new PictureFlowPrivate;
d->state = new PictureFlowState; d->state = new PictureFlowState;
d->state->model = _p_model;
d->state->reset(); d->state->reset();
d->state->reposition(); d->state->reposition();
...@@ -830,7 +803,7 @@ PictureFlow::~PictureFlow() ...@@ -830,7 +803,7 @@ PictureFlow::~PictureFlow()
int PictureFlow::slideCount() const int PictureFlow::slideCount() const
{ {
return d->state->slideImages.count(); return d->state->model->rowCount();
} }
QColor PictureFlow::backgroundColor() const QColor PictureFlow::backgroundColor() const
...@@ -868,51 +841,6 @@ void PictureFlow::setReflectionEffect(ReflectionEffect effect) ...@@ -868,51 +841,6 @@ void PictureFlow::setReflectionEffect(ReflectionEffect effect)
triggerRender(); 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 int PictureFlow::centerIndex() const
{ {
return d->state->centerIndex; return d->state->centerIndex;
...@@ -930,11 +858,6 @@ void PictureFlow::setCenterIndex(int index) ...@@ -930,11 +858,6 @@ void PictureFlow::setCenterIndex(int index)
void PictureFlow::clear() 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(); d->state->reset();
triggerRender(); triggerRender();
} }
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#define PICTUREFLOW_H #define PICTUREFLOW_H
#include <qwidget.h> #include <qwidget.h>
#include "../components/playlist/playlist_model.hpp" /* getArtPixmap etc */
class PictureFlowPrivate; class PictureFlowPrivate;
...@@ -62,7 +63,7 @@ public: ...@@ -62,7 +63,7 @@ public:
/*! /*!
Creates a new PictureFlow widget. Creates a new PictureFlow widget.
*/ */
PictureFlow(QWidget* parent = 0); PictureFlow(QWidget* parent = 0, PLModel *model = 0);
/*! /*!
Destroys the widget. Destroys the widget.
...@@ -94,11 +95,6 @@ public: ...@@ -94,11 +95,6 @@ public:
*/ */
int slideCount() const; 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. Returns the index of slide currently shown in the middle of the viewport.
*/ */
...@@ -117,33 +113,6 @@ public: ...@@ -117,33 +113,6 @@ public:
public slots: 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 Sets slide to be shown in the middle of the viewport. No animation
effect will be produced, unlike using showSlide. effect will be produced, unlike using showSlide.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment