diff options
-rw-r--r-- | qml/TopicPage.qml | 37 |
1 files changed, 37 insertions, 0 deletions
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 } |