summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWeng Xuetian <[email protected]>2017-03-07 12:37:54 -0800
committerWeng Xuetian <[email protected]>2017-03-07 12:38:45 -0800
commitab89da7d1d0547dc98f423e16d1dd28d3d9830c7 (patch)
tree569ab5078e26aec1c0a21548d92201fcd458623d
parent785efbdebcf2f64b26d92e87774c3477f7499a1c (diff)
kimpanel: add show/hide buttons functionality.
-rw-r--r--applets/kicker/package/contents/ui/ActionMenu.qml24
-rw-r--r--applets/kimpanel/package/contents/config/main.xml3
-rw-r--r--applets/kimpanel/package/contents/ui/ContextMenu.qml143
-rw-r--r--applets/kimpanel/package/contents/ui/StatusIcon.qml7
-rw-r--r--applets/kimpanel/package/contents/ui/main.qml83
5 files changed, 212 insertions, 48 deletions
diff --git a/applets/kicker/package/contents/ui/ActionMenu.qml b/applets/kicker/package/contents/ui/ActionMenu.qml
index e8c340c..8b5f710 100644
--- a/applets/kicker/package/contents/ui/ActionMenu.qml
+++ b/applets/kicker/package/contents/ui/ActionMenu.qml
@@ -28,29 +28,13 @@ Item {
property QtObject menu
property Item visualParent
property variant actionList
- property bool opened: menu ? (menu.status != PlasmaComponents.DialogStatus.Closed) : false
- signal actionClicked(string actionId, variant actionArgument)
- signal closed
+ signal actionClicked(string actionId)
onActionListChanged: refreshMenu();
- onOpenedChanged: {
- if (!opened) {
- closed();
- }
- }
-
- function open(x, y) {
- if (!actionList) {
- return;
- }
-
- if (x && y) {
- menu.open(x, y);
- } else {
- menu.open();
- }
+ function open() {
+ menu.open();
}
function refreshMenu() {
@@ -92,7 +76,7 @@ Item {
icon: actionItem.icon ? actionItem.icon : null
onClicked: {
- actionClicked(actionItem.actionId, actionItem.actionArgument);
+ actionClicked(actionItem.actionId);
}
}
}
diff --git a/applets/kimpanel/package/contents/config/main.xml b/applets/kimpanel/package/contents/config/main.xml
index 9871882..0f2a580 100644
--- a/applets/kimpanel/package/contents/config/main.xml
+++ b/applets/kimpanel/package/contents/config/main.xml
@@ -15,6 +15,9 @@
<entry name="font" type="Font">
<default></default>
</entry>
+ <entry name="hiddenList" type="StringList">
+ <default></default>
+ </entry>
</group>
</kcfg>
diff --git a/applets/kimpanel/package/contents/ui/ContextMenu.qml b/applets/kimpanel/package/contents/ui/ContextMenu.qml
new file mode 100644
index 0000000..86fbb76
--- /dev/null
+++ b/applets/kimpanel/package/contents/ui/ContextMenu.qml
@@ -0,0 +1,143 @@
+/***************************************************************************
+ * Copyright (C) 2013 by Aurélien Gâteau <[email protected]> *
+ * Copyright (C) 2014-2015 by Eike Hein <[email protected]> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, 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 General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU 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.0
+
+import org.kde.plasma.components 2.0 as PlasmaComponents
+
+Item {
+ id: root
+
+ property QtObject menu
+ property Item visualParent
+ property variant actionList
+
+ function open(item, actionItem) {
+ visualParent = item;
+ refreshMenu(actionItem);
+ menu.open();
+ }
+
+ function refreshMenu(actionItem) {
+ if (menu) {
+ menu.destroy();
+ }
+
+ menu = contextMenuComponent.createObject(root, {"actionItem": actionItem});
+
+ if (actionList && actionList.length > 0) {
+ menu.separator.visible = true;
+ actionList.forEach(function(actionItem) {
+ var item = contextMenuItemComponent.createObject(menu.showMenu, {
+ "actionItem": actionItem,
+ });
+ });
+ }
+ }
+
+ Component {
+ id: contextMenuItemComponent
+
+ PlasmaComponents.MenuItem {
+ property variant actionItem
+
+ text: actionItem.label
+ icon: actionItem.icon
+
+ onClicked: {
+ kimpanel.showAction(actionItem.key);
+ }
+ }
+ }
+
+ Component {
+ id: contextMenuComponent
+
+ PlasmaComponents.ContextMenu {
+ visualParent: root.visualParent
+ property variant actionItem
+ property Item separator: separatorItem
+ property QtObject showMenu: subShowMenu
+
+ PlasmaComponents.MenuItem {
+ id: showItem
+ visible: separatorItem.visible
+ text: i18n("Show")
+
+ PlasmaComponents.ContextMenu {
+ id: subShowMenu
+ visualParent: showItem.action
+ }
+ }
+
+ PlasmaComponents.MenuItem {
+ id: separatorItem
+ separator: true
+ visible: false
+ }
+
+ PlasmaComponents.MenuItem {
+ text: i18n("Hide %1", actionItem.label);
+ onClicked: {
+ kimpanel.hideAction(actionItem.key);
+ }
+ enabled: kimpanel.visibleButtons > 1
+ visible: kimpanel.visibleButtons > 1
+ }
+
+ PlasmaComponents.MenuItem {
+ text: i18n("Configure Input Method")
+ icon: "configure"
+ onClicked: {
+ kimpanel.action("Configure");
+ }
+ }
+
+ PlasmaComponents.MenuItem {
+ text: i18n("Reload Config")
+ icon: "view-refresh"
+ onClicked: {
+ kimpanel.action("ReloadConfig");
+ }
+ }
+
+ PlasmaComponents.MenuItem {
+ text: i18n("Exit Input Method")
+ icon: "application-exit"
+ onClicked: {
+ kimpanel.action("Exit");
+ }
+ }
+
+ PlasmaComponents.MenuItem {
+ property QtObject configureAction: null
+
+ enabled: configureAction && configureAction.enabled
+
+ text: configureAction ? configureAction.text : ""
+ icon: configureAction ? configureAction.icon : ""
+
+ onClicked: configureAction.trigger()
+
+ Component.onCompleted: configureAction = plasmoid.action("configure")
+ }
+ }
+ }
+}
diff --git a/applets/kimpanel/package/contents/ui/StatusIcon.qml b/applets/kimpanel/package/contents/ui/StatusIcon.qml
index bf3afc7..0493cd6 100644
--- a/applets/kimpanel/package/contents/ui/StatusIcon.qml
+++ b/applets/kimpanel/package/contents/ui/StatusIcon.qml
@@ -29,7 +29,7 @@ Item {
property string label;
property string tip;
property string hint;
- signal triggered;
+ signal triggered(variant button);
property int iconSize: units.roundToIconSize(Math.min(parent.width, parent.height))
opacity: 'disable' == hint ? 0.3 : 1
@@ -84,7 +84,10 @@ Item {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
- onReleased: statusIcon.triggered();
+ acceptedButtons: Qt.LeftButton | Qt.RightButton
+ onClicked: {
+ statusIcon.triggered(mouse.button);
+ }
PlasmaCore.ToolTipArea {
anchors.fill: parent
diff --git a/applets/kimpanel/package/contents/ui/main.qml b/applets/kimpanel/package/contents/ui/main.qml
index a0738cf..58c12b8 100644
--- a/applets/kimpanel/package/contents/ui/main.qml
+++ b/applets/kimpanel/package/contents/ui/main.qml
@@ -36,25 +36,6 @@ Item {
Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation
- function action_reloadconfig() {
- action("ReloadConfig");
- }
-
- function action_configureim() {
- action("Configure");
- }
-
- function action_exit() {
- action("Exit");
- }
-
- Component.onCompleted: {
- plasmoid.setAction("configureim", i18n("Configure Input Method"), "configure");
- plasmoid.setAction("reloadconfig", i18n("Reload Config"), "view-refresh");
- plasmoid.setAction("exit", i18n("Exit Input Method"), "application-exit");
- }
-
-
InputPanel { }
GridView {
@@ -77,6 +58,7 @@ Item {
width: items.itemWidth
height: items.itemHeight
StatusIcon {
+ id: statusIcon
anchors.centerIn: parent
width: items.iconSize
height: items.iconSize
@@ -84,7 +66,13 @@ Item {
tip: model.tip
icon: model.icon
hint: model.hint
- onTriggered : clickHandler(model.key)
+ onTriggered : {
+ if (button == Qt.LeftButton) {
+ clickHandler(model.key)
+ } else {
+ contextMenu.open(statusIcon, {key: model.key, label: model.label});
+ }
+ }
}
}
}
@@ -102,6 +90,29 @@ Item {
service.startOperationCall(operation);
}
+ function hideAction(key) {
+ // We must use assignment to change the configuration property,
+ // otherwise it won't get notified.
+ var hiddenList = plasmoid.configuration.hiddenList;
+ if (hiddenList.indexOf(key) === -1) {
+ hiddenList.push(key);
+ plasmoid.configuration.hiddenList = hiddenList;
+ }
+ timer.restart();
+ }
+
+ function showAction(key) {
+ // We must use assignment to change the configuration property,
+ // otherwise it won't get notified.
+ var hiddenList = plasmoid.configuration.hiddenList;
+ var index = hiddenList.indexOf(key);
+ if (index !== -1) {
+ hiddenList.splice(index, 1);
+ plasmoid.configuration.hiddenList = hiddenList;
+ }
+ timer.restart();
+ }
+
function showMenu(menu, menuData) {
if (!menuData) {
return;
@@ -128,6 +139,10 @@ Item {
}
}
+ ContextMenu {
+ id: contextMenu
+ }
+
Timer {
id: timer
interval: 50
@@ -136,25 +151,41 @@ Item {
if (!data) {
return;
}
- kimpanel.visibleButtons = data.length;
var count = list.count;
- if (data.length < count) {
- list.remove(data.length, count - data.length);
+ var c = 0, i;
+ var hiddenActions = [];
+ for (i = 0; i < data.length; i ++) {
+ if (plasmoid.configuration.hiddenList.indexOf(data[i].key) !== -1) {
+ hiddenActions.push({'key': data[i].key,
+ 'icon': data[i].icon,
+ 'label': data[i].label});
+ } else {
+ c = c + 1;
+ }
+ }
+ if (c < count) {
+ list.remove(c, count - c);
}
+ kimpanel.visibleButtons = c;
- var i;
+ c = 0;
for (i = 0; i < data.length; i ++) {
+ if (plasmoid.configuration.hiddenList.indexOf(data[i].key) !== -1) {
+ continue;
+ }
var itemData = {'key': data[i].key,
'icon': data[i].icon,
'label': data[i].label,
'tip': data[i].tip,
'hint': data[i].hint };
- if (i < count) {
- list.set(i, itemData);
+ if (c < count) {
+ list.set(c, itemData);
} else {
list.append(itemData);
}
+ c = c + 1;
}
+ contextMenu.actionList = hiddenActions;
}
}