diff options
Diffstat (limited to 'framework/qml/ConversationListView.qml')
-rw-r--r-- | framework/qml/ConversationListView.qml | 130 |
1 files changed, 67 insertions, 63 deletions
diff --git a/framework/qml/ConversationListView.qml b/framework/qml/ConversationListView.qml index fb91e14d..b00002b1 100644 --- a/framework/qml/ConversationListView.qml +++ b/framework/qml/ConversationListView.qml | |||
@@ -24,11 +24,11 @@ import org.kube.framework 1.0 as Kube | |||
24 | 24 | ||
25 | import QtQml 2.2 as QtQml | 25 | import QtQml 2.2 as QtQml |
26 | 26 | ||
27 | Flickable { | 27 | FocusScope { |
28 | id: root | 28 | id: root |
29 | focus: true | ||
30 | property alias model: repeater.model | 29 | property alias model: repeater.model |
31 | property alias delegate: repeater.delegate | 30 | property alias delegate: repeater.delegate |
31 | property alias contentHeight: flickable.contentHeight | ||
32 | property int currentIndex: -1 | 32 | property int currentIndex: -1 |
33 | 33 | ||
34 | property var currentItem: null | 34 | property var currentItem: null |
@@ -56,83 +56,87 @@ Flickable { | |||
56 | setCurrentItem() | 56 | setCurrentItem() |
57 | } | 57 | } |
58 | 58 | ||
59 | //Optimize for view quality | 59 | Flickable { |
60 | pixelAligned: true | 60 | id: flickable |
61 | 61 | anchors.fill: parent | |
62 | contentWidth: width | ||
63 | contentHeight: col.height | ||
64 | 62 | ||
65 | function scrollToIndex(index) { | 63 | //Optimize for view quality |
66 | var item = repeater.itemAt(index) | 64 | pixelAligned: true |
67 | var pos = item.y | 65 | |
68 | var scrollToEndPos = (root.contentHeight - root.height) | 66 | contentWidth: width |
69 | //Avoid scrolling past the end | 67 | contentHeight: col.height |
70 | if (pos < scrollToEndPos) { | 68 | |
71 | root.contentY = pos | 69 | function scrollToIndex(index) { |
72 | } else { | 70 | var item = repeater.itemAt(index) |
73 | root.contentY = scrollToEndPos | 71 | var pos = item.y |
72 | var scrollToEndPos = (flickable.contentHeight - flickable.height) | ||
73 | //Avoid scrolling past the end | ||
74 | if (pos < scrollToEndPos) { | ||
75 | flickable.contentY = pos | ||
76 | } else { | ||
77 | flickable.contentY = scrollToEndPos | ||
78 | } | ||
74 | } | 79 | } |
75 | } | ||
76 | 80 | ||
77 | onContentHeightChanged: { | 81 | onContentHeightChanged: { |
78 | if (repeater.count) { | 82 | if (repeater.count) { |
79 | //Scroll to the last item | 83 | //Scroll to the last item |
80 | currentIndex = repeater.count - 1 | 84 | currentIndex = repeater.count - 1 |
81 | scrollToIndex(repeater.count - 1) | 85 | scrollToIndex(repeater.count - 1) |
86 | } | ||
82 | } | 87 | } |
83 | } | ||
84 | 88 | ||
85 | property real span : contentY + height | 89 | Column { |
86 | Column { | 90 | id: col |
87 | id: col | 91 | width: parent.width |
88 | width: parent.width | 92 | spacing: 2 |
89 | spacing: 2 | 93 | Repeater { |
90 | Repeater { | 94 | id: repeater |
91 | id: repeater | 95 | onCountChanged: { |
92 | onCountChanged: { | 96 | for (var i = 0; i < count; i++) { |
93 | for (var i = 0; i < count; i++) { | 97 | itemAt(i).index = i |
94 | itemAt(i).index = i | 98 | } |
95 | } | 99 | } |
96 | } | 100 | } |
97 | } | 101 | } |
98 | } | ||
99 | 102 | ||
100 | function incrementCurrentIndex() { | 103 | function incrementCurrentIndex() { |
101 | if (currentIndex < repeater.count - 1) { | 104 | if (currentIndex < repeater.count - 1) { |
102 | currentIndex = currentIndex + 1 | 105 | currentIndex = currentIndex + 1 |
106 | } | ||
103 | } | 107 | } |
104 | } | ||
105 | 108 | ||
106 | function decrementCurrentIndex() { | 109 | function decrementCurrentIndex() { |
107 | if (currentIndex > 0) { | 110 | if (currentIndex > 0) { |
108 | currentIndex = currentIndex - 1 | 111 | currentIndex = currentIndex - 1 |
112 | } | ||
109 | } | 113 | } |
110 | } | ||
111 | 114 | ||
112 | Keys.onDownPressed: { | 115 | Keys.onDownPressed: { |
113 | incrementCurrentIndex() | 116 | incrementCurrentIndex() |
114 | scrollToIndex(currentIndex) | 117 | scrollToIndex(currentIndex) |
115 | } | 118 | } |
116 | 119 | ||
117 | Keys.onUpPressed: { | 120 | Keys.onUpPressed: { |
118 | decrementCurrentIndex() | 121 | decrementCurrentIndex() |
119 | scrollToIndex(currentIndex) | 122 | scrollToIndex(currentIndex) |
120 | } | 123 | } |
121 | 124 | ||
122 | Kube.ScrollHelper { | 125 | Kube.ScrollHelper { |
123 | id: scrollHelper | 126 | id: scrollHelper |
124 | flickable: root | 127 | flickable: flickable |
125 | anchors.fill: parent | 128 | anchors.fill: parent |
126 | } | 129 | } |
127 | 130 | ||
128 | //Intercept all scroll events, | 131 | //Intercept all scroll events, |
129 | //necessary due to the webengineview | 132 | //necessary due to the webengineview |
130 | Kube.MouseProxy { | 133 | Kube.MouseProxy { |
131 | anchors.fill: parent | 134 | anchors.fill: parent |
132 | target: scrollHelper | 135 | target: scrollHelper |
133 | forwardWheelEvents: true | 136 | forwardWheelEvents: true |
134 | } | 137 | } |
135 | 138 | ||
136 | ScrollBar.vertical: ScrollBar {} | 139 | ScrollBar.vertical: ScrollBar {} |
137 | 140 | ||
141 | } | ||
138 | } | 142 | } |