Link the FlowView in QML with the c++ view controller, so the comic info can be updated whenever the selected comic changes.

This commit is contained in:
Luis Ángel San Martín 2016-04-10 20:11:30 +02:00
parent af772f8aee
commit 8807a3b509
3 changed files with 19 additions and 0 deletions

View File

@ -3,6 +3,7 @@
#include <QtQuick>
#include "comic_model.h"
#include "comic_db.h"
#include "QsLog.h"
@ -10,6 +11,7 @@ InfoComicsView::InfoComicsView(QWidget *parent)
:ComicsView(parent)
{
qmlRegisterType<ComicModel>("com.yacreader.ComicModel",1,0,"ComicModel");
qmlRegisterType<ComicInfo>("com.yacreader.ComicInfo",1,0,"ComicInfo");
view = new QQuickView();
container = QWidget::createWindowContainer(view, this);
@ -18,6 +20,13 @@ InfoComicsView::InfoComicsView(QWidget *parent)
view->setSource(QUrl("qrc:/qml/InfoComicsView.qml"));
QObject *rootObject = dynamic_cast<QObject*>(view->rootObject());
flow = rootObject->findChild<QObject*>("flow");
list = rootObject->findChild<QObject*>("list");
connect(flow, SIGNAL(currentCoverChanged(int)), this, SLOT(updateInfoForIndex(int)));
QVBoxLayout * l = new QVBoxLayout;
l->addWidget(container);
this->setLayout(l);
@ -71,6 +80,12 @@ void InfoComicsView::setModel(ComicModel *model)
}
void InfoComicsView::setCurrentIndex(const QModelIndex &index)
{
QQmlProperty(list, "currentIndex").write(index.row());
}
void InfoComicsView::updateInfoForIndex(int index)
{
int FIXME;
}

View File

@ -27,12 +27,15 @@ public:
void selectIndex(int index);
public slots:
void updateInfoForIndex(int index);
void setShowMarks(bool show);
void selectAll();
protected:
QQuickView *view;
QWidget *container;
QObject *flow;
QObject *list;
};
#endif // INFOCOMICSVIEW_H

View File

@ -17,6 +17,7 @@ Rectangle {
FlowView {
id: flow
objectName: "flow"
height: 256 //TODO dynamic size?
anchors.top: parent.top