mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
Use the comics selection helper in the info comics view.
This commit is contained in:
parent
771597e4f4
commit
c052a82195
@ -4,11 +4,12 @@
|
|||||||
|
|
||||||
#include "comic_model.h"
|
#include "comic_model.h"
|
||||||
#include "comic_db.h"
|
#include "comic_db.h"
|
||||||
|
#include "yacreader_comics_selection_helper.h"
|
||||||
|
|
||||||
#include "QsLog.h"
|
#include "QsLog.h"
|
||||||
|
|
||||||
InfoComicsView::InfoComicsView(QWidget *parent)
|
InfoComicsView::InfoComicsView(QWidget *parent)
|
||||||
:ComicsView(parent),_selectionModel(nullptr)
|
:ComicsView(parent)
|
||||||
{
|
{
|
||||||
qmlRegisterType<ComicModel>("com.yacreader.ComicModel",1,0,"ComicModel");
|
qmlRegisterType<ComicModel>("com.yacreader.ComicModel",1,0,"ComicModel");
|
||||||
qmlRegisterType<ComicDB>("com.yacreader.ComicDB",1,0,"ComicDB");
|
qmlRegisterType<ComicDB>("com.yacreader.ComicDB",1,0,"ComicDB");
|
||||||
@ -29,6 +30,8 @@ InfoComicsView::InfoComicsView(QWidget *parent)
|
|||||||
connect(flow, SIGNAL(currentCoverChanged(int)), this, SLOT(updateInfoForIndex(int)));
|
connect(flow, SIGNAL(currentCoverChanged(int)), this, SLOT(updateInfoForIndex(int)));
|
||||||
connect(flow, SIGNAL(currentCoverChanged(int)), this, SLOT(setCurrentIndex(int)));
|
connect(flow, SIGNAL(currentCoverChanged(int)), this, SLOT(setCurrentIndex(int)));
|
||||||
|
|
||||||
|
selectionHelper = new YACReaderComicsSelectionHelper(this);
|
||||||
|
|
||||||
QVBoxLayout * l = new QVBoxLayout;
|
QVBoxLayout * l = new QVBoxLayout;
|
||||||
l->addWidget(container);
|
l->addWidget(container);
|
||||||
this->setLayout(l);
|
this->setLayout(l);
|
||||||
@ -58,10 +61,7 @@ void InfoComicsView::setModel(ComicModel *model)
|
|||||||
if(model == NULL)
|
if(model == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(_selectionModel != nullptr)
|
selectionHelper->setModel(model);
|
||||||
delete _selectionModel;
|
|
||||||
|
|
||||||
_selectionModel = new QItemSelectionModel(model);
|
|
||||||
|
|
||||||
ComicsView::setModel(model);
|
ComicsView::setModel(model);
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ void InfoComicsView::setModel(ComicModel *model)
|
|||||||
else
|
else
|
||||||
ctxt->setContextProperty("backgroundImage", QUrl());
|
ctxt->setContextProperty("backgroundImage", QUrl());
|
||||||
|
|
||||||
ctxt->setContextProperty("comicsSelection", _selectionModel);
|
ctxt->setContextProperty("comicsSelection", selectionHelper->selectionModel());
|
||||||
/*ctxt->setContextProperty("contextMenuHelper",this);
|
/*ctxt->setContextProperty("contextMenuHelper",this);
|
||||||
ctxt->setContextProperty("comicsSelectionHelper", this);
|
ctxt->setContextProperty("comicsSelectionHelper", this);
|
||||||
ctxt->setContextProperty("comicRatingHelper", this);
|
ctxt->setContextProperty("comicRatingHelper", this);
|
||||||
@ -99,40 +99,24 @@ void InfoComicsView::setCurrentIndex(const QModelIndex &index)
|
|||||||
{
|
{
|
||||||
QQmlProperty(list, "currentIndex").write(index.row());
|
QQmlProperty(list, "currentIndex").write(index.row());
|
||||||
|
|
||||||
_selectionModel->clear();
|
selectionHelper->clear();
|
||||||
_selectionModel->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
selectionHelper->selectIndex(index.row());
|
||||||
}
|
}
|
||||||
|
|
||||||
void InfoComicsView::setCurrentIndex(int index)
|
void InfoComicsView::setCurrentIndex(int index)
|
||||||
{
|
{
|
||||||
_selectionModel->clear();
|
selectionHelper->clear();
|
||||||
_selectionModel->select(model->index(index,0), QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
selectionHelper->selectIndex(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex InfoComicsView::currentIndex()
|
QModelIndex InfoComicsView::currentIndex()
|
||||||
{
|
{
|
||||||
if(!_selectionModel)
|
return selectionHelper->currentIndex();
|
||||||
return QModelIndex();
|
|
||||||
|
|
||||||
QModelIndexList indexes = _selectionModel->selectedRows();
|
|
||||||
if(indexes.length()>0)
|
|
||||||
return indexes[0];
|
|
||||||
|
|
||||||
this->selectIndex(0);
|
|
||||||
indexes = _selectionModel->selectedRows();
|
|
||||||
if(indexes.length()>0)
|
|
||||||
return indexes[0];
|
|
||||||
else
|
|
||||||
return QModelIndex();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QItemSelectionModel *InfoComicsView::selectionModel()
|
QItemSelectionModel *InfoComicsView::selectionModel()
|
||||||
{
|
{
|
||||||
QModelIndexList indexes = _selectionModel->selectedRows();
|
return selectionHelper->selectionModel();
|
||||||
if(indexes.length()==0)
|
|
||||||
this->selectIndex(0);
|
|
||||||
|
|
||||||
return _selectionModel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InfoComicsView::scrollTo(const QModelIndex &mi, QAbstractItemView::ScrollHint hint)
|
void InfoComicsView::scrollTo(const QModelIndex &mi, QAbstractItemView::ScrollHint hint)
|
||||||
@ -163,10 +147,7 @@ void InfoComicsView::enableFilterMode(bool enabled)
|
|||||||
|
|
||||||
void InfoComicsView::selectIndex(int index)
|
void InfoComicsView::selectIndex(int index)
|
||||||
{
|
{
|
||||||
if(_selectionModel != nullptr && model!=NULL)
|
selectionHelper->selectIndex(index);
|
||||||
{
|
|
||||||
_selectionModel->select(model->index(index,0),QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InfoComicsView::setShowMarks(bool show)
|
void InfoComicsView::setShowMarks(bool show)
|
||||||
@ -177,8 +158,5 @@ void InfoComicsView::setShowMarks(bool show)
|
|||||||
|
|
||||||
void InfoComicsView::selectAll()
|
void InfoComicsView::selectAll()
|
||||||
{
|
{
|
||||||
QModelIndex top = model->index(0, 0);
|
selectionHelper->selectAll();
|
||||||
QModelIndex bottom = model->index(model->rowCount()-1, 0);
|
|
||||||
QItemSelection selection(top, bottom);
|
|
||||||
_selectionModel->select(selection, QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
class QQuickView;
|
class QQuickView;
|
||||||
|
|
||||||
|
class YACReaderComicsSelectionHelper;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class InfoComicsView : public ComicsView
|
class InfoComicsView : public ComicsView
|
||||||
@ -39,7 +41,7 @@ protected:
|
|||||||
QObject *flow;
|
QObject *flow;
|
||||||
QObject *list;
|
QObject *list;
|
||||||
|
|
||||||
QItemSelectionModel * _selectionModel;
|
YACReaderComicsSelectionHelper * selectionHelper;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // INFOCOMICSVIEW_H
|
#endif // INFOCOMICSVIEW_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user