From 85345d20260fd5a8f46e1a123579bab862aa6ff5 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 12 May 2015 18:59:55 +0200 Subject: [PATCH] support statusnotifieritems --- containments/panel/contents/ui/TaskWidget.qml | 62 +++++++ containments/panel/contents/ui/main.qml | 157 +++++++++++------- 2 files changed, 156 insertions(+), 63 deletions(-) create mode 100644 containments/panel/contents/ui/TaskWidget.qml diff --git a/containments/panel/contents/ui/TaskWidget.qml b/containments/panel/contents/ui/TaskWidget.qml new file mode 100644 index 00000000..712cdcb0 --- /dev/null +++ b/containments/panel/contents/ui/TaskWidget.qml @@ -0,0 +1,62 @@ +/* + * Copyright 2011 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import QtQuick 2.1 +import org.kde.plasma.core 2.0 as PlasmaCore + +Item { + id: taskIcon + width: parent.height + height: width + //hide application status icons + opacity: (Category != "ApplicationStatus" && (main.state == "active" || Status != "Passive")) ? 1 : 0 + onOpacityChanged: visible = opacity + + Behavior on opacity { + NumberAnimation { + duration: 300 + easing.type: Easing.InOutQuad + } + } + + PlasmaCore.IconItem { + source: IconName ? IconName : Icon + width: Math.min(parent.width, parent.height) + height: width + anchors.centerIn: parent + colorGroup: PlasmaCore.ColorScope.colorGroup + } + + MouseArea { + anchors.fill: taskIcon + onClicked: { + //print(iconSvg.hasElement(IconName)) + var service = statusNotifierSource.serviceForSource(DataEngineSource) + var operation = service.operationDescription("Activate") + operation.x = parent.x + + // kmix shows main window instead of volume popup if (parent.x, parent.y) == (0, 0), which is the case here. + // I am passing a position right below the panel (assuming panel is at screen's top). + // Plasmoids' popups are already shown below the panel, so this make kmix's popup more consistent + // to them. + operation.y = parent.y + parent.height + 6 + service.startOperationCall(operation) + } + } +} diff --git a/containments/panel/contents/ui/main.qml b/containments/panel/contents/ui/main.qml index 0674d693..903a208c 100644 --- a/containments/panel/contents/ui/main.qml +++ b/containments/panel/contents/ui/main.qml @@ -99,6 +99,18 @@ PlasmaCore.ColorScope { LayoutManager.restore(); } + PlasmaCore.DataSource { + id: statusNotifierSource + engine: "statusnotifieritem" + interval: 0 + onSourceAdded: { + connectSource(source) + } + Component.onCompleted: { + connectedSources = sources + } + } + RowLayout { id: appletsLayout Layout.minimumHeight: Math.max(root.height, Math.round(Layout.preferredHeight / root.height) * root.height) @@ -226,6 +238,7 @@ PlasmaCore.ColorScope { color: PlasmaCore.ColorScope.textColor font.pixelSize: parent.height / 2 } + PlasmaComponents.Label { id: clock anchors.fill: parent @@ -236,78 +249,96 @@ PlasmaCore.ColorScope { font.pixelSize: height / 2 } - - PlasmaWorkspace.BatteryIcon { - id: batteryIcon - anchors { - right: parent.right - verticalCenter: parent.verticalCenter - } - width: height - height: parent.height - hasBattery: pmSource.data["Battery"]["Has Battery"] - // batteryType: "Phone" - percent: pmSource.data["Battery0"] ? pmSource.data["Battery0"]["Percent"] : 0 - - PlasmaCore.DataSource { - id: pmSource - engine: "powermanagement" - connectedSources: sources - onSourceAdded: { - disconnectSource(source); - connectSource(source); - } - onSourceRemoved: { - disconnectSource(source); + Row { + anchors.right: batteryIcon.left + height: parent.height + Repeater { + id: statusNotifierRepeater + model: PlasmaCore.SortFilterModel { + id: filteredStatusNotifiers + filterRole: "Title" + filterRegExp: tasksRow.skipItems + sourceModel: PlasmaCore.DataModel { + dataSource: statusNotifierSource } } - } - Rectangle { - height: units.smallSpacing/2 - color: PlasmaCore.ColorScope.highlightColor - anchors { - left: parent.left - right: parent.right - bottom: parent.bottom + + delegate: TaskWidget { } } } - MouseArea { - property int oldMouseY: 0 + PlasmaWorkspace.BatteryIcon { + id: batteryIcon + anchors { + right: parent.right + verticalCenter: parent.verticalCenter + } + width: height + height: parent.height + hasBattery: pmSource.data["Battery"]["Has Battery"] + // batteryType: "Phone" + percent: pmSource.data["Battery0"] ? pmSource.data["Battery0"]["Percent"] : 0 + + PlasmaCore.DataSource { + id: pmSource + engine: "powermanagement" + connectedSources: sources + onSourceAdded: { + disconnectSource(source); + connectSource(source); + } + onSourceRemoved: { + disconnectSource(source); + } + } + } + Rectangle { + height: units.smallSpacing/2 + color: PlasmaCore.ColorScope.highlightColor + anchors { + left: parent.left + right: parent.right + bottom: parent.bottom + } + } + } + MouseArea { + property int oldMouseY: 0 + + anchors.fill: parent + onPressed: { + oldMouseY = mouse.y; + slidingPanel.visibility = Qt.WindowFullScreen; + } + onPositionChanged: { + //var factor = (mouse.y - oldMouseY > 0) ? (1 - Math.max(0, (slidingArea.y + slidingPanel.overShoot) / slidingPanel.overShoot)) : 1 + var factor = 1; + slidingPanel.offset = slidingPanel.offset + (mouse.y - oldMouseY) * factor; + oldMouseY = mouse.y; + } + onReleased: slidingPanel.updateState(); + } + + SlidingPanel { + id: slidingPanel + width: plasmoid.availableScreenRect.width + height: plasmoid.availableScreenRect.height + contents: Item { + id: panelContents anchors.fill: parent - onPressed: { - oldMouseY = mouse.y; - slidingPanel.visibility = Qt.WindowFullScreen; - } - onPositionChanged: { - //var factor = (mouse.y - oldMouseY > 0) ? (1 - Math.max(0, (slidingArea.y + slidingPanel.overShoot) / slidingPanel.overShoot)) : 1 - var factor = 1; - slidingPanel.offset = slidingPanel.offset + (mouse.y - oldMouseY) * factor; - oldMouseY = mouse.y; - } - onReleased: slidingPanel.updateState(); - } + clip: true - SlidingPanel { - id: slidingPanel - width: plasmoid.availableScreenRect.width - height: plasmoid.availableScreenRect.height - contents: Item { - id: panelContents + Item { + id: lastSpacer + Layout.fillWidth: true + Layout.fillHeight: true + } + Column { + id: layout anchors.fill: parent - clip: true - - Item { - id: lastSpacer - Layout.fillWidth: true - Layout.fillHeight: true - } - Column { - id: layout - anchors.fill: parent - spacing: units.smallSpacing - } + spacing: units.smallSpacing } } + } }