mirror of
https://github.com/YACReader/yacreader
synced 2025-07-14 02:54:46 -04:00
Add current/next comic view to GridView.
This commit is contained in:
@ -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", ¤tComic);
|
||||
ctxt->setContextProperty("currentComicInfo", &(currentComic.info));
|
||||
ctxt->setContextProperty("showCurrentComic", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
ctxt->setContextProperty("currentComic", ¤tComic);
|
||||
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();
|
||||
|
||||
|
Reference in New Issue
Block a user