From 564f185e62e85fbd1662e9da06abbd853bab7266 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Sun, 7 Apr 2013 03:42:44 +0200 Subject: try to keep the first unread post in view while loading --- qml/TopicPage.qml | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/qml/TopicPage.qml b/qml/TopicPage.qml index 32a86ec..8ff7127 100644 --- a/qml/TopicPage.qml +++ b/qml/TopicPage.qml @@ -12,6 +12,9 @@ Page { property Board board; property int topicId; + /** -1: Do not keep view; -2: Keep view on last post; >0: Keep view on a post. */ + property int _keepView: -1; + tools: ToolBarLayout { ToolIcon { platformIconId: "toolbar-back" @@ -42,9 +45,28 @@ Page { } ToolIcon { platformIconId: "toolbar-view-menu" + onClicked: (topicMenu.status === DialogStatus.Closed) ? topicMenu.open() : topicMenu.close() } } + Menu { + id: topicMenu + MenuLayout { + MenuItem { + text: qsTr("Go to first post"); + onClicked: postsView.positionViewAtIndex(0, ListView.Beginning); + } + MenuItem { + text: qsTr("Go to last post") + onClicked: { + _keepView = -2; // Keep on last post + postsView.positionViewAtEnd(); + } + } + } + + } + ListView { id: postsView anchors.fill: parent @@ -56,6 +78,7 @@ Page { onFirstUnreadPostChanged: { postsView.positionViewAtIndex(firstUnreadPost, ListView.Beginning); topicModel.markAsRead(); + _keepView = firstUnreadPost; } } section.property: "humanDate" @@ -164,6 +187,20 @@ Page { } } + Connections { + target: _keepView !== -1 ? postsView : null + onMovementStarted: { + _keepView = -1; // Disable keep view + } + onContentHeightChanged: { + if (_keepView == -2) { + postsView.positionViewAtEnd(); + } else if (_keepView >= 0) { + postsView.positionViewAtIndex(_keepView, ListView.Beginning); + } + } + } + ScrollDecorator { flickableItem: postsView } -- cgit v1.2.3