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 | | ||||
44 | function open() { | ||||
45 | // Collect active task before opening the dialog. As the dialog | ||||
46 | // gains focus window focus changes, so we can't do it later. | ||||
47 | focusActiveTaskTimer.targetIndex = tasksModel.activeTask; | ||||
48 | | ||||
49 | visible = true; | ||||
50 | } | ||||
51 | | ||||
52 | function selectTask(task) { | ||||
53 | if (!task) { | ||||
54 | return; | ||||
55 | } | ||||
56 | | ||||
57 | task.forceActiveFocus(); | ||||
58 | scrollArea.ensureItemVisible(task); | ||||
59 | } | ||||
60 | | ||||
61 | mainItem: PlasmaExtras.ScrollArea { | ||||
62 | id: scrollArea | ||||
63 | | ||||
broulik: Remove | |||||
hein: Will do. | |||||
64 | property bool overflowing: (viewport.height < contentItem.height) | ||||
65 | | ||||
66 | horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff | ||||
67 | | ||||
68 | function ensureItemVisible(item) { | ||||
69 | var itemTop = item.y; | ||||
70 | var itemBottom = (item.y + item.height); | ||||
71 | | ||||
72 | if (itemTop < flickableItem.contentY) { | ||||
73 | flickableItem.contentY = itemTop; | ||||
74 | } | ||||
75 | | ||||
76 | if ((itemBottom - flickableItem.contentY) > viewport.height) { | ||||
77 | flickableItem.contentY = Math.abs(viewport.height - itemBottom); | ||||
78 | } | ||||
79 | } | ||||
39 | 80 | | |||
40 | mainItem: Item { | | |||
41 | MouseHandler { | 81 | MouseHandler { | ||
42 | id: mouseHandler | 82 | id: mouseHandler | ||
43 | 83 | | |||
44 | anchors.fill: parent | 84 | width: parent.width | ||
85 | height: (groupRepeater.count * (LayoutManager.verticalMargins() | ||||
86 | + Math.max(theme.mSize(theme.defaultFont).height, units.iconSizes.medium))) | ||||
45 | 87 | | |||
46 | target: taskList | 88 | target: taskList | ||
89 | handleWheelEvents: !scrollArea.overflowing | ||||
90 | | ||||
91 | Timer { | ||||
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… | |||||
92 | id: focusActiveTaskTimer | ||||
93 | | ||||
94 | property var targetIndex: null | ||||
95 | | ||||
96 | interval: 0 | ||||
97 | repeat: false | ||||
98 | | ||||
99 | onTriggered: { | ||||
100 | // Now we can home in on the previously active task | ||||
101 | // collected in groupDialog.onVisibleChanged. | ||||
102 | | ||||
103 | if (targetIndex != null) { | ||||
104 | for (var i = 0; i < groupRepeater.count; ++i) { | ||||
105 | var task = groupRepeater.itemAt(i); | ||||
106 | | ||||
107 | if (task.modelIndex() == targetIndex) { | ||||
108 | selectTask(task); | ||||
109 | return; | ||||
110 | } | ||||
111 | } | ||||
112 | } | ||||
113 | } | ||||
47 | } | 114 | } | ||
48 | 115 | | |||
49 | TaskList { | 116 | TaskList { | ||
50 | id: taskList | 117 | id: taskList | ||
51 | 118 | | |||
52 | anchors.fill: parent | 119 | anchors.fill: parent | ||
53 | 120 | | |||
121 | add: Transition { | ||||
122 | // We trigger a null-interval timer in the first add | ||||
123 | // transition after setting the model so onTriggered | ||||
124 | // will run after the Flow has positioned items. | ||||
125 | | ||||
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… | |||||
126 | ScriptAction { | ||||
127 | script: { | ||||
128 | if (groupRepeater.aboutToPopulate) { | ||||
129 | focusActiveTaskTimer.restart(); | ||||
130 | groupRepeater.aboutToPopulate = false; | ||||
131 | } | ||||
132 | } | ||||
133 | } | ||||
134 | } | ||||
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… | |||||
135 | | ||||
54 | Repeater { | 136 | Repeater { | ||
55 | id: groupRepeater | 137 | id: groupRepeater | ||
56 | 138 | | |||
139 | property bool aboutToPopulate: false | ||||
140 | | ||||
57 | function currentIndex() { | 141 | function currentIndex() { | ||
58 | for (var i = 0; i < count; ++i) { | 142 | for (var i = 0; i < count; ++i) { | ||
59 | if (itemAt(i).activeFocus) { | 143 | if (itemAt(i).activeFocus) { | ||
60 | return i; | 144 | return i; | ||
61 | } | 145 | } | ||
62 | } | 146 | } | ||
63 | 147 | | |||
64 | return -1; | 148 | return -1; | ||
65 | } | 149 | } | ||
66 | 150 | | |||
67 | onCountChanged: updateSize() | 151 | onCountChanged: updateSize(); | ||
152 | } | ||||
68 | } | 153 | } | ||
69 | } | 154 | } | ||
70 | 155 | | |||
71 | Keys.onUpPressed: { | 156 | Keys.onUpPressed: { | ||
72 | var currentIndex = groupRepeater.currentIndex(); | 157 | var currentIndex = groupRepeater.currentIndex(); | ||
73 | // In doubt focus the first item | 158 | // In doubt focus the first item | ||
74 | if (currentIndex === -1) { | 159 | if (currentIndex === -1) { | ||
75 | groupRepeater.itemAt(0).forceActiveFocus(); | 160 | selectTask(groupRepeater.itemAt(0)); | ||
76 | return; | 161 | 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 | } | 162 | } | ||
78 | 163 | | |||
79 | var previousIndex = currentIndex - 1; | 164 | var previousIndex = currentIndex - 1; | ||
80 | if (previousIndex < 0) { | 165 | if (previousIndex < 0) { | ||
81 | previousIndex = groupRepeater.count - 1; | 166 | previousIndex = groupRepeater.count - 1; | ||
82 | } | 167 | } | ||
83 | 168 | | |||
84 | groupRepeater.itemAt(previousIndex).forceActiveFocus() | 169 | selectTask(groupRepeater.itemAt(previousIndex)); | ||
85 | } | 170 | } | ||
86 | 171 | | |||
87 | Keys.onDownPressed: { | 172 | Keys.onDownPressed: { | ||
88 | var currentIndex = groupRepeater.currentIndex(); | 173 | var currentIndex = groupRepeater.currentIndex(); | ||
89 | // In doubt focus the first item, also wrap around. | 174 | // In doubt focus the first item, also wrap around. | ||
90 | if (currentIndex === -1 || currentIndex + 1 >= groupRepeater.count) { | 175 | if (currentIndex === -1 || currentIndex + 1 >= groupRepeater.count) { | ||
91 | groupRepeater.itemAt(0).forceActiveFocus(); | 176 | selectTask(groupRepeater.itemAt(0)); | ||
92 | return; | 177 | return; | ||
93 | } | 178 | } | ||
94 | 179 | | |||
95 | groupRepeater.itemAt(currentIndex + 1).forceActiveFocus(); | 180 | selectTask(groupRepeater.itemAt(currentIndex + 1)); | ||
96 | } | 181 | } | ||
97 | 182 | | |||
98 | Keys.onEscapePressed: groupDialog.visible = false; | 183 | Keys.onEscapePressed: groupDialog.visible = false; | ||
99 | } | 184 | } | ||
100 | 185 | | |||
101 | data: [ | 186 | data: [ | ||
102 | VisualDataModel { | 187 | VisualDataModel { | ||
103 | id: groupFilter | 188 | id: groupFilter | ||
Show All 10 Lines | 198 | if (!visualParent) { | |||
114 | visible = false; | 199 | visible = false; | ||
115 | } | 200 | } | ||
116 | } | 201 | } | ||
117 | 202 | | |||
118 | onVisibleChanged: { | 203 | onVisibleChanged: { | ||
119 | if (visible && visualParent) { | 204 | if (visible && visualParent) { | ||
120 | groupFilter.model = tasksModel; | 205 | groupFilter.model = tasksModel; | ||
121 | groupFilter.rootIndex = groupFilter.modelIndex(visualParent.itemIndex); | 206 | groupFilter.rootIndex = groupFilter.modelIndex(visualParent.itemIndex); | ||
207 | | ||||
208 | groupRepeater.aboutToPopulate = true; | ||||
122 | groupRepeater.model = groupFilter; | 209 | groupRepeater.model = groupFilter; | ||
123 | 210 | | |||
124 | mainItem.forceActiveFocus(); | 211 | mainItem.forceActiveFocus(); | ||
125 | } else { | 212 | } else { | ||
126 | visualParent = null; | 213 | visualParent = null; | ||
127 | groupRepeater.model = undefined; | 214 | groupRepeater.model = undefined; | ||
128 | groupFilter.model = undefined; | 215 | groupFilter.model = undefined; | ||
129 | groupFilter.rootIndex = undefined; | 216 | groupFilter.rootIndex = undefined; | ||
Show All 12 Lines | 227 | } else { | |||
142 | var maxWidth = 0; | 229 | var maxWidth = 0; | ||
143 | var maxHeight = 0; | 230 | var maxHeight = 0; | ||
144 | 231 | | |||
145 | backend.cancelHighlightWindows(); | 232 | backend.cancelHighlightWindows(); | ||
146 | 233 | | |||
147 | for (var i = 0; i < taskList.children.length - 1; ++i) { | 234 | for (var i = 0; i < taskList.children.length - 1; ++i) { | ||
148 | task = taskList.children[i]; | 235 | task = taskList.children[i]; | ||
149 | 236 | | |||
150 | if (task.textWidth > maxWidth) { | 237 | textMetrics.text = task.labelText; | ||
151 | maxWidth = task.textWidth; | 238 | var textWidth = textMetrics.boundingRect.width; | ||
239 | | ||||
240 | if (textWidth > maxWidth) { | ||||
241 | maxWidth = textWidth; | ||||
152 | } | 242 | } | ||
153 | 243 | | |||
154 | task.textWidthChanged.connect(updateSize); | 244 | task.labelTextChanged.connect(updateSize); | ||
155 | } | 245 | } | ||
156 | 246 | | |||
157 | maxWidth += LayoutManager.horizontalMargins() + units.iconSizes.medium + 2 * units.smallSpacing; | 247 | 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)); | 248 | maxHeight = groupRepeater.count * (LayoutManager.verticalMargins() + Math.max(theme.mSize(theme.defaultFont).height, units.iconSizes.medium)); | ||
159 | 249 | | |||
160 | mainItem.height = Math.min(preferredHeight, maxHeight); | 250 | 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))); | 251 | mainItem.width = Math.min(preferredWidth, (tasks.vertical ? Math.max(maxWidth, tasks.width) : Math.min(maxWidth, tasks.width))); | ||
162 | } | 252 | } | ||
163 | } | 253 | } | ||
164 | } | 254 | } | ||
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