Changeset View
Changeset View
Standalone View
Standalone View
lib/qml/ResultsView.qml
Show All 18 Lines | |||||
19 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | 19 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
20 | * | 20 | * | ||
21 | */ | 21 | */ | ||
22 | 22 | | |||
23 | import QtQuick 2.1 | 23 | import QtQuick 2.1 | ||
24 | 24 | | |||
25 | import org.kde.plasma.components 2.0 as PlasmaComponents | 25 | import org.kde.plasma.components 2.0 as PlasmaComponents | ||
26 | import org.kde.plasma.core 2.0 as PlasmaCore | 26 | import org.kde.plasma.core 2.0 as PlasmaCore | ||
27 | import org.kde.milou 0.2 as Milou | 27 | import org.kde.milou 0.3 as Milou | ||
28 | 28 | | |||
29 | ListView { | 29 | ListView { | ||
30 | id: listView | 30 | id: listView | ||
31 | property alias queryString: resultModel.queryString | 31 | property alias queryString: resultModel.queryString | ||
32 | property alias runner: resultModel.runner | 32 | property alias runner: resultModel.runner | ||
33 | | ||||
33 | property alias runnerName: resultModel.runnerName | 34 | property alias runnerName: resultModel.runnerName | ||
34 | property alias runnerIcon: resultModel.runnerIcon | 35 | property alias runnerIcon: resultModel.runnerIcon | ||
36 | property alias querying: resultModel.querying | ||||
35 | property bool reversed | 37 | property bool reversed | ||
36 | signal activated | 38 | signal activated | ||
37 | signal updateQueryString(string text, int cursorPosition) | 39 | signal updateQueryString(string text, int cursorPosition) | ||
38 | 40 | | |||
39 | // NOTE this also flips increment/decrementCurrentIndex (Bug 360789) | 41 | // NOTE this also flips increment/decrementCurrentIndex (Bug 360789) | ||
40 | verticalLayoutDirection: reversed ? ListView.BottomToTop : ListView.TopToBottom | 42 | verticalLayoutDirection: reversed ? ListView.BottomToTop : ListView.TopToBottom | ||
41 | keyNavigationWraps: true | 43 | keyNavigationWraps: true | ||
42 | highlight: PlasmaComponents.Highlight {} | 44 | highlight: PlasmaComponents.Highlight {} | ||
43 | highlightMoveDuration: 0 | 45 | highlightMoveDuration: 0 | ||
44 | activeFocusOnTab: true | 46 | activeFocusOnTab: true | ||
45 | Accessible.role: Accessible.List | 47 | Accessible.role: Accessible.List | ||
46 | 48 | | |||
47 | section { | 49 | section { | ||
48 | criteria: ViewSection.FullString | 50 | criteria: ViewSection.FullString | ||
49 | property: "type" | 51 | property: "category" | ||
50 | } | 52 | } | ||
51 | 53 | | |||
52 | // This is used to keep track if the user has pressed enter before | 54 | // This is used to keep track if the user has pressed enter before | ||
53 | // the first result has been shown, in the case the first result should | 55 | // the first result has been shown, in the case the first result should | ||
54 | // be run when the model is populated | 56 | // be run when the model is populated | ||
55 | property bool runAutomatically | 57 | property bool runAutomatically | ||
56 | 58 | | |||
57 | // This is used to disable mouse selection if the user interacts only with keyboard | 59 | // This is used to disable mouse selection if the user interacts only with keyboard | ||
58 | property bool moved: false | 60 | property bool moved: false | ||
59 | property point savedMousePosition: Milou.MouseHelper.globalMousePosition() | 61 | property point savedMousePosition: Milou.MouseHelper.globalMousePosition() | ||
60 | function mouseMovedGlobally() { | 62 | function mouseMovedGlobally() { | ||
61 | return savedMousePosition != Milou.MouseHelper.globalMousePosition(); | 63 | return savedMousePosition != Milou.MouseHelper.globalMousePosition(); | ||
62 | } | 64 | } | ||
63 | 65 | | |||
64 | Milou.DragHelper { | 66 | Milou.DragHelper { | ||
65 | id: dragHelper | 67 | id: dragHelper | ||
66 | dragIconSize: units.iconSizes.medium | 68 | dragIconSize: units.iconSizes.medium | ||
67 | } | 69 | } | ||
68 | 70 | | |||
69 | model: Milou.SourcesModel { | 71 | model: Milou.ResultsModel { | ||
70 | id: resultModel | 72 | id: resultModel | ||
71 | queryLimit: 20 | 73 | limit: 20 | ||
72 | 74 | onQueryStringChangeRequested:{ | |||
73 | 75 | listView.updateQueryString(queryString, pos) | |||
74 | onUpdateSearchTerm: listView.updateQueryString(text, pos) | 76 | } | ||
75 | } | 77 | } | ||
76 | 78 | | |||
77 | // Internally when the query string changes, the model is reset | 79 | // Internally when the query string changes, the model is reset | ||
78 | // and the results are presented | 80 | // and the results are presented | ||
79 | onCountChanged: { | 81 | onCountChanged: { | ||
80 | listView.currentIndex = 0 | 82 | listView.currentIndex = 0 | ||
81 | listView.moved = false | 83 | listView.moved = false | ||
82 | listView.savedMousePosition = Milou.MouseHelper.globalMousePosition() | 84 | listView.savedMousePosition = Milou.MouseHelper.globalMousePosition() | ||
83 | 85 | | |||
davidedmundson: This recreates the bug I just fixed!
Adding a Qt.callLater round this would also work | |||||
84 | if (runAutomatically) { | 86 | if (runAutomatically) { | ||
85 | runCurrentIndex(); | 87 | runCurrentIndex(); | ||
Call it resetView()? Otherwise it seems like you're resetting the model again. apol: Call it `resetView()`? Otherwise it seems like you're resetting the model again. | |||||
86 | } | 88 | } | ||
87 | } | 89 | } | ||
88 | 90 | | |||
89 | delegate: ResultDelegate { | 91 | delegate: ResultDelegate { | ||
90 | id: resultDelegate | 92 | id: resultDelegate | ||
91 | width: listView.width | 93 | width: listView.width | ||
92 | } | 94 | } | ||
93 | 95 | | |||
Show All 17 Lines | 110 | if (event && event.modifiers === Qt.ShiftModifier | |||
111 | return | 113 | return | ||
112 | } | 114 | } | ||
113 | 115 | | |||
114 | if (currentItem.activeAction > -1) { | 116 | if (currentItem.activeAction > -1) { | ||
115 | runAction(currentItem.activeAction) | 117 | runAction(currentItem.activeAction) | ||
116 | return | 118 | return | ||
117 | } | 119 | } | ||
118 | 120 | | |||
119 | if (resultModel.run(currentIndex)) { | 121 | if (resultModel.run(resultModel.index(currentIndex, 0))) { | ||
120 | activated() | 122 | activated() | ||
121 | } | 123 | } | ||
122 | runAutomatically = false | 124 | runAutomatically = false | ||
123 | } | 125 | } | ||
124 | } | 126 | } | ||
125 | 127 | | |||
126 | function runAction(index) { | 128 | function runAction(index) { | ||
127 | if (resultModel.runAction(currentIndex, index)) { | 129 | if (resultModel.runAction(resultModel.index(currentIndex, 0), index)) { | ||
128 | activated() | 130 | activated() | ||
129 | } | 131 | } | ||
130 | } | 132 | } | ||
131 | 133 | | |||
132 | onActiveFocusChanged: { | 134 | onActiveFocusChanged: { | ||
133 | if (!activeFocus && currentIndex == listView.count-1) { | 135 | if (!activeFocus && currentIndex == listView.count-1) { | ||
134 | currentIndex = 0; | 136 | currentIndex = 0; | ||
135 | } | 137 | } | ||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | |||||
180 | Keys.onDownPressed: reversed ? decrementCurrentIndex() : incrementCurrentIndex(); | 182 | Keys.onDownPressed: reversed ? decrementCurrentIndex() : incrementCurrentIndex(); | ||
181 | 183 | | |||
182 | boundsBehavior: Flickable.StopAtBounds | 184 | boundsBehavior: Flickable.StopAtBounds | ||
183 | 185 | | |||
184 | function loadSettings() { | 186 | function loadSettings() { | ||
185 | resultModel.loadSettings() | 187 | resultModel.loadSettings() | ||
186 | } | 188 | } | ||
187 | 189 | | |||
188 | function setQueryString(string) { | 190 | function setQueryString(queryString) { | ||
189 | resultModel.queryString = string | 191 | resultModel.queryString = queryString | ||
190 | runAutomatically = false | 192 | runAutomatically = false | ||
191 | } | 193 | } | ||
192 | } | 194 | } |
This recreates the bug I just fixed!
Adding a Qt.callLater round this would also work