[app] BooksListWatcher should emit sizeChanged when view is assigned

This commit is contained in:
Slava Monich 2016-11-02 23:52:40 +03:00
parent b227c42e1d
commit 3fbe9561be
2 changed files with 25 additions and 14 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2015 Jolla Ltd. * Copyright (C) 2015-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com> * Contact: Slava Monich <slava.monich@jolla.com>
* *
* You may use this file under the terms of the BSD license as follows: * You may use this file under the terms of the BSD license as follows:
@ -14,7 +14,7 @@
* notice, this list of conditions and the following disclaimer in * notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the * the documentation and/or other materials provided with the
* distribution. * distribution.
* * Neither the name of Nemo Mobile nor the names of its contributors * * Neither the name of Jolla Ltd nor the names of its contributors
* may be used to endorse or promote products derived from this * may be used to endorse or promote products derived from this
* software without specific prior written permission. * software without specific prior written permission.
* *
@ -79,12 +79,13 @@ void BooksListWatcher::setListView(QQuickItem* aView)
SLOT(onContentSizeChanged())); SLOT(onContentSizeChanged()));
iContentX = contentX(); iContentX = contentX();
iContentY = contentY(); iContentY = contentY();
updateCurrentIndex(); iSize = QSize(iListView->width(), iListView->height());
} else { } else {
iContentX = iContentY = 0; iContentX = iContentY = 0;
iSize = QSize(0,0); iSize = QSize(0,0);
} }
Q_EMIT listViewChanged(); Q_EMIT listViewChanged();
updateCurrentIndex();
if (oldSize != iSize) { if (oldSize != iSize) {
Q_EMIT sizeChanged(); Q_EMIT sizeChanged();
} }
@ -119,17 +120,26 @@ qreal BooksListWatcher::contentY()
return getRealProperty(LISTVIEW_CONTENT_Y); return getRealProperty(LISTVIEW_CONTENT_Y);
} }
int BooksListWatcher::getCurrentIndex()
{
if (iListView) {
int index = -1;
if (QMetaObject::invokeMethod(iListView, LISTVIEW_INDEX_AT,
Q_RETURN_ARG(int,index), Q_ARG(qreal,iContentX+width()/2),
Q_ARG(qreal,iContentY+height()/2))) {
return index;
}
}
return -1;
}
void BooksListWatcher::updateCurrentIndex() void BooksListWatcher::updateCurrentIndex()
{ {
int index = -1; const int index = getCurrentIndex();
if (QMetaObject::invokeMethod(iListView, LISTVIEW_INDEX_AT, if (iCurrentIndex != index) {
Q_RETURN_ARG(int,index), Q_ARG(qreal,iContentX+width()/2), HDEBUG(index);
Q_ARG(qreal,iContentY+height()/2))) { iCurrentIndex = index;
if (iCurrentIndex != index) { Q_EMIT currentIndexChanged();
HDEBUG(index);
iCurrentIndex = index;
Q_EMIT currentIndexChanged();
}
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2015 Jolla Ltd. * Copyright (C) 2015-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com> * Contact: Slava Monich <slava.monich@jolla.com>
* *
* You may use this file under the terms of the BSD license as follows: * You may use this file under the terms of the BSD license as follows:
@ -14,7 +14,7 @@
* notice, this list of conditions and the following disclaimer in * notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the * the documentation and/or other materials provided with the
* distribution. * distribution.
* * Neither the name of Nemo Mobile nor the names of its contributors * * Neither the name of Jolla Ltd nor the names of its contributors
* may be used to endorse or promote products derived from this * may be used to endorse or promote products derived from this
* software without specific prior written permission. * software without specific prior written permission.
* *
@ -63,6 +63,7 @@ private:
qreal contentX(); qreal contentX();
qreal contentY(); qreal contentY();
qreal getRealProperty(const char *name, qreal defaultValue = 0.0); qreal getRealProperty(const char *name, qreal defaultValue = 0.0);
int getCurrentIndex();
void updateCurrentIndex(); void updateCurrentIndex();
void updateSize(); void updateSize();