From aa1398666efdf20466ee2c136807fcbd50310bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Fri, 30 Jan 2015 16:40:57 +0100 Subject: [PATCH] added drag&drop support for sorting comics in lists --- YACReaderLibrary/classic_comics_view.cpp | 7 +- YACReaderLibrary/classic_comics_view.h | 3 +- YACReaderLibrary/comic_flow.cpp | 28 +++- YACReaderLibrary/comic_flow.h | 1 + YACReaderLibrary/comic_flow_widget.cpp | 16 +- YACReaderLibrary/comic_flow_widget.h | 5 +- YACReaderLibrary/comics_view.cpp | 8 +- YACReaderLibrary/db/comic_model.cpp | 146 ++++++++++++++++++- YACReaderLibrary/db/comic_model.h | 19 +++ YACReaderLibrary/db/data_base_management.cpp | 3 +- YACReaderLibrary/db/reading_list_model.cpp | 5 +- YACReaderLibrary/db_helper.cpp | 57 ++++++++ YACReaderLibrary/db_helper.h | 3 + common/pictureflow.cpp | 56 +++++-- common/pictureflow.h | 1 + common/yacreader_flow_gl.cpp | 70 ++++++--- common/yacreader_flow_gl.h | 4 +- common/yacreader_global.cpp | 10 ++ common/yacreader_global.h | 2 + custom_widgets/yacreader_table_view.cpp | 30 ++++ custom_widgets/yacreader_table_view.h | 4 + 21 files changed, 429 insertions(+), 49 deletions(-) diff --git a/YACReaderLibrary/classic_comics_view.cpp b/YACReaderLibrary/classic_comics_view.cpp index f6845abc..0677bc73 100644 --- a/YACReaderLibrary/classic_comics_view.cpp +++ b/YACReaderLibrary/classic_comics_view.cpp @@ -81,8 +81,6 @@ ClassicComicsView::ClassicComicsView(QWidget *parent) if(settings->contains(COMICS_VIEW_FLOW_SPLITTER_STATUS)) sVertical->restoreState(settings->value(COMICS_VIEW_FLOW_SPLITTER_STATUS).toByteArray()); - - } void ClassicComicsView::setToolBar(QToolBar *toolBar) @@ -104,6 +102,8 @@ void ClassicComicsView::setModel(ComicModel *model) { connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector)), this, SLOT(applyModelChanges(QModelIndex,QModelIndex,QVector)),Qt::UniqueConnection); connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(removeItemsFromFlow(QModelIndex,int,int)),Qt::UniqueConnection); + connect(model, SIGNAL(resortedIndexes(QList)),comicFlow,SLOT(resortCovers(QList)),Qt::UniqueConnection); + connect(model, SIGNAL(newSelectedIndex(QModelIndex)),this,SLOT(setCurrentIndex(QModelIndex)),Qt::UniqueConnection); tableView->setModel(model); if(model->rowCount()>0) @@ -146,8 +146,9 @@ void ClassicComicsView::setModel(ComicModel *model) void ClassicComicsView::setCurrentIndex(const QModelIndex &index) { + QLOG_INFO() << "*******************************************************ClassicComicsView::setCurrentIndex"; tableView->setCurrentIndex(index); - //TODO ComicsView: scroll comicFlow to index + centerComicFlow(index); } QModelIndex ClassicComicsView::currentIndex() diff --git a/YACReaderLibrary/classic_comics_view.h b/YACReaderLibrary/classic_comics_view.h index 161027eb..d98b3910 100644 --- a/YACReaderLibrary/classic_comics_view.h +++ b/YACReaderLibrary/classic_comics_view.h @@ -20,7 +20,7 @@ public: ClassicComicsView(QWidget *parent = 0); void setToolBar(QToolBar * toolBar); void setModel(ComicModel *model); - void setCurrentIndex(const QModelIndex &index); + QModelIndex currentIndex(); QItemSelectionModel * selectionModel(); void scrollTo(const QModelIndex & mi, QAbstractItemView::ScrollHint hint ); @@ -31,6 +31,7 @@ public: void selectIndex(int index); public slots: + void setCurrentIndex(const QModelIndex &index); void centerComicFlow(const QModelIndex & mi); void updateTableView(int i); void saveTableHeadersStatus(); diff --git a/YACReaderLibrary/comic_flow.cpp b/YACReaderLibrary/comic_flow.cpp index 6404e817..06e2af58 100644 --- a/YACReaderLibrary/comic_flow.cpp +++ b/YACReaderLibrary/comic_flow.cpp @@ -142,7 +142,33 @@ void ComicFlow::removeSlide(int cover) YACReaderFlow::removeSlide(cover); worker->unlock(); - preload(); + preload(); +} + +void ComicFlow::resortCovers(QList newOrder) +{ + worker->lock(); + worker->reset(); + + YACReaderFlow::resortCovers(newOrder); + + QStringList imageFilesNew; + QVector imagesLoadedNew; + QVector imagesSettedNew; + foreach(int index, newOrder) + { + imageFilesNew << imageFiles.at(index); + imagesLoadedNew << imagesLoaded.at(index); + imagesSettedNew << imagesSetted.at(index); + } + + + + imageFiles = imageFilesNew; + imagesLoaded = imagesLoadedNew; + imagesSetted = imagesSettedNew; + + worker->unlock(); } //----------------------------------------------------------------------------- //ImageLoader diff --git a/YACReaderLibrary/comic_flow.h b/YACReaderLibrary/comic_flow.h index 632e4871..c49543b3 100644 --- a/YACReaderLibrary/comic_flow.h +++ b/YACReaderLibrary/comic_flow.h @@ -24,6 +24,7 @@ public: //bool eventFilter(QObject *target, QEvent *event); void keyPressEvent(QKeyEvent* event); void removeSlide(int cover); + void resortCovers(QList newOrder); private slots: void preload(); diff --git a/YACReaderLibrary/comic_flow_widget.cpp b/YACReaderLibrary/comic_flow_widget.cpp index 9b523d57..2fce350c 100644 --- a/YACReaderLibrary/comic_flow_widget.cpp +++ b/YACReaderLibrary/comic_flow_widget.cpp @@ -137,7 +137,12 @@ void ComicFlowWidgetSW::updateConfig(QSettings * settings) void ComicFlowWidgetSW::remove(int cover) { - flow->removeSlide(cover); + flow->removeSlide(cover); +} + +void ComicFlowWidgetSW::resortCovers(QList newOrder) +{ + flow->resortCovers(newOrder); } @@ -329,7 +334,12 @@ void ComicFlowWidgetGL::updateConfig(QSettings * settings) void ComicFlowWidgetGL::remove(int cover) { - flow->remove(cover); + flow->remove(cover); +} + +void ComicFlowWidgetGL::resortCovers(QList newOrder) +{ + flow->resortCovers(newOrder); } //void ComicFlowWidgetGL::setCF_RX(int value){ flow->setCF_RX(value);} @@ -342,4 +352,4 @@ void ComicFlowWidgetGL::remove(int cover) //void ComicFlowWidgetGL::setZ_Distance(int distance){ flow->setZ_Distance(distance);} //void ComicFlowWidgetGL::setCF_Y(int value){ flow->setCF_Y(value);} //void ComicFlowWidgetGL::setY_Distance(int value){ flow->setY_Distance(value);} -//void ComicFlowWidgetGL::setPreset(const Preset & p){ flow->setPreset(p);} \ No newline at end of file +//void ComicFlowWidgetGL::setPreset(const Preset & p){ flow->setPreset(p);} diff --git a/YACReaderLibrary/comic_flow_widget.h b/YACReaderLibrary/comic_flow_widget.h index 028d9177..90eaccba 100644 --- a/YACReaderLibrary/comic_flow_widget.h +++ b/YACReaderLibrary/comic_flow_widget.h @@ -31,6 +31,7 @@ public slots: virtual void render() = 0; virtual void updateConfig(QSettings * settings) = 0; virtual void remove(int cover) = 0; + virtual void resortCovers(QList newOrder) = 0; signals: void centerIndexChanged(int); void selected(unsigned int); @@ -61,6 +62,7 @@ public: void render(); void updateConfig(QSettings * settings); void remove(int cover); + void resortCovers(QList newOrder); protected: void keyPressEvent(QKeyEvent* event); void paintEvent(QPaintEvent *event); @@ -97,6 +99,7 @@ public: void render(); void updateConfig(QSettings * settings); void remove(int cover); + void resortCovers(QList newOrder); //public slots: // void setCF_RX(int value); // //the Y Rotation of the Coverflow @@ -125,4 +128,4 @@ protected: QSize sizeHint() const; }; -#endif \ No newline at end of file +#endif diff --git a/YACReaderLibrary/comics_view.cpp b/YACReaderLibrary/comics_view.cpp index 47d181cd..2aa52bec 100644 --- a/YACReaderLibrary/comics_view.cpp +++ b/YACReaderLibrary/comics_view.cpp @@ -17,6 +17,11 @@ void ComicsView::setModel(ComicModel *m) void ComicsView::dragEnterEvent(QDragEnterEvent *event) { + if(model->canDropMimeData(event->mimeData(),event->proposedAction(),0,0,QModelIndex())) + event->acceptProposedAction(); + else + { + QLOG_INFO() << "dragEnterEvent"; QList urlList; if (event->mimeData()->hasUrls() && event->dropAction() == Qt::CopyAction) @@ -34,6 +39,7 @@ void ComicsView::dragEnterEvent(QDragEnterEvent *event) } } } + } } void ComicsView::dropEvent(QDropEvent *event) @@ -42,7 +48,7 @@ void ComicsView::dropEvent(QDropEvent *event) bool validAction = event->dropAction() == Qt::CopyAction;// || event->dropAction() & Qt::MoveAction; TODO move - if(validAction) + if(event->mimeData()->hasUrls() && validAction) { QList > droppedFiles = ComicFilesManager::getDroppedFiles(event->mimeData()->urls()); diff --git a/YACReaderLibrary/db/comic_model.cpp b/YACReaderLibrary/db/comic_model.cpp index 3fabc9aa..222e2fc6 100644 --- a/YACReaderLibrary/db/comic_model.cpp +++ b/YACReaderLibrary/db/comic_model.cpp @@ -40,6 +40,118 @@ int ComicModel::columnCount(const QModelIndex &parent) const return _data.first()->columnCount(); } +bool ComicModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const +{ + if(!enableResorting) + return false; + return data->formats().contains(YACReader::YACReaderLibrarComiscSelectionMimeDataFormat); +} + +//TODO: optimize this method +bool ComicModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) +{ + QAbstractItemModel::dropMimeData(data,action,row,column,parent); + QLOG_INFO() << ">>>>>>>>>>>>>>dropMimeData ComicModel<<<<<<<<<<<<<<<<<"<< parent << row << "," << column; + + if(!data->formats().contains(YACReader::YACReaderLibrarComiscSelectionMimeDataFormat)) + return false; + + QList comicIds = YACReader::mimeDataToComicsIds(data); + QList currentIndexes; + int i; + foreach(qulonglong id, comicIds) + { + i = 0; + foreach (ComicItem *item, _data) { + if(item->data(Id)==id) + { + currentIndexes << i; + break; + } + i++; + } + } + + std::sort(currentIndexes.begin(), currentIndexes.end()); + QList resortedData; + + if(currentIndexes.contains(row))//no resorting + return false; + + ComicItem * destinationItem; + if(row == -1 || row >= _data.length()) + destinationItem = 0; + else + destinationItem = _data.at(row); + + QList newSorting; + + i = 0; + foreach (ComicItem *item, _data) { + if(!currentIndexes.contains(i)) + { + + if(item == destinationItem) { + foreach(int index, currentIndexes) + { + resortedData << _data.at(index); + newSorting << index; + } + } + + resortedData << item; + newSorting << i; + } + + i++; + } + + if(destinationItem == 0) + { + foreach(int index, currentIndexes) + { + resortedData << _data.at(index); + newSorting << index; + } + } + + QLOG_INFO() << newSorting; + + _data = resortedData; + + + //TODO emit signals + //TODO fix selection + QList allComicIds; + foreach (ComicItem *item, _data) { + allComicIds << item->data(Id).toULongLong(); + } + + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + switch (mode) { + case Favorites: + DBHelper::reasignOrderToComicsInFavorites(allComicIds,db); + break; + case Label: + DBHelper::reasignOrderToComicsInLabel(sourceId,allComicIds,db); + break; + case ReadingList: + DBHelper::reasignOrderToComicsInReadingList(sourceId,allComicIds,db); + break; + } + + QSqlDatabase::removeDatabase(_databasePath); + emit resortedIndexes(newSorting); + int destSelectedIndex = row<0?_data.length():row; + + if(destSelectedIndex>currentIndexes.at(0)) + emit newSelectedIndex(index(qMax(0,destSelectedIndex-1),0,parent)); + else + emit newSelectedIndex(index(qMax(0,destSelectedIndex),0,parent)); + + return true; +} + QMimeData *ComicModel::mimeData(const QModelIndexList &indexes) const { //custom model data @@ -62,6 +174,14 @@ QMimeData *ComicModel::mimeData(const QModelIndexList &indexes) const return mimeData; } +QStringList ComicModel::mimeTypes() const +{ + QLOG_DEBUG() << "mimeTypes"; + QStringList list; + list << YACReader::YACReaderLibrarComiscSelectionMimeDataFormat; + return list; +} + QHash ComicModel::roleNames() const { QHash roles; @@ -162,10 +282,10 @@ QVariant ComicModel::data(const QModelIndex &index, int role) const Qt::ItemFlags ComicModel::flags(const QModelIndex &index) const { if (!index.isValid()) - return 0; + return 0; if(index.column() == ComicModel::Rating) return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable; - return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled; + return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled ; } QVariant ComicModel::headerData(int section, Qt::Orientation orientation, @@ -284,6 +404,10 @@ QStringList ComicModel::getPaths(const QString & _source) void ComicModel::setupFolderModelData(unsigned long long int folderId,const QString & databasePath) { + enableResorting = false; + mode = Folder; + sourceId=folderId; + beginResetModel(); qDeleteAll(_data); _data.clear(); @@ -309,6 +433,10 @@ void ComicModel::setupFolderModelData(unsigned long long int folderId,const QStr void ComicModel::setupLabelModelData(unsigned long long parentLabel, const QString &databasePath) { + enableResorting = true; + mode = Label; + sourceId = parentLabel; + beginResetModel(); qDeleteAll(_data); _data.clear(); @@ -336,6 +464,9 @@ void ComicModel::setupLabelModelData(unsigned long long parentLabel, const QStri void ComicModel::setupReadingListModelData(unsigned long long parentReadingList, const QString &databasePath) { + mode = ReadingList; + sourceId = parentReadingList; + beginResetModel(); qDeleteAll(_data); _data.clear(); @@ -356,6 +487,9 @@ void ComicModel::setupReadingListModelData(unsigned long long parentReadingList, while(subfolders.next()) ids << subfolders.record().value(0).toULongLong(); + enableResorting = ids.length()==1;//only resorting if no sublists exist + + foreach(qulonglong id, ids) { QSqlQuery selectQuery(db); @@ -371,7 +505,7 @@ void ComicModel::setupReadingListModelData(unsigned long long parentReadingList, QList tempData = _data; _data.clear(); - setupModelData(selectQuery); + setupModelDataForList(selectQuery); _data = tempData << _data; } @@ -384,6 +518,9 @@ void ComicModel::setupReadingListModelData(unsigned long long parentReadingList, void ComicModel::setupFavoritesModelData(const QString &databasePath) { + enableResorting = true; + mode = Favorites; + beginResetModel(); qDeleteAll(_data); _data.clear(); @@ -411,6 +548,9 @@ void ComicModel::setupFavoritesModelData(const QString &databasePath) void ComicModel::setupReadingModelData(const QString &databasePath) { + enableResorting = false; + mode = Reading; + beginResetModel(); qDeleteAll(_data); _data.clear(); diff --git a/YACReaderLibrary/db/comic_model.h b/YACReaderLibrary/db/comic_model.h index 48387248..8ec5271b 100644 --- a/YACReaderLibrary/db/comic_model.h +++ b/YACReaderLibrary/db/comic_model.h @@ -34,7 +34,10 @@ public: QModelIndex parent(const QModelIndex &index) const; int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; + bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const; + bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); QMimeData * mimeData(const QModelIndexList &indexes) const; + QStringList mimeTypes() const; void setupFolderModelData(unsigned long long int parentFolder,const QString & databasePath); void setupLabelModelData(unsigned long long int parentLabel, const QString & databasePath); @@ -113,6 +116,16 @@ public: }; + enum Mode { + Folder, + Favorites, + Reading, + Label, + ReadingList + }; + + + public slots: void remove(int row); void startTransaction(); @@ -135,11 +148,17 @@ private: QSqlDatabase dbTransaction; + bool enableResorting; + Mode mode; + qulonglong sourceId; + signals: void beforeReset(); void reset(); void isEmpty(); void searchNumResults(int); + void resortedIndexes(QList); + void newSelectedIndex(const QModelIndex &); }; //! [0] diff --git a/YACReaderLibrary/db/data_base_management.cpp b/YACReaderLibrary/db/data_base_management.cpp index ef39941f..e8052aee 100644 --- a/YACReaderLibrary/db/data_base_management.cpp +++ b/YACReaderLibrary/db/data_base_management.cpp @@ -220,7 +220,7 @@ bool DataBaseManagement::createTables(QSqlDatabase & database) return success; } -#include "QsLog.h" + bool DataBaseManagement::createV8Tables(QSqlDatabase &database) { bool success = true; @@ -304,7 +304,6 @@ bool DataBaseManagement::createV8Tables(QSqlDatabase &database) //1 Favorites //queryInsertDefaultReadingList.bindValue(":name", "Favorites"); success = success && queryInsertDefaultReadingList.exec("INSERT INTO default_reading_list (name) VALUES (\"Favorites\")"); - QLOG_ERROR() << success; //Reading doesn't need its onw list diff --git a/YACReaderLibrary/db/reading_list_model.cpp b/YACReaderLibrary/db/reading_list_model.cpp index 1c15e335..406f8e5a 100644 --- a/YACReaderLibrary/db/reading_list_model.cpp +++ b/YACReaderLibrary/db/reading_list_model.cpp @@ -244,10 +244,7 @@ bool ReadingListModel::dropMimeData(const QMimeData *data, Qt::DropAction action bool ReadingListModel::dropComics(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) { - QList comicIds; - QByteArray rawData = data->data(YACReader::YACReaderLibrarComiscSelectionMimeDataFormat); - QDataStream in(&rawData,QIODevice::ReadOnly); - in >> comicIds; //deserialize the list of indentifiers + QList comicIds = YACReader::mimeDataToComicsIds(data); QLOG_DEBUG() << "dropped : " << comicIds; diff --git a/YACReaderLibrary/db_helper.cpp b/YACReaderLibrary/db_helper.cpp index bb51f8b0..94b038d2 100644 --- a/YACReaderLibrary/db_helper.cpp +++ b/YACReaderLibrary/db_helper.cpp @@ -428,6 +428,63 @@ void DBHelper::reasignOrderToSublists(QList ids, QSqlDatabase &db) db.commit(); } +void DBHelper::reasignOrderToComicsInFavorites(QList comicIds, QSqlDatabase &db) +{ + QSqlQuery updateOrdering(db); + updateOrdering.prepare("UPDATE comic_default_reading_list SET " + "ordering = :ordering " + "WHERE comic_id = :comic_id AND default_reading_list_id = 0"); + db.transaction(); + int order = 0; + foreach(qulonglong id, comicIds) + { + updateOrdering.bindValue(":ordering",order++); + updateOrdering.bindValue(":comic_id", id); + updateOrdering.exec(); + } + + db.commit(); +} + +void DBHelper::reasignOrderToComicsInLabel(qulonglong labelId, QList comicIds, QSqlDatabase &db) +{ + QSqlQuery updateOrdering(db); + updateOrdering.prepare("UPDATE comic_label SET " + "ordering = :ordering " + "WHERE comic_id = :comic_id AND label_id = :label_id"); + db.transaction(); + int order = 0; + foreach(qulonglong id, comicIds) + { + updateOrdering.bindValue(":ordering",order++); + updateOrdering.bindValue(":comic_id", id); + updateOrdering.bindValue(":label_id", labelId); + updateOrdering.exec(); + } + + db.commit(); +} + +void DBHelper::reasignOrderToComicsInReadingList(qulonglong readingListId, QList comicIds, QSqlDatabase &db) +{ + QSqlQuery updateOrdering(db); + updateOrdering.prepare("UPDATE comic_reading_list SET " + "ordering = :ordering " + "WHERE comic_id = :comic_id AND reading_list_id = :reading_list_id"); + db.transaction(); + int order = 0; + foreach(qulonglong id, comicIds) + { + updateOrdering.bindValue(":ordering",order++); + updateOrdering.bindValue(":comic_id", id); + updateOrdering.bindValue(":reading_list_id", readingListId); + updateOrdering.exec(); + QLOG_INFO() << updateOrdering.lastError().databaseText() << "-" << updateOrdering.lastError().driverText(); + } + + db.commit(); +} + //inserts qulonglong DBHelper::insert(Folder * folder, QSqlDatabase & db) { diff --git a/YACReaderLibrary/db_helper.h b/YACReaderLibrary/db_helper.h index 55405bdf..14ca3598 100644 --- a/YACReaderLibrary/db_helper.h +++ b/YACReaderLibrary/db_helper.h @@ -59,6 +59,9 @@ public: static void renameLabel(qulonglong id, const QString & name, QSqlDatabase & db); static void renameList(qulonglong id, const QString & name, QSqlDatabase & db); static void reasignOrderToSublists(QList ids, QSqlDatabase & db); + static void reasignOrderToComicsInFavorites(QList comicIds, QSqlDatabase & db); + static void reasignOrderToComicsInLabel(qulonglong labelId, QList comicIds, QSqlDatabase & db); + static void reasignOrderToComicsInReadingList(qulonglong readingListId, QList comicIds, QSqlDatabase & db); static QList getFoldersFromParent(qulonglong parentId, QSqlDatabase & db, bool sort = true); static QList getSortedComicsFromParent(qulonglong parentId, QSqlDatabase & db); diff --git a/common/pictureflow.cpp b/common/pictureflow.cpp index 5aa4ba3f..c029a69a 100644 --- a/common/pictureflow.cpp +++ b/common/pictureflow.cpp @@ -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é 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(index, 0); index = qMin(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 PictureFlow::getMarks() { - return d->state->marks; + return d->state->marks; +} + +void PictureFlow::resortCovers(QList newOrder) +{ + QVector slideImagesNew; + + QVector marksNew; + + SlideInfo centerSlideNew; + QVector leftSlidesNew; + QVector rightSlidesNew; + + QVector slidesInfo; + slidesInfo << d->state->leftSlides << d->state->centerSlide << d->state->rightSlides; + QVector 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); } diff --git a/common/pictureflow.h b/common/pictureflow.h index b12b0b25..b746ef70 100644 --- a/common/pictureflow.h +++ b/common/pictureflow.h @@ -203,6 +203,7 @@ public slots: QVector getMarks(); + void resortCovers(QList newOrder); signals: void centerIndexChanged(int index); diff --git a/common/yacreader_flow_gl.cpp b/common/yacreader_flow_gl.cpp index d74f9ecb..1309d0d9 100644 --- a/common/yacreader_flow_gl.cpp +++ b/common/yacreader_flow_gl.cpp @@ -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 newOrder) +{ + worker->lock(); + worker->reset();//is this necesary? + startAnimationTimer(); + QList pathsNew; + QVector loadedNew; + QVector marksNew; + QVector 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(); } diff --git a/common/yacreader_flow_gl.h b/common/yacreader_flow_gl.h index 18d04e7b..2fc37d51 100644 --- a/common/yacreader_flow_gl.h +++ b/common/yacreader_flow_gl.h @@ -141,7 +141,6 @@ protected: bool showMarks; QVector loaded; QVector marks; - QList paths; QVector images; @@ -293,9 +292,12 @@ public: void setImagePaths(QStringList paths); void updateImageData(); void remove(int item); + void resortCovers(QList newOrder); friend class ImageLoaderGL; private: ImageLoaderGL * worker; +protected: + QList paths; }; diff --git a/common/yacreader_global.cpp b/common/yacreader_global.cpp index 1ec5b58f..fbf2540e 100644 --- a/common/yacreader_global.cpp +++ b/common/yacreader_global.cpp @@ -129,3 +129,13 @@ QString YACReader::labelColorToRGBString(LabelColors color) } } + + +QList YACReader::mimeDataToComicsIds(const QMimeData *data) +{ + QList comicIds; + QByteArray rawData = data->data(YACReader::YACReaderLibrarComiscSelectionMimeDataFormat); + QDataStream in(&rawData,QIODevice::ReadOnly); + in >> comicIds; //deserialize the list of indentifiers + return comicIds; +} diff --git a/common/yacreader_global.h b/common/yacreader_global.h index ca13e872..74ce104e 100644 --- a/common/yacreader_global.h +++ b/common/yacreader_global.h @@ -8,6 +8,7 @@ #endif #include +#include #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 mimeDataToComicsIds(const QMimeData * data); } #endif diff --git a/custom_widgets/yacreader_table_view.cpp b/custom_widgets/yacreader_table_view.cpp index c5ed980e..58f25f78 100644 --- a/custom_widgets/yacreader_table_view.cpp +++ b/custom_widgets/yacreader_table_view.cpp @@ -75,6 +75,8 @@ YACReaderTableView::YACReaderTableView(QWidget *parent) : //drag: if the default drag is enabled there is no way for setting a custom image //TODO report bug/suggestion //setDragEnabled(true); + //setDragDropMode(QAbstractItemView::DragDrop); + setAcceptDrops(true); } void YACReaderTableView::mouseMoveEvent(QMouseEvent *event) @@ -161,6 +163,34 @@ void YACReaderTableView::performDrag() Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction); } +void YACReaderTableView::dragEnterEvent(QDragEnterEvent *event) +{ + QTableView::dragEnterEvent(event); + + if(model()->canDropMimeData(event->mimeData(),event->proposedAction(),0,0,QModelIndex())) + event->acceptProposedAction(); + QLOG_DEBUG() << "drag enter table"; +} + +void YACReaderTableView::dragMoveEvent(QDragMoveEvent *event) +{ + QTableView::dragMoveEvent(event); + + if(model()->canDropMimeData(event->mimeData(),event->proposedAction(),0,0,QModelIndex())) + event->acceptProposedAction(); + QLOG_DEBUG() << "dragMoveEvent table"; +} + +void YACReaderTableView::dropEvent(QDropEvent *event) +{ + QTableView::dropEvent(event); + + if(model()->canDropMimeData(event->mimeData(),event->proposedAction(),0,0,QModelIndex())) + event->acceptProposedAction(); + QLOG_DEBUG() << "drop on table"; + +} + void YACReaderTableView::closeRatingEditor() { editing = false; diff --git a/custom_widgets/yacreader_table_view.h b/custom_widgets/yacreader_table_view.h index e7e4deb5..0c7bb607 100644 --- a/custom_widgets/yacreader_table_view.h +++ b/custom_widgets/yacreader_table_view.h @@ -34,6 +34,10 @@ private: void mousePressEvent(QMouseEvent * event); void leaveEvent(QEvent * event); void performDrag(); + void dragEnterEvent(QDragEnterEvent * event); + void dragMoveEvent(QDragMoveEvent * event); + void dropEvent(QDropEvent * event); + bool editing; QModelIndex currentIndexEditing;