added drag&drop support for sorting comics in lists

This commit is contained in:
Luis Ángel San Martín
2015-01-30 16:40:57 +01:00
parent 27d096162d
commit aa1398666e
21 changed files with 429 additions and 49 deletions

View File

@ -569,7 +569,7 @@ void PictureFlowSoftwareRenderer::init()
int wh = size.height();
int w = (ww+1)/2;
int h = (wh+1)/2;
if(h<10)//TODO a partir de qu<EFBFBD> h es seguro??
if(h<10)//TODO a partir de qué h es seguro??
return;
#ifdef PICTUREFLOW_QT4
@ -1207,18 +1207,19 @@ void PictureFlow::showSlide(unsigned int index)
index = qMax<unsigned int>(index, 0);
index = qMin<unsigned int>(slideCount()-1, index);
if(index == d->state->centerSlide.slideIndex)
return;
return;
int distance = centerIndex()-index;
int distance = centerIndex()-index;
if(abs(distance)>10)
{
if(distance<0)
setCenterIndex(centerIndex()+(-distance)-10);
else
setCenterIndex(centerIndex()-distance+10);
}
if(abs(distance)>10)
{
if(distance<0)
setCenterIndex(centerIndex()+(-distance)-10);
else
setCenterIndex(centerIndex()-distance+10);
}
d->state->centerIndex = index;
d->animator->start(index);
}
@ -1375,6 +1376,39 @@ void PictureFlow::setShowMarks(bool enable)
QVector<YACReaderComicReadStatus > PictureFlow::getMarks()
{
return d->state->marks;
return d->state->marks;
}
void PictureFlow::resortCovers(QList<int> newOrder)
{
QVector<QImage*> slideImagesNew;
QVector<YACReaderComicReadStatus> marksNew;
SlideInfo centerSlideNew;
QVector<SlideInfo> leftSlidesNew;
QVector<SlideInfo> rightSlidesNew;
QVector<SlideInfo> slidesInfo;
slidesInfo << d->state->leftSlides << d->state->centerSlide << d->state->rightSlides;
QVector<SlideInfo> slidesInfoNew;
int numSlides = 1 + d->state->leftSlides.length() + d->state->rightSlides.length();
int order = 0;
foreach(int index, newOrder)
{
slideImagesNew << d->state->slideImages.at(index);
marksNew << d->state->marks.at(index);
slidesInfoNew << slidesInfo.at(index);
slidesInfoNew.last().slideIndex = order++;
}
d->state->slideImages = slideImagesNew;
d->state->marks = marksNew;
d->state->leftSlides = slidesInfoNew.mid(0,d->state->leftSlides.length());
d->state->centerSlide = slidesInfoNew.at(d->state->centerIndex);
d->state->leftSlides = slidesInfoNew.mid(d->state->centerIndex+1,d->state->leftSlides.length());
setCenterIndex(d->state->centerIndex);
}

View File

@ -203,6 +203,7 @@ public slots:
QVector<YACReaderComicReadStatus> getMarks();
void resortCovers(QList<int> newOrder);
signals:
void centerIndexChanged(int index);

View File

@ -638,21 +638,27 @@ void YACReaderFlowGL::showNext()
void YACReaderFlowGL::setCurrentIndex(int pos)
{
startAnimationTimer();
if(!(pos>=0 && pos < images.length() && images.length()>0))
return;
if(pos >= images.length() && images.length() > 0)
pos = images.length()-1;
currentSelected = pos;
startAnimationTimer();
config.animationStep *= config.animationSpeedUp;
currentSelected = pos;
if(config.animationStep > config.animationStepMax){
config.animationStep = config.animationStepMax;
}
config.animationStep *= config.animationSpeedUp;
if(viewRotateActive && viewRotate < 1){
viewRotate += config.viewRotateAdd;
}
if(config.animationStep > config.animationStepMax){
config.animationStep = config.animationStepMax;
}
if(viewRotateActive && viewRotate < 1){
viewRotate += config.viewRotateAdd;
}
viewRotateActive = 1;
viewRotateActive = 1;
}
void YACReaderFlowGL::updatePositions()
@ -672,7 +678,7 @@ void YACReaderFlowGL::updatePositions()
}
if(fabs (images[currentSelected].current.x - images[currentSelected].animEnd.x) < 1)//viewRotate < 0.2)
{
{
cleanupAnimation();
if(updateCount >= 0) //TODO parametrizar
{
@ -718,14 +724,13 @@ void YACReaderFlowGL::insert(char *name, QOpenGLTexture * texture, float x, floa
void YACReaderFlowGL::remove(int item)
{
if(item < 0 || item >= paths.size())
if(item < 0 || item >= images.size())
return;
startAnimationTimer();
loaded.remove(item);
marks.remove(item);
paths.removeAt(item);
//reposition current selection
if(item <= currentSelected && currentSelected != 0){
@ -1041,7 +1046,7 @@ void YACReaderFlowGL::render()
}
//EVENTOS
#include "QsLog.h"
void YACReaderFlowGL::wheelEvent(QWheelEvent * event)
{
Movement m = getMovement(event);
@ -1248,8 +1253,8 @@ void YACReaderComicFlowGL::updateImageData()
{
int i = indexes[c];
if((i >= 0) && (i < numObjects))
if(!loaded[i])//slide(i).isNull())
{
if(!loaded[i])//slide(i).isNull())
{
//loader->loadTexture(i);
//loaded[i]=true;
// schedule thumbnail generation
@ -1262,7 +1267,7 @@ void YACReaderComicFlowGL::updateImageData()
}
delete[] indexes;
return;
}
}
}
}
@ -1271,7 +1276,36 @@ void YACReaderComicFlowGL::remove(int item)
worker->lock();
worker->reset();
YACReaderFlowGL::remove(item);
worker->unlock();
if(item >= 0 && item < paths.size())
paths.removeAt(item);
worker->unlock();
}
void YACReaderComicFlowGL::resortCovers(QList<int> newOrder)
{
worker->lock();
worker->reset();//is this necesary?
startAnimationTimer();
QList<QString> pathsNew;
QVector<bool> loadedNew;
QVector<YACReaderComicReadStatus> marksNew;
QVector<YACReader3DImage> imagesNew;
int index = 0;
foreach (int i, newOrder) {
pathsNew << paths.at(i);
loadedNew << loaded.at(i);
marksNew << marks.at(i);
imagesNew << images.at(i);
imagesNew.last().index = index++;
}
paths = pathsNew;
loaded = loadedNew;
marks = marksNew;
images = imagesNew;
worker->unlock();
}

View File

@ -141,7 +141,6 @@ protected:
bool showMarks;
QVector<bool> loaded;
QVector<YACReaderComicReadStatus> marks;
QList<QString> paths;
QVector<YACReader3DImage> images;
@ -293,9 +292,12 @@ public:
void setImagePaths(QStringList paths);
void updateImageData();
void remove(int item);
void resortCovers(QList<int> newOrder);
friend class ImageLoaderGL;
private:
ImageLoaderGL * worker;
protected:
QList<QString> paths;
};

View File

@ -129,3 +129,13 @@ QString YACReader::labelColorToRGBString(LabelColors color)
}
}
QList<qulonglong> YACReader::mimeDataToComicsIds(const QMimeData *data)
{
QList<qulonglong> comicIds;
QByteArray rawData = data->data(YACReader::YACReaderLibrarComiscSelectionMimeDataFormat);
QDataStream in(&rawData,QIODevice::ReadOnly);
in >> comicIds; //deserialize the list of indentifiers
return comicIds;
}

View File

@ -8,6 +8,7 @@
#endif
#include <QWidget>
#include <QMimeData>
#define VERSION "8.0.0"
@ -138,6 +139,7 @@ QString colorToName(LabelColors colors);
QIcon noHighlightedIcon(const QString & path);
void colorize(QImage &img, QColor &col);
QString labelColorToRGBString(LabelColors color);
QList<qulonglong> mimeDataToComicsIds(const QMimeData * data);
}
#endif