Add current/next comic view to GridView.

This commit is contained in:
Luis Ángel San Martín
2018-04-23 19:22:51 +02:00
parent b41884d5db
commit f6d389ff35
23 changed files with 933 additions and 32 deletions

View File

@ -11,6 +11,7 @@
#include "comic_db.h"
#include "yacreader_comics_selection_helper.h"
#include "yacreader_comic_info_helper.h"
#include "current_comic_view_helper.h"
//values relative to visible cells
const unsigned int YACREADER_MIN_GRID_ZOOM_WIDTH = 156;
@ -30,7 +31,7 @@ const unsigned int YACREADER_MIN_ITEM_WIDTH = YACREADER_MIN_COVER_WIDTH;
GridComicsView::GridComicsView(QWidget *parent) :
ComicsView(parent)
ComicsView(parent), filterEnabled(false)
{
settings = new QSettings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini", QSettings::IniFormat, this);
settings->beginGroup("libraryConfig");
@ -151,6 +152,7 @@ GridComicsView::GridComicsView(QWidget *parent) :
ctxt->setContextProperty("dummyValue", true);
ctxt->setContextProperty("dragManager", this);
ctxt->setContextProperty("dropManager", this);
ctxt->setContextProperty("comicOpener", this);
bool showInfo = settings->value(COMICS_GRID_SHOW_INFO, false).toBool();
ctxt->setContextProperty("showInfo", showInfo);
@ -237,6 +239,8 @@ void GridComicsView::setModel(ComicModel *model)
ComicsView::setModel(model);
setCurrentComicIfNeeded();
selectionHelper->setModel(model);
comicInfoHelper->setModel(model);
@ -255,12 +259,18 @@ void GridComicsView::setModel(ComicModel *model)
updateBackgroundConfig();
selectionHelper->clear();
if(model->rowCount()>0)
{
setCurrentIndex(model->index(0,0));
if(showInfoAction->isChecked())
updateInfoForIndex(0);
}
//If the currentComicView was hidden before showing it sometimes the scroll view doesn't show it
//this is a hacky solution...
QTimer::singleShot(0, this, SLOT(resetScroll()));
}
void GridComicsView::updateBackgroundConfig()
@ -360,7 +370,16 @@ void GridComicsView::updateConfig(QSettings *settings)
void GridComicsView::enableFilterMode(bool enabled)
{
Q_UNUSED(enabled);
filterEnabled = enabled;
QQmlContext *ctxt = view->rootContext();
if (enabled) {
ctxt->setContextProperty("showCurrentComic", false);
ctxt->setContextProperty("currentComic", nullptr);
} else {
setCurrentComicIfNeeded();
}
}
void GridComicsView::selectAll()
@ -373,6 +392,11 @@ void GridComicsView::selectIndex(int index)
selectionHelper->selectIndex(index);
}
void GridComicsView::triggerOpenCurrentComic()
{
emit openComic(currentComic);
}
void GridComicsView::rate(int index, int rating)
{
model->updateRating(rating,model->index(index,0));
@ -414,6 +438,36 @@ void GridComicsView::dummyUpdater()
ctxt->setContextProperty("dummyValue", true);
}
void GridComicsView::setCurrentComicIfNeeded()
{
bool found;
currentComic = currentComicFromModel(model, found);
QQmlContext *ctxt = view->rootContext();
if (found && filterEnabled == false) {
ctxt->setContextProperty("currentComic", &currentComic);
ctxt->setContextProperty("currentComicInfo", &(currentComic.info));
ctxt->setContextProperty("showCurrentComic", true);
}
else
{
ctxt->setContextProperty("currentComic", &currentComic);
ctxt->setContextProperty("currentComicInfo", &(currentComic.info));
ctxt->setContextProperty("showCurrentComic", false);
//ctxt->setContextProperty("currentComic", nullptr);
}
}
void GridComicsView::resetScroll()
{
QObject *rootObject = dynamic_cast<QObject*>(view->rootObject());
QObject *scrollView = rootObject->findChild<QObject*>("topScrollView", Qt::FindChildrenRecursively);
QMetaObject::invokeMethod(scrollView, "scrollToOrigin");
}
QSize GridComicsView::sizeHint()
{
return QSize(1280,768);
@ -431,6 +485,11 @@ QByteArray GridComicsView::getMimeDataFromSelection()
return data;
}
void GridComicsView::updateCurrentComicView()
{
setCurrentComicIfNeeded();
}
void GridComicsView::startDrag()
{
QDrag *drag = new QDrag(this);
@ -498,7 +557,7 @@ void GridComicsView::closeEvent(QCloseEvent *event)
toolbar->removeAction(coverSizeSliderAction);
QObject *rootObject = dynamic_cast<QObject*>(view->rootObject());
QObject *infoContainer = rootObject->findChild<QObject*>("infoContainer");
QObject *infoContainer = rootObject->findChild<QObject*>("infoContainer", Qt::FindChildrenRecursively);
int infoWidth = QQmlProperty(infoContainer, "width").read().toInt();