Commit f65b9c87 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

Use QActions directly in menu

Instead of duplicating the name and icon work, just bind it to the QAction itself.
Also respect visibility of actions for KIOSK restriction.

Differential Revision:
parent 770a0ef5
......@@ -263,6 +263,8 @@ SidebarMode::SidebarMode( QObject *parent, const QVariantList& )
d->aboutIcon->addAuthor( i18n( "Ben Cooksley" ), i18n( "Author" ), "" );
d->aboutIcon->addAuthor( i18n( "Mathias Soeken" ), i18n( "Developer" ), "" );
d->aboutIcon->setProgramIconName( "view-sidetree" );
......@@ -346,16 +348,22 @@ void SidebarMode::initEvent()
void SidebarMode::triggerGlobalAction(const QString &name)
QAction *SidebarMode::action(const QString &name) const
if (!d->collection) {
return nullptr;
QAction *action = d->collection->action(name);
if (action) {
return d->collection->action(name);
QString SidebarMode::actionIconName(const QString &name) const
if (QAction *a = action(name)) {
return a->icon().name();
return QString();
void SidebarMode::requestToolTip(int index, const QRectF &rect)
......@@ -28,6 +28,7 @@ class KAboutData;
class QModelIndex;
class QAbstractItemView;
class QAbstractItemModel;
class QAction;
class FocusHackWidget : public QWidget {
......@@ -71,7 +72,9 @@ public:
int width() const;
Q_INVOKABLE void triggerGlobalAction(const QString &name);
Q_INVOKABLE QAction *action(const QString &name) const;
// QML doesn't understand QIcon, otherwise we could get it from the QAction itself
Q_INVOKABLE QString actionIconName(const QString &name) const;
Q_INVOKABLE void requestToolTip(int index, const QRectF &rect);
Q_INVOKABLE void hideToolTip();
Q_INVOKABLE void loadMostUsed(int index);
Copyright (c) 2017 Kai Uwe Broulik <>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
import QtQuick 2.3
import QtQml 2.2
import QtQuick.Controls 1.0 as QtControls
QtControls.Menu {
id: menu
property alias actions: instantiator.model
Instantiator {
id: instantiator
delegate: QtControls.MenuItem {
readonly property QtObject action: systemsettings.action(modelData)
text: action.text
iconName: systemsettings.actionIconName(modelData)
visible: action.visible
enabled: action.enabled
onTriggered: action.trigger()
onObjectAdded: menu.insertItem(index, object)
onObjectRemoved: menu.removeItem(object)
......@@ -46,28 +46,8 @@ Kirigami.ScrollablePage {
Keys.onBacktabPressed: {
menu: QtControls.Menu {
id: globalMenu
QtControls.MenuItem {
text: i18n("Configure")
iconName: "settings-configure"
onTriggered: systemsettings.triggerGlobalAction("configure");
QtControls.MenuItem {
text: i18n("System Settings Handbook")
iconName: "help-contents"
onTriggered: systemsettings.triggerGlobalAction("help_contents");
QtControls.MenuItem {
text: i18n("About System Settings")
iconName: "help-about"
onTriggered: systemsettings.triggerGlobalAction("help_about_app");
QtControls.MenuItem {
text: i18n("About KDE")
iconName: "kde"
onTriggered: systemsettings.triggerGlobalAction("help_about_kde");
menu: ActionMenu {
actions: ["configure", "help_contents", "help_about_app", "help_about_kde"]
QtControls.TextField {
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment