summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Hein <hein@kde.org>2017-04-03 14:03:11 (GMT)
committerEike Hein <hein@kde.org>2017-04-03 14:06:20 (GMT)
commit76034a4cd3b2ecd2d97802037ea6db0756651786 (patch)
treeff8a71be6c9f2658f9b56579ff129aa1376cd74b
parent782d593ccfd269e643d92af2c9db7e71a741f76e (diff)
Backport 5.9/Master's GroupDialog code to 5.8.
Summary: This brings us to a common baseline on the three active branches and addresses regressions on the 5.8 branch. 5.9's code added a scrollbar and improved keyboard nav. BUG:378042 Reviewers: #plasma, mart Subscribers: plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D5287
-rw-r--r--applets/taskmanager/package/contents/ui/GroupDialog.qml130
-rw-r--r--applets/taskmanager/package/contents/ui/MouseHandler.qml15
-rw-r--r--applets/taskmanager/package/contents/ui/Task.qml10
-rw-r--r--applets/taskmanager/package/contents/ui/main.qml12
4 files changed, 139 insertions, 28 deletions
diff --git a/applets/taskmanager/package/contents/ui/GroupDialog.qml b/applets/taskmanager/package/contents/ui/GroupDialog.qml
index c87852b..4b1fee5 100644
--- a/applets/taskmanager/package/contents/ui/GroupDialog.qml
+++ b/applets/taskmanager/package/contents/ui/GroupDialog.qml
@@ -17,10 +17,11 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
-import QtQuick 2.0
+import QtQuick 2.4
import QtQuick.Window 2.2
import org.kde.plasma.core 2.0 as PlasmaCore
+import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.draganddrop 2.0
import "../code/layout.js" as LayoutManager
@@ -36,43 +37,121 @@ PlasmaCore.Dialog {
property int preferredWidth: Screen.width / (3 * Screen.devicePixelRatio)
property int preferredHeight: Screen.height / (2 * Screen.devicePixelRatio)
+ property int contentWidth: scrollArea.overflowing ? mainItem.width - (units.smallSpacing * 3) : mainItem.width
+ property TextMetrics textMetrics: TextMetrics {}
+ property alias overflowing: scrollArea.overflowing
+ property alias activeTask: focusActiveTaskTimer.targetIndex
+
+ function selectTask(task) {
+ if (!task) {
+ return;
+ }
+
+ task.forceActiveFocus();
+ scrollArea.ensureItemVisible(task);
+ }
+
+ mainItem: PlasmaExtras.ScrollArea {
+ id: scrollArea
+
+ property bool overflowing: (viewport.height < contentItem.height)
+
+ horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff
+
+ function ensureItemVisible(item) {
+ var itemTop = item.y;
+ var itemBottom = (item.y + item.height);
+
+ if (itemTop < flickableItem.contentY) {
+ flickableItem.contentY = itemTop;
+ }
+
+ if ((itemBottom - flickableItem.contentY) > viewport.height) {
+ flickableItem.contentY = Math.abs(viewport.height - itemBottom);
+ }
+ }
- mainItem: Item {
MouseHandler {
id: mouseHandler
- anchors.fill: parent
+ width: parent.width
+ height: (groupRepeater.count * (LayoutManager.verticalMargins()
+ + Math.max(theme.mSize(theme.defaultFont).height, units.iconSizes.medium)))
target: taskList
- }
+ handleWheelEvents: !scrollArea.overflowing
+
+ Timer {
+ id: focusActiveTaskTimer
+
+ property var targetIndex: null
- TaskList {
- id: taskList
+ interval: 0
+ repeat: false
- anchors.fill: parent
+ onTriggered: {
+ // Now we can home in on the previously active task
+ // collected in groupDialog.onVisibleChanged.
- Repeater {
- id: groupRepeater
+ if (targetIndex != null) {
+ for (var i = 0; i < groupRepeater.count; ++i) {
+ var task = groupRepeater.itemAt(i);
- function currentIndex() {
- for (var i = 0; i < count; ++i) {
- if (itemAt(i).activeFocus) {
- return i;
+ if (task.modelIndex() == targetIndex) {
+ selectTask(task);
+ return;
+ }
}
}
+ }
+ }
+
+ TaskList {
+ id: taskList
+
+ anchors.fill: parent
- return -1;
+ add: Transition {
+ // We trigger a null-interval timer in the first add
+ // transition after setting the model so onTriggered
+ // will run after the Flow has positioned items.
+
+ ScriptAction {
+ script: {
+ if (groupRepeater.aboutToPopulate) {
+ focusActiveTaskTimer.restart();
+ groupRepeater.aboutToPopulate = false;
+ }
+ }
+ }
}
- onCountChanged: updateSize()
+ Repeater {
+ id: groupRepeater
+
+ property bool aboutToPopulate: false
+
+ function currentIndex() {
+ for (var i = 0; i < count; ++i) {
+ if (itemAt(i).activeFocus) {
+ return i;
+ }
+ }
+
+ return -1;
+ }
+
+ onCountChanged: updateSize();
+ }
}
}
Keys.onUpPressed: {
var currentIndex = groupRepeater.currentIndex();
- // In doubt focus the first item
+ // In doubt focus the last item, so we start at the bottom when user
+ // initially presses up.
if (currentIndex === -1) {
- groupRepeater.itemAt(0).forceActiveFocus();
+ selectTask(groupRepeater.itemAt(groupRepeater.count - 1));
return;
}
@@ -81,18 +160,18 @@ PlasmaCore.Dialog {
previousIndex = groupRepeater.count - 1;
}
- groupRepeater.itemAt(previousIndex).forceActiveFocus()
+ selectTask(groupRepeater.itemAt(previousIndex));
}
Keys.onDownPressed: {
var currentIndex = groupRepeater.currentIndex();
// In doubt focus the first item, also wrap around.
if (currentIndex === -1 || currentIndex + 1 >= groupRepeater.count) {
- groupRepeater.itemAt(0).forceActiveFocus();
+ selectTask(groupRepeater.itemAt(0));
return;
}
- groupRepeater.itemAt(currentIndex + 1).forceActiveFocus();
+ selectTask(groupRepeater.itemAt(currentIndex + 1));
}
Keys.onEscapePressed: groupDialog.visible = false;
@@ -119,6 +198,8 @@ PlasmaCore.Dialog {
if (visible && visualParent) {
groupFilter.model = tasksModel;
groupFilter.rootIndex = groupFilter.modelIndex(visualParent.itemIndex);
+
+ groupRepeater.aboutToPopulate = true;
groupRepeater.model = groupFilter;
mainItem.forceActiveFocus();
@@ -147,11 +228,14 @@ PlasmaCore.Dialog {
for (var i = 0; i < taskList.children.length - 1; ++i) {
task = taskList.children[i];
- if (task.textWidth > maxWidth) {
- maxWidth = task.textWidth;
+ textMetrics.text = task.labelText;
+ var textWidth = textMetrics.boundingRect.width;
+
+ if (textWidth > maxWidth) {
+ maxWidth = textWidth;
}
- task.textWidthChanged.connect(updateSize);
+ task.labelTextChanged.connect(updateSize);
}
maxWidth += LayoutManager.horizontalMargins() + units.iconSizes.medium + 2 * units.smallSpacing;
diff --git a/applets/taskmanager/package/contents/ui/MouseHandler.qml b/applets/taskmanager/package/contents/ui/MouseHandler.qml
index 94fa8b0..b5d0ea0 100644
--- a/applets/taskmanager/package/contents/ui/MouseHandler.qml
+++ b/applets/taskmanager/package/contents/ui/MouseHandler.qml
@@ -34,6 +34,7 @@ Item {
property bool moved: false
property alias hoveredItem: dropHandler.hoveredItem
+ property alias handleWheelEvents: wheelHandler.active
Timer {
id: ignoreItemTimer
@@ -145,9 +146,19 @@ Item {
id: wheelHandler
anchors.fill: parent
+
+ enabled: active && plasmoid.configuration.wheelEnabled
+
+ property bool active: true
property int wheelDelta: 0;
- enabled: plasmoid.configuration.wheelEnabled
- onWheel: wheelDelta = TaskTools.wheelActivateNextPrevTask(null, wheelDelta, wheel.angleDelta.y);
+ onWheel: {
+ if (!active) {
+ wheel.accepted = false;
+ return;
+ }
+
+ wheelDelta = TaskTools.wheelActivateNextPrevTask(null, wheelDelta, wheel.angleDelta.y);
+ }
}
}
diff --git a/applets/taskmanager/package/contents/ui/Task.qml b/applets/taskmanager/package/contents/ui/Task.qml
index e17319d..41fa91c 100644
--- a/applets/taskmanager/package/contents/ui/Task.qml
+++ b/applets/taskmanager/package/contents/ui/Task.qml
@@ -31,7 +31,7 @@ import "../code/tools.js" as TaskTools
MouseArea {
id: task
- width: groupDialog.mainItem.width
+ width: groupDialog.contentWidth
height: Math.max(theme.mSize(theme.defaultFont).height, units.iconSizes.medium) + LayoutManager.verticalMargins()
visible: false
@@ -46,7 +46,7 @@ MouseArea {
property bool isWindow: model.IsWindow === true
property int childCount: model.ChildCount != undefined ? model.ChildCount : 0
property int previousChildCount: 0
- property alias textWidth: label.implicitWidth
+ property alias labelText: label.text
property bool pressed: false
property int pressX: -1
property int pressY: -1
@@ -68,6 +68,10 @@ MouseArea {
}
onChildCountChanged: {
+ if (containsMouse) {
+ groupDialog.activeTask = null;
+ }
+
if (childCount > previousChildCount) {
tasksModel.requestPublishDelegateGeometry(modelIndex(), backend.globalRect(task), task);
}
@@ -147,7 +151,7 @@ MouseArea {
}
onWheel: {
- if (plasmoid.configuration.wheelEnabled) {
+ if (plasmoid.configuration.wheelEnabled && (!inPopup || !groupDialog.overflowing)) {
wheelDelta = TaskTools.wheelActivateNextPrevTask(task, wheelDelta, wheel.angleDelta.y);
} else {
wheel.accepted = false;
diff --git a/applets/taskmanager/package/contents/ui/main.qml b/applets/taskmanager/package/contents/ui/main.qml
index 74dca9e..03e712d 100644
--- a/applets/taskmanager/package/contents/ui/main.qml
+++ b/applets/taskmanager/package/contents/ui/main.qml
@@ -164,6 +164,18 @@ Item {
}
}
+ Connections {
+ enabled: plasmoid.configuration.groupPopups
+
+ target: tasksModel
+
+ onActiveTaskChanged: {
+ if (tasksModel.activeTask.parent.valid) {
+ groupDialog.activeTask = tasksModel.activeTask;
+ }
+ }
+ }
+
TaskManager.VirtualDesktopInfo {
id: virtualDesktopInfo
}