Commit 8d3db54d authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Reenable the Qt4-PictureFlow

These patches now should integrate better into the StandardPanel etc.
Parts had to be rearranged to be able to merge some code from libqxt into the source.
Fix bugs due to PL/ML change

Patch by VlcVelope
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 391bb327
......@@ -378,11 +378,17 @@ PicFlowView::PicFlowView( PLModel *p_model, QWidget *parent ) : QAbstractItemVie
QHBoxLayout *layout = new QHBoxLayout( this );
layout->setMargin( 0 );
picFlow = new PictureFlow( this, p_model );
picFlow->setSlideSize(QSize(128,128));
layout->addWidget( picFlow );
picFlow->setSlideSize(QSize( 4*LISTVIEW_ART_SIZE, 3*LISTVIEW_ART_SIZE) );
setSelectionMode( QAbstractItemView::SingleSelection );
}
void PicFlowView::setModel( QAbstractItemModel *model )
{
QAbstractItemView::setModel( model );
picFlow->setModel( model );
}
int PicFlowView::horizontalOffset() const
{
return 0;
......
......@@ -104,6 +104,7 @@ public:
virtual QRect visualRect(const QModelIndex&) const;
virtual void scrollTo(const QModelIndex&, QAbstractItemView::ScrollHint);
virtual QModelIndex indexAt(const QPoint&) const;
virtual void setModel(QAbstractItemModel *model);
protected:
virtual int horizontalOffset() const;
......
/*
PictureFlow - animated image show widget
http://pictureflow.googlecode.com
and
http://libqxt.org <foundation@libqxt.org>
Copyright (C) 2009 Ariya Hidayat (ariya@kde.org)
Copyright (C) 2008 Ariya Hidayat (ariya@kde.org)
Copyright (C) 2007 Ariya Hidayat (ariya@kde.org)
Copyright (C) Qxt Foundation. Some rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
......@@ -41,170 +45,11 @@
#include "../components/playlist/sorting.h" /* Columns List */
#include "input_manager.hpp"
// for fixed-point arithmetic, we need minimum 32-bit long
// long long (64-bit) might be useful for multiplication and division
typedef long PFreal;
#define PFREAL_SHIFT 10
#define PFREAL_ONE (1 << PFREAL_SHIFT)
#define IANGLE_MAX 1024
#define IANGLE_MASK 1023
inline PFreal fmul(PFreal a, PFreal b)
{
return ((long long)(a))*((long long)(b)) >> PFREAL_SHIFT;
}
inline PFreal fdiv(PFreal num, PFreal den)
{
long long p = (long long)(num) << (PFREAL_SHIFT * 2);
long long q = p / (long long)den;
long long r = q >> PFREAL_SHIFT;
return r;
}
inline PFreal fsin(int iangle)
{
// warning: regenerate the table if IANGLE_MAX and PFREAL_SHIFT are changed!
static const PFreal tab[] = {
3, 103, 202, 300, 394, 485, 571, 652,
726, 793, 853, 904, 947, 980, 1004, 1019,
1023, 1018, 1003, 978, 944, 901, 849, 789,
721, 647, 566, 479, 388, 294, 196, 97,
-4, -104, -203, -301, -395, -486, -572, -653,
-727, -794, -854, -905, -948, -981, -1005, -1020,
-1024, -1019, -1004, -979, -945, -902, -850, -790,
-722, -648, -567, -480, -389, -295, -197, -98,
3
};
while (iangle < 0)
iangle += IANGLE_MAX;
iangle &= IANGLE_MASK;
int i = (iangle >> 4);
PFreal p = tab[i];
PFreal q = tab[(i+1)];
PFreal g = (q - p);
return p + g *(iangle - i*16) / 16;
}
inline PFreal fcos(int iangle)
{
return fsin(iangle + (IANGLE_MAX >> 2));
}
/* ----------------------------------------------------------
PictureFlowState stores the state of all slides, i.e. all the necessary
information to be able to render them.
PictureFlowAnimator is responsible to move the slides during the
transition between slides, to achieve the effect similar to Cover Flow,
by changing the state.
PictureFlowSoftwareRenderer (or PictureFlowOpenGLRenderer) is
the actual 3-d renderer. It should render all slides given the state
(an instance of PictureFlowState).
Instances of all the above three classes are stored in
PictureFlowPrivate.
------------------------------------------------------- */
struct SlideInfo {
int slideIndex;
int angle;
PFreal cx;
PFreal cy;
int blend;
};
class PictureFlowState
{
public:
PictureFlowState();
~PictureFlowState();
void reposition();
void reset();
QRgb backgroundColor;
int slideWidth;
int slideHeight;
PictureFlow::ReflectionEffect reflectionEffect;
int angle;
int spacing;
PFreal offsetX;
PFreal offsetY;
VLCModel *model;
SlideInfo centerSlide;
QVector<SlideInfo> leftSlides;
QVector<SlideInfo> rightSlides;
int centerIndex;
};
class PictureFlowAnimator
{
public:
PictureFlowAnimator();
PictureFlowState* state;
void start(int slide);
void stop(int slide);
void update();
int target;
int step;
int frame;
QTimer animateTimer;
};
class PictureFlowAbstractRenderer
{
public:
PictureFlowAbstractRenderer(): state(0), dirty(false), widget(0) {}
virtual ~PictureFlowAbstractRenderer() {}
PictureFlowState* state;
bool dirty;
QWidget* widget;
virtual void init() = 0;
virtual void paint() = 0;
};
class PictureFlowSoftwareRenderer: public PictureFlowAbstractRenderer
{
public:
PictureFlowSoftwareRenderer();
~PictureFlowSoftwareRenderer();
virtual void init();
virtual void paint();
private:
QSize size;
QRgb bgcolor;
int effect;
QImage buffer;
QVector<PFreal> rays;
QImage* blankSurface;
void render();
void renderSlides();
QRect renderSlide(const SlideInfo &slide, int col1 = -1, int col2 = -1);
QImage* surface(QModelIndex);
QHash<QString, QImage*> cache;
};
// ------------- PictureFlowState ---------------------------------------
PictureFlowState::PictureFlowState():
backgroundColor(0), slideWidth(150), slideHeight(200),
backgroundColor(qRgba(0,0,0,0)), slideWidth(150), slideHeight(120),
reflectionEffect(PictureFlow::BlurredReflection), centerIndex(0)
{
}
......@@ -296,9 +141,9 @@ void PictureFlowAnimator::update()
if (!state)
return;
int speed = 16384;
int speed = 16384/2;
#if 0
#if 1
// deaccelerate when approaching the target
const int max = 2 * 65536;
......@@ -437,10 +282,8 @@ void PictureFlowSoftwareRenderer::paint()
render();
QPainter painter(widget);
painter.setCompositionMode(QPainter::CompositionMode_Source);
painter.drawImage(QPoint(0, 0), buffer);
QModelIndex index = state->model->index( state->centerIndex, 0, state->model->currentIndex().parent() );
}
void PictureFlowSoftwareRenderer::init()
......@@ -456,7 +299,7 @@ void PictureFlowSoftwareRenderer::init()
int w = (ww + 1) / 2;
int h = (wh + 1) / 2;
buffer = QImage(ww, wh, QImage::Format_RGB32);
buffer = QImage(ww, wh, QImage::Format_ARGB32);
buffer.fill(bgcolor);
rays.resize(w*2);
......@@ -472,10 +315,23 @@ void PictureFlowSoftwareRenderer::init()
// TODO: optimize this with lookup tables
static QRgb blendColor(QRgb c1, QRgb c2, int blend)
{
int r = qRed(c1) * blend / 256 + qRed(c2) * (256 - blend) / 256;
int g = qGreen(c1) * blend / 256 + qGreen(c2) * (256 - blend) / 256;
int b = qBlue(c1) * blend / 256 + qBlue(c2) * (256 - blend) / 256;
return qRgb(r, g, b);
unsigned int a,r,g,b,as,ad;
if(blend>255)
blend=255;
as=(qAlpha(c1)*blend)/256;
ad=qAlpha(c2);
a=as+((255-as)*ad)/256;
if(a>0)
{
r=(as*qRed(c1)+((255-as)*ad*qRed(c2))/256)/a;
g=(as*qGreen(c1)+((255-as)*ad*qGreen(c2))/256)/a;
b=(as*qBlue(c1)+((255-as)*ad*qBlue(c2))/256)/a;
}
else
{
r=g=b=0;
}
return qRgba(r, g, b, a);
}
......@@ -483,14 +339,14 @@ static QImage* prepareSurface(const QImage* slideImage, int w, int h, QRgb bgcol
PictureFlow::ReflectionEffect reflectionEffect, QModelIndex index)
{
Qt::TransformationMode mode = Qt::SmoothTransformation;
QImage img = slideImage->scaled(w, h, Qt::IgnoreAspectRatio, mode);
QImage img = slideImage->scaled(w, h, Qt::KeepAspectRatio, mode);
// slightly larger, to accomodate for the reflection
int hs = h * 2;
int hofs = h / 3;
// offscreen buffer: black is sweet
QImage* result = new QImage(hs, w, QImage::Format_RGB32);
QImage* result = new QImage(hs, w, QImage::Format_ARGB32);
QFont font( index.data( Qt::FontRole ).value<QFont>() );
QPainter imagePainter( result );
QTransform rotation;
......@@ -498,7 +354,8 @@ static QImage* prepareSurface(const QImage* slideImage, int w, int h, QRgb bgcol
rotation.rotate(90);
rotation.scale(1,-1);
rotation.translate( 0, hofs );
result->fill(bgcolor);
QRgb bg=qRgba(0, 0, 0, 0);
result->fill(bg);
// transpose the image, this is to speed-up the rendering
// because we process one column at a time
......@@ -508,7 +365,6 @@ static QImage* prepareSurface(const QImage* slideImage, int w, int h, QRgb bgcol
for (int y = 0; y < h; y++)
result->setPixel(hofs + y, x, img.pixel(x, y));
*/
imagePainter.drawImage( hofs+h, 0, img );
if (reflectionEffect != PictureFlow::NoReflection) {
// create the reflection
int ht = hs - h - hofs;
......@@ -516,9 +372,15 @@ static QImage* prepareSurface(const QImage* slideImage, int w, int h, QRgb bgcol
for (int x = 0; x < w; x++)
{
QRgb *line = (QRgb*)(result->scanLine( x ));
int xw=img.width(),yw=img.height();
QRgb color;
for (int y = 0; y < ht; y++) {
QRgb color = img.pixel(x, img.height() - y - 1);
line[h+hofs+y] = blendColor( color, bgcolor, 128*(hte-y)/hte );
color=bg;
int x0=x-(w-xw)/2;
int y0=yw - y - 1+(h-yw)/2;
if(x0>=0 && x0<xw && y0>=0 && y0<yw)
color = img.pixel(x0, y0);
line[h+hofs+y] = blendColor( color, bg, 128*(hte-y)/hte );
//result->setPixel(h + hofs + y, x, blendColor(color, bgcolor, 128*(hte - y) / hte));
}
}
......@@ -585,22 +447,22 @@ static QImage* prepareSurface(const QImage* slideImage, int w, int h, QRgb bgcol
p[i] = (rgba[i] += (((p[i] << 4) - rgba[i])) >> 1) >> 4;
}
}
// overdraw to leave only the reflection blurred (but not the actual image)
imagePainter.setTransform( rotation );
imagePainter.drawImage( 0, 0, img );
imagePainter.setBrush( QBrush( Qt::lightGray ) );
imagePainter.setPen( QColor( Qt::lightGray ) );
QFontMetrics fm = imagePainter.fontMetrics();
imagePainter.drawText( 0, img.height()+ 13, VLCModel::getMeta( index, COLUMN_TITLE ) );
imagePainter.drawText( 0, img.height()+ 13 + fm.xHeight()*2, VLCModel::getMeta( index, COLUMN_ARTIST ) );
/*
for (int x = 0; x < w; x++)
for (int y = 0; y < h; y++)
result->setPixel(hofs + y, x, img.pixel(x, y));
*/
}
}
// overdraw to leave only the reflection blurred (but not the actual image)
imagePainter.setTransform( rotation );
imagePainter.drawImage( (w-img.width())/2, (h-img.height())/2, img );
imagePainter.setBrush( QColor(bg));//QBrush( Qt::lightGray ) );
imagePainter.setPen( QColor( Qt::lightGray ) );
QFontMetrics fm = imagePainter.fontMetrics();
imagePainter.setPen( QColor( Qt::darkGray ) );
imagePainter.drawText( 0+1, 1+h-fm.height()*2, VLCModel::getMeta( index, COLUMN_TITLE ) );
imagePainter.setPen( QColor( Qt::lightGray ) );
imagePainter.drawText( 0, h-fm.height()*2, VLCModel::getMeta( index, COLUMN_TITLE ) );
imagePainter.setPen( QColor( Qt::darkGray ) );
imagePainter.drawText( 0+1, 1+h-fm.height()*1, VLCModel::getMeta( index, COLUMN_ARTIST ) );
imagePainter.setPen( QColor( Qt::lightGray ) );
imagePainter.drawText( 0, h-fm.height()*1, VLCModel::getMeta( index, COLUMN_ARTIST ) );
return result;
}
......@@ -740,23 +602,11 @@ QRect PictureFlowSoftwareRenderer::renderSlide(const SlideInfo &slide, int col1,
int p2 = center * PFREAL_ONE + dy / 2;
const QRgb *ptr = (const QRgb*)(src->scanLine(column));
if (blend == 256)
while ((y1 >= 0) && (y2 < h) && (p1 >= 0)) {
*pixel1 = ptr[p1 >> PFREAL_SHIFT];
*pixel2 = ptr[p2 >> PFREAL_SHIFT];
p1 -= dy;
p2 += dy;
y1--;
y2++;
pixel1 -= pixelstep;
pixel2 += pixelstep;
}
else
while ((y1 >= 0) && (y2 < h) && (p1 >= 0)) {
QRgb c1 = ptr[p1 >> PFREAL_SHIFT];
QRgb c2 = ptr[p2 >> PFREAL_SHIFT];
*pixel1 = blendColor(c1, bgcolor, blend);
*pixel2 = blendColor(c2, bgcolor, blend);
*pixel1 = blendColor(c1, *pixel1+0*bgcolor, blend);
*pixel2 = blendColor(c2, *pixel2+0*bgcolor, blend);
p1 -= dy;
p2 += dy;
y1--;
......@@ -776,20 +626,13 @@ void PictureFlowSoftwareRenderer::renderSlides()
int nleft = state->leftSlides.count();
int nright = state->rightSlides.count();
QRect r = renderSlide(state->centerSlide);
int c1 = r.left();
int c2 = r.right();
for (int index = 0; index < nleft; index++) {
QRect rs = renderSlide(state->leftSlides[index], 0, c1 - 1);
if (!rs.isEmpty())
c1 = rs.left();
for (int index = nleft-1; index >= 0; index--) {
renderSlide(state->leftSlides[index]);
}
for (int index = 0; index < nright; index++) {
QRect rs = renderSlide(state->rightSlides[index], c2 + 1, buffer.width());
if (!rs.isEmpty())
c2 = rs.right();
for (int index = nright-1; index >= 0; index--) {
renderSlide(state->rightSlides[index]);
}
renderSlide(state->centerSlide);
}
// Render the slides. Updates only the offscreen buffer.
......@@ -802,21 +645,17 @@ void PictureFlowSoftwareRenderer::render()
// -----------------------------------------
class PictureFlowPrivate
{
public:
PictureFlowState* state;
PictureFlowAnimator* animator;
PictureFlowAbstractRenderer* renderer;
QTimer triggerTimer;
};
PictureFlow::PictureFlow(QWidget* parent, VLCModel* _p_model): QWidget(parent)
{
d = new PictureFlowPrivate;
d->picrole = Qt::DecorationRole;
d->textrole = Qt::DisplayRole;
d->piccolumn = 0;
d->textcolumn = 0;
d->state = new PictureFlowState;
d->state->model = _p_model;
d->state->model = 0;
d->state->reset();
d->state->reposition();
......@@ -834,6 +673,8 @@ PictureFlow::PictureFlow(QWidget* parent, VLCModel* _p_model): QWidget(parent)
setAttribute(Qt::WA_StaticContents, true);
setAttribute(Qt::WA_OpaquePaintEvent, true);
setAttribute(Qt::WA_NoSystemBackground, true);
d->setModel(_p_model);
}
PictureFlow::~PictureFlow()
......@@ -844,6 +685,30 @@ PictureFlow::~PictureFlow()
delete d;
}
/*!
Sets the \a model.
\bold {Note:} The view does not take ownership of the model unless it is the
model's parent object because it may be shared between many different views.
*/
void PictureFlow::setModel(QAbstractItemModel * model)
{
d->setModel(model);
//d->state->model=(VLCModel*)model;
d->state->reset();
d->state->reposition();
d->renderer->init();
triggerRender();
}
/*!
Returns the model.
*/
QAbstractItemModel * PictureFlow::model()
{
return d->state->model;
}
int PictureFlow::slideCount() const
{
return d->state->model->rowCount( d->state->model->currentIndex().parent() );
......@@ -856,7 +721,7 @@ QColor PictureFlow::backgroundColor() const
void PictureFlow::setBackgroundColor(const QColor& c)
{
d->state->backgroundColor = c.rgb();
d->state->backgroundColor = c.rgba();
triggerRender();
}
......@@ -953,7 +818,7 @@ void PictureFlow::showSlide(int index)
{
index = qMax(index, 0);
index = qMin(slideCount() - 1, index);
if (index == d->state->centerSlide.slideIndex)
if (index < 0 || index == d->state->centerSlide.slideIndex)
return;
d->animator->start(index);
......@@ -988,9 +853,14 @@ void PictureFlow::mousePressEvent(QMouseEvent* event)
showNext();
else if (event->x() < width() / 2 - d->state->slideWidth/2 )
showPrevious();
else if ( d->state->model->currentIndex().row() != d->state->centerIndex )
d->state->model->activateItem( d->state->model->index( d->state->centerIndex, 0,
d->state->model->currentIndex().parent() ) );
else if ( d->state->model->rowCount()>0 && d->state->model->currentIndex().row() != d->state->centerIndex )
{
if(d->state->model->hasIndex( d->state->centerIndex, 0, d->state->model->currentIndex().parent() ))
{
QModelIndex i=d->state->model->index( d->state->centerIndex, 0, d->state->model->currentIndex().parent() );
d->state->model->activateItem( i );
}
}
}
void PictureFlow::paintEvent(QPaintEvent* event)
......@@ -1005,6 +875,34 @@ void PictureFlow::resizeEvent(QResizeEvent* event)
QWidget::resizeEvent(event);
}
void PictureFlow::wheelEvent(QWheelEvent * event)
{
if (event->orientation() == Qt::Horizontal)
{
event->ignore();
}
else
{
int numSteps = -((event->delta() / 8) / 15);
if (numSteps > 0)
{
for (int i = 0;i < numSteps;i++)
{
showNext();
}
}
else
{
for (int i = numSteps;i < 0;i++)
{
showPrevious();
}
}
event->accept();
}
}
void PictureFlow::updateAnimation()
{
int old_center = d->state->centerIndex;
......@@ -1014,3 +912,277 @@ void PictureFlow::updateAnimation()
emit centerIndexChanged(d->state->centerIndex);
}
void PictureFlowPrivate::columnsAboutToBeInserted(const QModelIndex & parent, int start, int end)
{
Q_UNUSED(parent);
Q_UNUSED(start);
Q_UNUSED(end);
}
void PictureFlowPrivate::columnsAboutToBeRemoved(const QModelIndex & parent, int start, int end)
{
Q_UNUSED(parent);
Q_UNUSED(start);
Q_UNUSED(end);
}
void PictureFlowPrivate::columnsInserted(const QModelIndex & parent, int start, int end)
{
Q_UNUSED(parent);
Q_UNUSED(start);
Q_UNUSED(end);
}
void PictureFlowPrivate::columnsRemoved(const QModelIndex & parent, int start, int end)
{
Q_UNUSED(parent);
Q_UNUSED(start);
Q_UNUSED(end);
}
void PictureFlowPrivate::dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight)
{
Q_UNUSED(topLeft);
Q_UNUSED(bottomRight);
if (topLeft.parent() != rootindex)
return;
if (bottomRight.parent() != rootindex)
return;
int start = topLeft.row();
int end = bottomRight.row();
for (int i = start;i <= end;i++)
replaceSlide(i, qvariant_cast<QImage>(state->model->data(state->model->index(i, piccolumn, rootindex), picrole)));
}
void PictureFlowPrivate::headerDataChanged(Qt::Orientation orientation, int first, int last)
{
Q_UNUSED(orientation);
Q_UNUSED(first);
Q_UNUSED(last);
}
void PictureFlowPrivate::layoutAboutToBeChanged()
{
}
void PictureFlowPrivate::layoutChanged()
{
reset();
setCurrentIndex(currentcenter);
}
void PictureFlowPrivate::modelAboutToBeReset()
{
}
void PictureFlowPrivate::modelReset()
{
reset();
}
void PictureFlowPrivate::rowsAboutToBeInserted(const QModelIndex & parent, int start, int end)
{
Q_UNUSED(parent);
Q_UNUSED(start);
Q_UNUSED(end);
}
void PictureFlowPrivate::rowsAboutToBeRemoved(const QModelIndex & parent, int start, int end)
{
Q_UNUSED(parent);
Q_UNUSED(start);
Q_UNUSED(end);
}
void PictureFlowPrivate::rowsInserted(const QModelIndex & parent, int start, int end)
{
if (rootindex != parent)
return;
for (int i = start;i <= end;i++)
{
QModelIndex idx = state->model->index(i, piccolumn, rootindex);
insertSlide(i, qvariant_cast<QImage>(state->model->data(idx, picrole)));
modelmap.insert(i, idx);
}
}
void PictureFlowPrivate::rowsRemoved(const QModelIndex & parent, int start, int end)
{
if (rootindex != parent)
return;
for (int i = start;i <= end;i++)
{
removeSlide(i);
modelmap.removeAt(i);
}
}
void PictureFlowPrivate::setModel(QAbstractItemModel * m)
{
if (state->model)
{
disconnect(state->model, SIGNAL(columnsAboutToBeInserted(const QModelIndex & , int , int)),
this, SLOT(columnsAboutToBeInserted(const QModelIndex & , int , int)));
disconnect(state->model, SIGNAL(columnsAboutToBeRemoved(const QModelIndex & , int , int)),
this, SLOT(columnsAboutToBeRemoved(const QModelIndex & , int , int)));
disconnect(state->model, SIGNAL(columnsInserted(const QModelIndex & , int , int)),
this, SLOT(columnsInserted(const QModelIndex & , int , int)));
disconnect(state->model, SIGNAL(columnsRemoved(const QModelIndex & , int , int)),
this, SLOT(columnsRemoved(const QModelIndex & , int , int)));
disconnect(state->model, SIGNAL(dataChanged(const QModelIndex & , const QModelIndex &)),
this, SLOT(dataChanged(const QModelIndex & , const QModelIndex &)));
disconnect(state->model, SIGNAL(headerDataChanged(Qt::Orientation , int , int)),
this, SLOT(headerDataChanged(Qt::Orientation , int , int)));
disconnect(state->model, SIGNAL(layoutAboutToBeChanged()),
this, SLOT(layoutAboutToBeChanged()));
disconnect(state->model, SIGNAL(layoutChanged()),
this, SLOT(layoutChanged()));
disconnect(state->model, SIGNAL(modelAboutToBeReset()),
this, SLOT(modelAboutToBeReset()));
disconnect(state->model, SIGNAL(modelReset()),
this, SLOT(modelReset()));
disconnect(state->model, SIGNAL(rowsAboutToBeInserted(const QModelIndex & , int , int)),
this, SLOT(rowsAboutToBeInserted(const QModelIndex & , int , int)));
disconnect(state->model, SIGNAL(rowsAboutToBeRemoved(const QModelIndex & , int , int)),
this, SLOT(rowsAboutToBeRemoved(const QModelIndex & , int , int)));
disconnect(state->model, SIGNAL(rowsInserted(const QModelIndex & , int , int)),
this, SLOT(rowsInserted(const QModelIndex & , int , int)));
disconnect(state->model, SIGNAL(rowsRemoved(const QModelIndex & , int , int)),
this, SLOT(rowsRemoved(const QModelIndex & , int , int)));
}
state->model = (VLCModel*)m;
if (state->model)
{
rootindex = state->model->parent(QModelIndex());
connect(state->model, SIGNAL(columnsAboutToBeInserted(const QModelIndex & , int , int)),
this, SLOT(columnsAboutToBeInserted(const QModelIndex & , int , int)));
connect(state->model, SIGNAL(columnsAboutToBeRemoved(const QModelIndex & , int , int)),
this, SLOT(columnsAboutToBeRemoved(const QModelIndex & , int , int)));
connect(state->model, SIGNAL(columnsInserted(const QModelIndex & , int , int)),
this, SLOT(columnsInserted(const QModelIndex & , int , int)));
connect(state->model, SIGNAL(columnsRemoved(const QModelIndex & , int , int)),
this, SLOT(columnsRemoved(const QModelIndex & , int , int)));
connect(state->model, SIGNAL(dataChanged(const QModelIndex & , const QModelIndex &)),
this, SLOT(dataChanged(const QModelIndex & , const QModelIndex &)));
connect(state->model, SIGNAL(headerDataChanged(Qt::Orientation , int , int)),
this, SLOT(headerDataChanged(Qt::Orientation , int , int)));
connect(state->model, SIGNAL(layoutAboutToBeChanged()),
this, SLOT(layoutAboutToBeChanged()));
connect(state->model, SIGNAL(layoutChanged()),
this, SLOT(layoutChanged()));
connect(state->model, SIGNAL(modelAboutToBeReset()),
this, SLOT(modelAboutToBeReset()));
connect(state->model, SIGNAL(modelReset()),
this, SLOT(modelReset()));
connect(state->model, SIGNAL(rowsAboutToBeInserted(const QModelIndex & , int , int)),
this, SLOT(rowsAboutToBeInserted(const QModelIndex & , int , int)));
connect(state->model, SIGNAL(rowsAboutToBeRemoved(const QModelIndex & , int , int)),
this, SLOT(rowsAboutToBeRemoved(const QModelIndex & , int , int)));
connect(state->model, SIGNAL(rowsInserted(const QModelIndex & , int , int)),
this, SLOT(rowsInserted(const QModelIndex & , int , int)));
connect(state->model, SIGNAL(rowsRemoved(const QModelIndex & , int , int)),
this, SLOT(rowsRemoved(const QModelIndex & , int , int)));
}
reset();
}
void PictureFlowPrivate::clear()
{
state->reset();
modelmap.clear();
triggerRender();
}
void PictureFlowPrivate::triggerRender()
{
triggerTimer.setSingleShot(true);
triggerTimer.start(0);
}
void PictureFlowPrivate::insertSlide(int index, const QImage& image)
{
// state->slideImages.insert(index, new QImage(image));
// triggerRender();
}
void PictureFlowPrivate::replaceSlide(int index, const QImage& image)
{
// Q_ASSERT((index >= 0) && (index < state->slideImages.count()));
// QImage* i = image.isNull() ? 0 : new QImage(image);
// delete state->slideImages[index];
// state->slideImages[index] = i;
// triggerRender();
}
void PictureFlowPrivate::removeSlide(int index)
{
// delete state->slideImages[index];
// state->slideImages.remove(index);
// triggerRender();
}
void PictureFlowPrivate::showSlide(int index)
{
if (index == state->centerSlide.slideIndex)
return;
animator->start(index);
}
void PictureFlowPrivate::reset()
{
clear();
if (state->model)
{
for (int i = 0;i < state->model->rowCount(rootindex);i++)
{
QModelIndex idx = state->model->index(i, piccolumn, rootindex);
insertSlide(i, qvariant_cast<QImage>(state->model->data(idx, picrole)));
modelmap.insert(i, idx);
}
if(modelmap.count())
currentcenter=modelmap.at(0);
else
currentcenter=QModelIndex();
}
triggerRender();
}
void PictureFlowPrivate::setCurrentIndex(QModelIndex index)
{
if (state->model->parent(index) != rootindex)
return;
int r = modelmap.indexOf(index);
if (r < 0)
return;
state->centerIndex = r;
state->reset();
animator->stop(r);
triggerRender();
}
/*
PictureFlow - animated image show widget
http://pictureflow.googlecode.com
and
http://libqxt.org <foundation@libqxt.org>
Copyright (C) 2009 Ariya Hidayat (ariya@kde.org)
Copyright (C) 2008 Ariya Hidayat (ariya@kde.org)
Copyright (C) 2007 Ariya Hidayat (ariya@kde.org)
Copyright (C) Qxt Foundation. Some rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
......@@ -28,9 +32,23 @@
#ifndef PICTUREFLOW_H
#define PICTUREFLOW_H
#include <qwidget.h>
#include <QApplication>
#include <QCache>
#include <QHash>
#include <QImage>
#include <QKeyEvent>
#include <QPainter>
#include <QPixmap>
#include <QTimer>
#include <QVector>
#include <QWidget>
#include <QAbstractItemModel>
#include <QPersistentModelIndex>
#include <QList>
#include "../components/playlist/playlist_model.hpp" /* getArtPixmap etc */
class PictureFlowPrivate;
/*!
......@@ -70,6 +88,9 @@ public:
*/
~PictureFlow();
void setModel(QAbstractItemModel * model);
QAbstractItemModel * model();
/*!
Returns the background color.
*/
......@@ -158,6 +179,7 @@ protected:
void paintEvent(QPaintEvent *event);
void keyPressEvent(QKeyEvent* event);
void mousePressEvent(QMouseEvent* event);
void wheelEvent(QWheelEvent* event);
void resizeEvent(QResizeEvent* event);
private slots:
......@@ -167,5 +189,197 @@ private:
PictureFlowPrivate* d;
};
// for fixed-point arithmetic, we need minimum 32-bit long
// long long (64-bit) might be useful for multiplication and division
typedef long PFreal;
#define PFREAL_SHIFT 10
#define PFREAL_ONE (1 << PFREAL_SHIFT)
#define IANGLE_MAX 1024
#define IANGLE_MASK 1023
inline PFreal fmul(PFreal a, PFreal b)
{
return ((long long)(a))*((long long)(b)) >> PFREAL_SHIFT;
}
inline PFreal fdiv(PFreal num, PFreal den)
{
long long p = (long long)(num) << (PFREAL_SHIFT * 2);
long long q = p / (long long)den;
long long r = q >> PFREAL_SHIFT;
return r;
}
inline PFreal fsin(int iangle)
{
// warning: regenerate the table if IANGLE_MAX and PFREAL_SHIFT are changed!
static const PFreal tab[] = {
3, 103, 202, 300, 394, 485, 571, 652,
726, 793, 853, 904, 947, 980, 1004, 1019,
1023, 1018, 1003, 978, 944, 901, 849, 789,
721, 647, 566, 479, 388, 294, 196, 97,
-4, -104, -203, -301, -395, -486, -572, -653,
-727, -794, -854, -905, -948, -981, -1005, -1020,
-1024, -1019, -1004, -979, -945, -902, -850, -790,
-722, -648, -567, -480, -389, -295, -197, -98,
3
};
while (iangle < 0)
iangle += IANGLE_MAX;
iangle &= IANGLE_MASK;
int i = (iangle >> 4);
PFreal p = tab[i];
PFreal q = tab[(i+1)];
PFreal g = (q - p);
return p + g *(iangle - i*16) / 16;
}
inline PFreal fcos(int iangle)
{
return fsin(iangle + (IANGLE_MAX >> 2));
}
struct SlideInfo {
int slideIndex;
int angle;
PFreal cx;
PFreal cy;
int blend;
};
class PictureFlow;
class PictureFlowState
{
public:
PictureFlowState();
~PictureFlowState();
void reposition();
void reset();
QRgb backgroundColor;
int slideWidth;
int slideHeight;
PictureFlow::ReflectionEffect reflectionEffect;
int angle;
int spacing;
PFreal offsetX;
PFreal offsetY;
VLCModel *model;
SlideInfo centerSlide;
QVector<SlideInfo> leftSlides;
QVector<SlideInfo> rightSlides;
int centerIndex;
};
class PictureFlowAnimator
{
public:
PictureFlowAnimator();
PictureFlowState* state;
void start(int slide);
void stop(int slide);
void update();
int target;
int step;
int frame;
QTimer animateTimer;
};
class PictureFlowAbstractRenderer
{
public:
PictureFlowAbstractRenderer(): state(0), dirty(false), widget(0) {}
virtual ~PictureFlowAbstractRenderer() {}
PictureFlowState* state;
bool dirty;
QWidget* widget;
virtual void init() = 0;
virtual void paint() = 0;
};
class PictureFlowSoftwareRenderer: public PictureFlowAbstractRenderer
{
public:
PictureFlowSoftwareRenderer();
~PictureFlowSoftwareRenderer();
virtual void init();
virtual void paint();
private:
QSize size;
QRgb bgcolor;
int effect;
QImage buffer;
QVector<PFreal> rays;
QImage* blankSurface;
void render();
void renderSlides();
QRect renderSlide(const SlideInfo &slide, int col1 = -1, int col2 = -1);
QImage* surface(QModelIndex);
QHash<QString, QImage*> cache;
};
class PictureFlowPrivate : public QObject
{
Q_OBJECT
public:
PictureFlowState* state;
PictureFlowAnimator* animator;
PictureFlowAbstractRenderer* renderer;
QTimer triggerTimer;
void setModel(QAbstractItemModel * model);
void clear();
void triggerRender();
void insertSlide(int index, const QImage& image);
void replaceSlide(int index, const QImage& image);
void removeSlide(int index);
void setCurrentIndex(QModelIndex index);
void showSlide(int index);
int picrole;
int textrole;
int piccolumn;
int textcolumn;
void reset();
QList<QPersistentModelIndex> modelmap;
QPersistentModelIndex currentcenter;
QPoint lastgrabpos;
QModelIndex rootindex;
public Q_SLOTS:
void columnsAboutToBeInserted(const QModelIndex & parent, int start, int end);
void columnsAboutToBeRemoved(const QModelIndex & parent, int start, int end);
void columnsInserted(const QModelIndex & parent, int start, int end);
void columnsRemoved(const QModelIndex & parent, int start, int end);
void dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight);
void headerDataChanged(Qt::Orientation orientation, int first, int last);
void layoutAboutToBeChanged();
void layoutChanged();
void modelAboutToBeReset();
void modelReset();
void rowsAboutToBeInserted(const QModelIndex & parent, int start, int end);
void rowsAboutToBeRemoved(const QModelIndex & parent, int start, int end);
void rowsInserted(const QModelIndex & parent, int start, int end);
void rowsRemoved(const QModelIndex & parent, int start, int end);
};
#endif // PICTUREFLOW_H
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