diff --git a/YACReaderLibrary/YACReaderLibrary.pro b/YACReaderLibrary/YACReaderLibrary.pro index 68275057..53db0a03 100644 --- a/YACReaderLibrary/YACReaderLibrary.pro +++ b/YACReaderLibrary/YACReaderLibrary.pro @@ -148,7 +148,8 @@ HEADERS += comic_flow.h \ ../common/opengl_checker.h \ yacreader_comics_views_manager.h \ info_comics_view.h \ - yacreader_comics_selection_helper.h + yacreader_comics_selection_helper.h \ + yacreader_comic_info_helper.h !CONFIG(no_opengl) { CONFIG(legacy_gl_widget) { @@ -221,7 +222,8 @@ SOURCES += comic_flow.cpp \ ../common/opengl_checker.cpp \ yacreader_comics_views_manager.cpp \ info_comics_view.cpp \ - yacreader_comics_selection_helper.cpp + yacreader_comics_selection_helper.cpp \ + yacreader_comic_info_helper.cpp !CONFIG(no_opengl) { CONFIG(legacy_gl_widget) { diff --git a/YACReaderLibrary/comics_view.cpp b/YACReaderLibrary/comics_view.cpp index fdc8c16f..96e46f75 100644 --- a/YACReaderLibrary/comics_view.cpp +++ b/YACReaderLibrary/comics_view.cpp @@ -26,10 +26,12 @@ void ComicsView::updateInfoForIndex(int index) comicDB = new ComicDB(model->getComic(this->model->index(index, 0))); ComicInfo *comicInfo = &(comicDB->info); + comicInfo->isFavorite = model->isFavorite(model->index(index,0)); + ctxt->setContextProperty("comic", comicDB); ctxt->setContextProperty("comicInfo", comicInfo); - ctxt->setContextProperty("is_favorite", model->isFavorite(model->index(index,0))); + ctxt->setContextProperty("comic_info_index", index); } void ComicsView::dragEnterEvent(QDragEnterEvent *event) diff --git a/YACReaderLibrary/db/comic_model.cpp b/YACReaderLibrary/db/comic_model.cpp index 896fdf7a..cb9efa17 100644 --- a/YACReaderLibrary/db/comic_model.cpp +++ b/YACReaderLibrary/db/comic_model.cpp @@ -1107,8 +1107,8 @@ void ComicModel::deleteComicsFromFavorites(const QList &comicsList) db.close(); QSqlDatabase::removeDatabase(_databasePath); - deleteComicsFromModel(comicsList); - + if(mode == Favorites) + deleteComicsFromModel(comicsList); } void ComicModel::deleteComicsFromLabel(const QList &comicsList, qulonglong labelId) diff --git a/YACReaderLibrary/grid_comics_view.cpp b/YACReaderLibrary/grid_comics_view.cpp index 4e56d96e..b0355df0 100644 --- a/YACReaderLibrary/grid_comics_view.cpp +++ b/YACReaderLibrary/grid_comics_view.cpp @@ -10,6 +10,7 @@ #include "yacreader_tool_bar_stretch.h" #include "comic_db.h" #include "yacreader_comics_selection_helper.h" +#include "yacreader_comic_info_helper.h" //values relative to visible cells const unsigned int YACREADER_MIN_GRID_ZOOM_WIDTH = 156; @@ -47,6 +48,8 @@ GridComicsView::GridComicsView(QWidget *parent) : selectionHelper = new YACReaderComicsSelectionHelper(this); connect(selectionHelper, &YACReaderComicsSelectionHelper::selectionChanged, this, &GridComicsView::dummyUpdater); + comicInfoHelper = new YACReaderComicInfoHelper(this); + QQmlContext *ctxt = view->rootContext(); #ifdef Q_OS_MAC @@ -174,6 +177,7 @@ void GridComicsView::setModel(ComicModel *model) ComicsView::setModel(model); selectionHelper->setModel(model); + comicInfoHelper->setModel(model); QQmlContext *ctxt = view->rootContext(); @@ -186,6 +190,7 @@ void GridComicsView::setModel(ComicModel *model) ctxt->setContextProperty("dummyValue", true); ctxt->setContextProperty("dragManager", this); ctxt->setContextProperty("dropManager", this); + ctxt->setContextProperty("comicInfoHelper", comicInfoHelper); updateBackgroundConfig(); diff --git a/YACReaderLibrary/grid_comics_view.h b/YACReaderLibrary/grid_comics_view.h index 006c7ed7..9aa6b9b8 100644 --- a/YACReaderLibrary/grid_comics_view.h +++ b/YACReaderLibrary/grid_comics_view.h @@ -5,6 +5,8 @@ #include + + class QAbstractListModel; class QItemSelectionModel; class QQuickView; @@ -12,6 +14,9 @@ class QQuickView; class YACReaderToolBarStretch; class YACReaderComicsSelectionHelper; +class YACReaderComicInfoHelper; + + class GridComicsView : public ComicsView { @@ -74,6 +79,7 @@ private: QAction * showInfoAction; YACReaderComicsSelectionHelper * selectionHelper; + YACReaderComicInfoHelper * comicInfoHelper; bool dummy; void closeEvent ( QCloseEvent * event ); diff --git a/YACReaderLibrary/info_comics_view.cpp b/YACReaderLibrary/info_comics_view.cpp index 3893e226..5912686b 100644 --- a/YACReaderLibrary/info_comics_view.cpp +++ b/YACReaderLibrary/info_comics_view.cpp @@ -6,6 +6,7 @@ #include "comic_files_manager.h" #include "comic_model.h" #include "comic_db.h" +#include "yacreader_comic_info_helper.h" #include "yacreader_comics_selection_helper.h" #include "QsLog.h" @@ -33,6 +34,7 @@ InfoComicsView::InfoComicsView(QWidget *parent) connect(flow, SIGNAL(currentCoverChanged(int)), this, SLOT(setCurrentIndex(int))); selectionHelper = new YACReaderComicsSelectionHelper(this); + comicInfoHelper = new YACReaderComicInfoHelper(this); QVBoxLayout * l = new QVBoxLayout; l->addWidget(container); @@ -64,6 +66,7 @@ void InfoComicsView::setModel(ComicModel *model) return; selectionHelper->setModel(model); + comicInfoHelper->setModel(model); ComicsView::setModel(model); @@ -83,9 +86,8 @@ void InfoComicsView::setModel(ComicModel *model) ctxt->setContextProperty("comicsSelection", selectionHelper->selectionModel()); ctxt->setContextProperty("contextMenuHelper",this); ctxt->setContextProperty("currentIndexHelper", this); + ctxt->setContextProperty("comicInfoHelper", comicInfoHelper); /*ctxt->setContextProperty("comicsSelectionHelper", this); - ctxt->setContextProperty("comicRatingHelper", this); - ctxt->setContextProperty("dummyValue", true); ctxt->setContextProperty("dragManager", this);*/ ctxt->setContextProperty("dropManager", this); diff --git a/YACReaderLibrary/info_comics_view.h b/YACReaderLibrary/info_comics_view.h index 0180600a..53699148 100644 --- a/YACReaderLibrary/info_comics_view.h +++ b/YACReaderLibrary/info_comics_view.h @@ -8,6 +8,7 @@ class QQuickView; class YACReaderComicsSelectionHelper; +class YACReaderComicInfoHelper; @@ -49,6 +50,7 @@ protected: QObject *list; YACReaderComicsSelectionHelper * selectionHelper; + YACReaderComicInfoHelper * comicInfoHelper; }; #endif // INFOCOMICSVIEW_H diff --git a/YACReaderLibrary/qml/ComicInfo.qml b/YACReaderLibrary/qml/ComicInfo.qml index f1f48084..ce6f86e2 100644 --- a/YACReaderLibrary/qml/ComicInfo.qml +++ b/YACReaderLibrary/qml/ComicInfo.qml @@ -55,6 +55,7 @@ Rectangle { onReadChangedByUser: { comicInfo.read = read; + comicInfoHelper.setRead(comic_info_index, read); } } } @@ -87,6 +88,7 @@ Rectangle { onReadChangedByUser: { comicInfo.read = read; + comicInfoHelper.setRead(comic_info_index, read); } } @@ -99,13 +101,27 @@ Rectangle { Layout.rightMargin: 17 Layout.alignment: Qt.AlignTop - active: is_favorite + active: comicInfo.isFavorite + + onActiveChangedByUser: { + if(active) + comicInfoHelper.addToFavorites(comic_info_index); + else + comicInfoHelper.removeFromFavorites(comic_info_index); + + comicInfo.isFavorite = active; + } } InfoRating { Layout.alignment: Qt.AlignTop Layout.rightMargin: 30 rating: comicInfo.rating + + onRatingChangedByUser: { + comicInfo.rating = rating; + comicInfoHelper.rate(comic_info_index, rating); + } } visible: mainContainer.compact @@ -141,13 +157,27 @@ Rectangle { Layout.rightMargin: 17 Layout.alignment: Qt.AlignTop - active: is_favorite + active: comicInfo.isFavorite + + onActiveChangedByUser: { + if(active) + comicInfoHelper.addToFavorites(comic_info_index); + else + comicInfoHelper.removeFromFavorites(comic_info_index); + + comicInfo.isFavorite = active; + } } InfoRating { Layout.alignment: Qt.AlignTop Layout.rightMargin: 30 rating: comicInfo.rating + + onRatingChangedByUser: { + comicInfo.rating = rating; + comicInfoHelper.rate(comic_info_index, rating); + } } } } diff --git a/YACReaderLibrary/qml/InfoFavorites.qml b/YACReaderLibrary/qml/InfoFavorites.qml index 8fd22d3c..daf6b956 100644 --- a/YACReaderLibrary/qml/InfoFavorites.qml +++ b/YACReaderLibrary/qml/InfoFavorites.qml @@ -8,7 +8,7 @@ Item { property bool active - signal activeChangedByUser(bool read) + signal activeChangedByUser(bool active) MouseArea { anchors.fill: favorites_button_compact diff --git a/YACReaderLibrary/yacreader_comic_info_helper.cpp b/YACReaderLibrary/yacreader_comic_info_helper.cpp new file mode 100644 index 00000000..45ee091f --- /dev/null +++ b/YACReaderLibrary/yacreader_comic_info_helper.cpp @@ -0,0 +1,45 @@ +#include "yacreader_comic_info_helper.h" + + + +#include "comic_model.h" + + + +YACReaderComicInfoHelper::YACReaderComicInfoHelper(QObject *parent) + : QObject(parent), model(nullptr) +{ + +} + +void YACReaderComicInfoHelper::setModel(ComicModel *model) +{ + this->model = model; +} + +void YACReaderComicInfoHelper::rate(int index, int rating) +{ + if(model != nullptr) + model->updateRating(rating,model->index(index,0)); +} + +void YACReaderComicInfoHelper::setRead(int index, bool read) +{ + YACReaderComicReadStatus status; + read ? (status = YACReaderComicReadStatus::Read) : (status = YACReaderComicReadStatus::Unread); + + if(model != nullptr) + model->setComicsRead(QModelIndexList() << model->index(index, 0), status); +} + +void YACReaderComicInfoHelper::addToFavorites(int index) +{ + if(model != nullptr) + model->addComicsToFavorites(QModelIndexList() << model->index(index, 0)); +} + +void YACReaderComicInfoHelper::removeFromFavorites(int index) +{ + if(model != nullptr) + model->deleteComicsFromFavorites(QModelIndexList() << model->index(index, 0)); +} diff --git a/YACReaderLibrary/yacreader_comic_info_helper.h b/YACReaderLibrary/yacreader_comic_info_helper.h new file mode 100644 index 00000000..13bd85b4 --- /dev/null +++ b/YACReaderLibrary/yacreader_comic_info_helper.h @@ -0,0 +1,31 @@ +#ifndef YACREADERCOMICINFOHELPER_H +#define YACREADERCOMICINFOHELPER_H + +#include + + +class ComicModel; + + +class YACReaderComicInfoHelper : public QObject +{ + Q_OBJECT +public: + explicit YACReaderComicInfoHelper(QObject *parent = 0); + + void setModel(ComicModel *model); + + Q_INVOKABLE void rate(int index, int rating); + Q_INVOKABLE void setRead(int index, bool read); + Q_INVOKABLE void addToFavorites(int index); + Q_INVOKABLE void removeFromFavorites(int index); + +signals: + +public slots: + +protected: + ComicModel *model; +}; + +#endif // YACREADERCOMICINFOHELPER_H diff --git a/common/comic_db.cpp b/common/comic_db.cpp index f06bd30b..2f88ee58 100644 --- a/common/comic_db.cpp +++ b/common/comic_db.cpp @@ -463,6 +463,15 @@ void ComicInfo::setRating(int r) } } +void ComicInfo::setFavorite(bool f) +{ + if(f != isFavorite) + { + isFavorite = f; + emit favoriteChanged(); + } +} + QDataStream &operator<<(QDataStream & stream, const ComicDB & comic) { stream << comic.id; diff --git a/common/comic_db.h b/common/comic_db.h index 2303f30d..5850de65 100644 --- a/common/comic_db.h +++ b/common/comic_db.h @@ -186,14 +186,20 @@ public: Q_PROPERTY(QImage cover MEMBER cover CONSTANT) + //-new properties, not loaded from the DB automatically + bool isFavorite; + Q_PROPERTY(bool isFavorite MEMBER isFavorite WRITE setFavorite NOTIFY favoriteChanged) + //setters, used in QML only by now void setRead(bool r); void setRating(int r); + void setFavorite(bool f); private: signals: void readChanged(); void ratingChanged(); + void favoriteChanged(); };