mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
Implemented logic for comic info interactive items (read, fav, rating)
This commit is contained in:
parent
6b9041c095
commit
64b77586fc
@ -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) {
|
||||
|
@ -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)
|
||||
|
@ -1107,8 +1107,8 @@ void ComicModel::deleteComicsFromFavorites(const QList<QModelIndex> &comicsList)
|
||||
db.close();
|
||||
QSqlDatabase::removeDatabase(_databasePath);
|
||||
|
||||
deleteComicsFromModel(comicsList);
|
||||
|
||||
if(mode == Favorites)
|
||||
deleteComicsFromModel(comicsList);
|
||||
}
|
||||
|
||||
void ComicModel::deleteComicsFromLabel(const QList<QModelIndex> &comicsList, qulonglong labelId)
|
||||
|
@ -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();
|
||||
|
||||
|
@ -5,6 +5,8 @@
|
||||
|
||||
#include <QModelIndex>
|
||||
|
||||
|
||||
|
||||
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 );
|
||||
|
@ -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);
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
class QQuickView;
|
||||
|
||||
class YACReaderComicsSelectionHelper;
|
||||
class YACReaderComicInfoHelper;
|
||||
|
||||
|
||||
|
||||
@ -49,6 +50,7 @@ protected:
|
||||
QObject *list;
|
||||
|
||||
YACReaderComicsSelectionHelper * selectionHelper;
|
||||
YACReaderComicInfoHelper * comicInfoHelper;
|
||||
};
|
||||
|
||||
#endif // INFOCOMICSVIEW_H
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ Item {
|
||||
|
||||
property bool active
|
||||
|
||||
signal activeChangedByUser(bool read)
|
||||
signal activeChangedByUser(bool active)
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: favorites_button_compact
|
||||
|
45
YACReaderLibrary/yacreader_comic_info_helper.cpp
Normal file
45
YACReaderLibrary/yacreader_comic_info_helper.cpp
Normal file
@ -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));
|
||||
}
|
31
YACReaderLibrary/yacreader_comic_info_helper.h
Normal file
31
YACReaderLibrary/yacreader_comic_info_helper.h
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef YACREADERCOMICINFOHELPER_H
|
||||
#define YACREADERCOMICINFOHELPER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
|
||||
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
|
@ -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;
|
||||
|
@ -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();
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user