Changeset View
Standalone View
applets/taskmanager/package/contents/ui/GroupDialog.qml
Show All 11 Lines | |||||
12 | * GNU General Public License for more details. * | 12 | * GNU General Public License for more details. * | ||
13 | * * | 13 | * * | ||
14 | * You should have received a copy of the GNU General Public License * | 14 | * You should have received a copy of the GNU General Public License * | ||
15 | * along with this program; if not, write to the * | 15 | * along with this program; if not, write to the * | ||
16 | * Free Software Foundation, Inc., * | 16 | * Free Software Foundation, Inc., * | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * | 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * | ||
18 | ***************************************************************************/ | 18 | ***************************************************************************/ | ||
19 | 19 | | |||
20 | import QtQuick 2.0 | 20 | import QtQuick 2.7 | ||
21 | import QtQuick.Window 2.2 | 21 | import QtQuick.Window 2.2 | ||
22 | 22 | | |||
23 | import org.kde.plasma.core 2.0 as PlasmaCore | 23 | import org.kde.plasma.core 2.0 as PlasmaCore | ||
24 | import org.kde.plasma.extras 2.0 as PlasmaExtras | ||||
24 | import org.kde.draganddrop 2.0 | 25 | import org.kde.draganddrop 2.0 | ||
25 | 26 | | |||
26 | import "../code/layout.js" as LayoutManager | 27 | import "../code/layout.js" as LayoutManager | ||
27 | 28 | | |||
28 | PlasmaCore.Dialog { | 29 | PlasmaCore.Dialog { | ||
29 | id: groupDialog | 30 | id: groupDialog | ||
30 | visible: false | 31 | visible: false | ||
31 | 32 | | |||
32 | type: PlasmaCore.Dialog.PopupMenu | 33 | type: PlasmaCore.Dialog.PopupMenu | ||
33 | flags: Qt.WindowStaysOnTopHint | 34 | flags: Qt.WindowStaysOnTopHint | ||
34 | hideOnWindowDeactivate: true | 35 | hideOnWindowDeactivate: true | ||
35 | location: plasmoid.location | 36 | location: plasmoid.location | ||
36 | 37 | | |||
37 | property int preferredWidth: Screen.width / (3 * Screen.devicePixelRatio) | 38 | property int preferredWidth: Screen.width / (3 * Screen.devicePixelRatio) | ||
38 | property int preferredHeight: Screen.height / (2 * Screen.devicePixelRatio) | 39 | property int preferredHeight: Screen.height / (2 * Screen.devicePixelRatio) | ||
40 | property int contentWidth: scrollArea.overflowing ? mainItem.width - (units.smallSpacing * 3) : mainItem.width | ||||
41 | property TextMetrics textMetrics: TextMetrics {} | ||||
42 | property alias overflowing: scrollArea.overflowing | ||||
43 | property alias activeTask: focusActiveTaskTimer.targetIndex | ||||
44 | | ||||
45 | function selectTask(task) { | ||||
46 | if (!task) { | ||||
47 | return; | ||||
48 | } | ||||
49 | | ||||
50 | task.forceActiveFocus(); | ||||
51 | scrollArea.ensureItemVisible(task); | ||||
52 | } | ||||
53 | | ||||
54 | mainItem: PlasmaExtras.ScrollArea { | ||||
55 | id: scrollArea | ||||
56 | | ||||
57 | property bool overflowing: (viewport.height < contentItem.height) | ||||
58 | | ||||
59 | horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff | ||||
60 | | ||||
61 | function ensureItemVisible(item) { | ||||
62 | var itemTop = item.y; | ||||
63 | var itemBottom = (item.y + item.height); | ||||
broulik: Remove | |||||
hein: Will do. | |||||
64 | | ||||
65 | if (itemTop < flickableItem.contentY) { | ||||
66 | flickableItem.contentY = itemTop; | ||||
67 | } | ||||
68 | | ||||
69 | if ((itemBottom - flickableItem.contentY) > viewport.height) { | ||||
70 | flickableItem.contentY = Math.abs(viewport.height - itemBottom); | ||||
71 | } | ||||
72 | } | ||||
39 | 73 | | |||
40 | mainItem: Item { | | |||
41 | MouseHandler { | 74 | MouseHandler { | ||
42 | id: mouseHandler | 75 | id: mouseHandler | ||
43 | 76 | | |||
44 | anchors.fill: parent | 77 | width: parent.width | ||
78 | height: (groupRepeater.count * (LayoutManager.verticalMargins() | ||||
79 | + Math.max(theme.mSize(theme.defaultFont).height, units.iconSizes.medium))) | ||||
45 | 80 | | |||
46 | target: taskList | 81 | target: taskList | ||
82 | handleWheelEvents: !scrollArea.overflowing | ||||
83 | | ||||
84 | Timer { | ||||
85 | id: focusActiveTaskTimer | ||||
86 | | ||||
87 | property var targetIndex: null | ||||
88 | | ||||
89 | interval: 0 | ||||
90 | repeat: false | ||||
is this timer working around some bug? should have at least some comments explaining why this needs to be delayed mart: is this timer working around some bug? should have at least some comments explaining why this… | |||||
91 | | ||||
92 | onTriggered: { | ||||
93 | // Now we can home in on the previously active task | ||||
94 | // collected in groupDialog.onVisibleChanged. | ||||
95 | | ||||
96 | if (targetIndex != null) { | ||||
97 | for (var i = 0; i < groupRepeater.count; ++i) { | ||||
98 | var task = groupRepeater.itemAt(i); | ||||
99 | | ||||
100 | if (task.modelIndex() == targetIndex) { | ||||
101 | selectTask(task); | ||||
102 | return; | ||||
103 | } | ||||
104 | } | ||||
105 | } | ||||
106 | } | ||||
47 | } | 107 | } | ||
48 | 108 | | |||
49 | TaskList { | 109 | TaskList { | ||
50 | id: taskList | 110 | id: taskList | ||
51 | 111 | | |||
52 | anchors.fill: parent | 112 | anchors.fill: parent | ||
53 | 113 | | |||
114 | add: Transition { | ||||
115 | // We trigger a null-interval timer in the first add | ||||
116 | // transition after setting the model so onTriggered | ||||
117 | // will run after the Flow has positioned items. | ||||
118 | | ||||
119 | ScriptAction { | ||||
120 | script: { | ||||
broulik: FTR: Qt 5.9 will add a "positioningComplete" signal :) | |||||
Nifty, about time. That also means we can remove some fugly code in main.qml for the layouting and delegate geo publishs. hein: Nifty, about time. That also means we can remove some fugly code in main.qml for the layouting… | |||||
121 | if (groupRepeater.aboutToPopulate) { | ||||
122 | focusActiveTaskTimer.restart(); | ||||
123 | groupRepeater.aboutToPopulate = false; | ||||
124 | } | ||||
125 | } | ||||
126 | } | ||||
127 | } | ||||
broulik: Why this change? | |||||
I was doing heavy refactoring and changing the nesting and trying different things a few times, happened along the way. I'll clean it out of the diff. hein: I was doing heavy refactoring and changing the nesting and trying different things a few times… | |||||
128 | | ||||
54 | Repeater { | 129 | Repeater { | ||
55 | id: groupRepeater | 130 | id: groupRepeater | ||
56 | 131 | | |||
132 | property bool aboutToPopulate: false | ||||
133 | | ||||
57 | function currentIndex() { | 134 | function currentIndex() { | ||
58 | for (var i = 0; i < count; ++i) { | 135 | for (var i = 0; i < count; ++i) { | ||
59 | if (itemAt(i).activeFocus) { | 136 | if (itemAt(i).activeFocus) { | ||
60 | return i; | 137 | return i; | ||
61 | } | 138 | } | ||
62 | } | 139 | } | ||
63 | 140 | | |||
64 | return -1; | 141 | return -1; | ||
65 | } | 142 | } | ||
66 | 143 | | |||
67 | onCountChanged: updateSize() | 144 | onCountChanged: updateSize(); | ||
145 | } | ||||
68 | } | 146 | } | ||
69 | } | 147 | } | ||
70 | 148 | | |||
71 | Keys.onUpPressed: { | 149 | Keys.onUpPressed: { | ||
72 | var currentIndex = groupRepeater.currentIndex(); | 150 | var currentIndex = groupRepeater.currentIndex(); | ||
73 | // In doubt focus the first item | 151 | // In doubt focus the first item | ||
74 | if (currentIndex === -1) { | 152 | if (currentIndex === -1) { | ||
75 | groupRepeater.itemAt(0).forceActiveFocus(); | 153 | selectTask(groupRepeater.itemAt(0)); | ||
76 | return; | 154 | return; | ||
Can you perhaps have the task do that automatically since fwict you always do forceActiveFocus and then ensureItemVisible: onActiveFocusChanged: { if (activeFocus) { ensureItemVisible(this); } } broulik: Can you perhaps have the task do that automatically since fwict you always do forceActiveFocus… | |||||
I see the appeal, but I'd rather not do it implicitly and calling GroupDialog API ... I'm rather unhappy with how much coupling there is between Task and GroupDialog already (writing a delegate that relies on API outside of it is always pretty ugly). I'll think about whether I can find some other nice solution. hein: I see the appeal, but I'd rather not do it implicitly and calling GroupDialog API ... I'm… | |||||
77 | } | 155 | } | ||
78 | 156 | | |||
79 | var previousIndex = currentIndex - 1; | 157 | var previousIndex = currentIndex - 1; | ||
80 | if (previousIndex < 0) { | 158 | if (previousIndex < 0) { | ||
81 | previousIndex = groupRepeater.count - 1; | 159 | previousIndex = groupRepeater.count - 1; | ||
82 | } | 160 | } | ||
83 | 161 | | |||
84 | groupRepeater.itemAt(previousIndex).forceActiveFocus() | 162 | selectTask(groupRepeater.itemAt(previousIndex)); | ||
85 | } | 163 | } | ||
86 | 164 | | |||
87 | Keys.onDownPressed: { | 165 | Keys.onDownPressed: { | ||
88 | var currentIndex = groupRepeater.currentIndex(); | 166 | var currentIndex = groupRepeater.currentIndex(); | ||
89 | // In doubt focus the first item, also wrap around. | 167 | // In doubt focus the first item, also wrap around. | ||
90 | if (currentIndex === -1 || currentIndex + 1 >= groupRepeater.count) { | 168 | if (currentIndex === -1 || currentIndex + 1 >= groupRepeater.count) { | ||
91 | groupRepeater.itemAt(0).forceActiveFocus(); | 169 | selectTask(groupRepeater.itemAt(0)); | ||
92 | return; | 170 | return; | ||
93 | } | 171 | } | ||
94 | 172 | | |||
95 | groupRepeater.itemAt(currentIndex + 1).forceActiveFocus(); | 173 | selectTask(groupRepeater.itemAt(currentIndex + 1)); | ||
96 | } | 174 | } | ||
97 | 175 | | |||
98 | Keys.onEscapePressed: groupDialog.visible = false; | 176 | Keys.onEscapePressed: groupDialog.visible = false; | ||
99 | } | 177 | } | ||
100 | 178 | | |||
101 | data: [ | 179 | data: [ | ||
102 | VisualDataModel { | 180 | VisualDataModel { | ||
103 | id: groupFilter | 181 | id: groupFilter | ||
Show All 10 Lines | 191 | if (!visualParent) { | |||
114 | visible = false; | 192 | visible = false; | ||
115 | } | 193 | } | ||
116 | } | 194 | } | ||
117 | 195 | | |||
118 | onVisibleChanged: { | 196 | onVisibleChanged: { | ||
119 | if (visible && visualParent) { | 197 | if (visible && visualParent) { | ||
120 | groupFilter.model = tasksModel; | 198 | groupFilter.model = tasksModel; | ||
121 | groupFilter.rootIndex = groupFilter.modelIndex(visualParent.itemIndex); | 199 | groupFilter.rootIndex = groupFilter.modelIndex(visualParent.itemIndex); | ||
200 | | ||||
201 | groupRepeater.aboutToPopulate = true; | ||||
122 | groupRepeater.model = groupFilter; | 202 | groupRepeater.model = groupFilter; | ||
123 | 203 | | |||
124 | mainItem.forceActiveFocus(); | 204 | mainItem.forceActiveFocus(); | ||
125 | } else { | 205 | } else { | ||
126 | visualParent = null; | 206 | visualParent = null; | ||
127 | groupRepeater.model = undefined; | 207 | groupRepeater.model = undefined; | ||
128 | groupFilter.model = undefined; | 208 | groupFilter.model = undefined; | ||
129 | groupFilter.rootIndex = undefined; | 209 | groupFilter.rootIndex = undefined; | ||
Show All 12 Lines | 220 | } else { | |||
142 | var maxWidth = 0; | 222 | var maxWidth = 0; | ||
143 | var maxHeight = 0; | 223 | var maxHeight = 0; | ||
144 | 224 | | |||
145 | backend.cancelHighlightWindows(); | 225 | backend.cancelHighlightWindows(); | ||
146 | 226 | | |||
147 | for (var i = 0; i < taskList.children.length - 1; ++i) { | 227 | for (var i = 0; i < taskList.children.length - 1; ++i) { | ||
148 | task = taskList.children[i]; | 228 | task = taskList.children[i]; | ||
149 | 229 | | |||
150 | if (task.textWidth > maxWidth) { | 230 | textMetrics.text = task.labelText; | ||
151 | maxWidth = task.textWidth; | 231 | var textWidth = textMetrics.boundingRect.width; | ||
232 | | ||||
233 | if (textWidth > maxWidth) { | ||||
234 | maxWidth = textWidth; | ||||
152 | } | 235 | } | ||
153 | 236 | | |||
154 | task.textWidthChanged.connect(updateSize); | 237 | task.labelTextChanged.connect(updateSize); | ||
155 | } | 238 | } | ||
156 | 239 | | |||
157 | maxWidth += LayoutManager.horizontalMargins() + units.iconSizes.medium + 2 * units.smallSpacing; | 240 | maxWidth += LayoutManager.horizontalMargins() + units.iconSizes.medium + 2 * units.smallSpacing; | ||
158 | maxHeight = groupRepeater.count * (LayoutManager.verticalMargins() + Math.max(theme.mSize(theme.defaultFont).height, units.iconSizes.medium)); | 241 | maxHeight = groupRepeater.count * (LayoutManager.verticalMargins() + Math.max(theme.mSize(theme.defaultFont).height, units.iconSizes.medium)); | ||
159 | 242 | | |||
160 | mainItem.height = Math.min(preferredHeight, maxHeight); | 243 | mainItem.height = Math.min(preferredHeight, maxHeight); | ||
broulik: ? | |||||
hein: Doing it declaratively creates a binding loop in this case. | |||||
I don't get how assigning a number as a child works. This line makes no sense to me. broulik: I don't get how assigning a number as a child works. This line makes no sense to me. | |||||
Actually, to me it doesn't, either ;). I was asleep at the wheel/rushed earlier, will remove. Thanks for being persistent. hein: Actually, to me it doesn't, either ;). I was asleep at the wheel/rushed earlier, will remove. | |||||
161 | mainItem.width = Math.min(preferredWidth, (tasks.vertical ? Math.max(maxWidth, tasks.width) : Math.min(maxWidth, tasks.width))); | 244 | mainItem.width = Math.min(preferredWidth, (tasks.vertical ? Math.max(maxWidth, tasks.width) : Math.min(maxWidth, tasks.width))); | ||
162 | } | 245 | } | ||
163 | } | 246 | } | ||
164 | } | 247 | } | ||
Why not assign it directly above? property TextMetrics textMetrics: TextMetrics {} broulik: Why not assign it directly above?
```
property TextMetrics textMetrics: TextMetrics {}
``` | |||||
I think this wasn't possible in older Qt Quicks? Nice that it's possible now, will do. hein: I think this wasn't possible in older Qt Quicks? Nice that it's possible now, will do. | |||||
I think this has always been possible :) definitely for years. What doesn't (until Qt 5.8 which fixes this) is having name spaced declarations, ie. property PlasmaCore.Foo bar will choke on the dot. broulik: I think this has always been possible :) definitely for years.
What doesn't (until Qt 5.8… |
Remove