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: https://phabricator.kde.org/D8358
parent 770a0ef5
......@@ -263,6 +263,8 @@ SidebarMode::SidebarMode( QObject *parent, const QVariantList& )
d->aboutIcon->addAuthor( i18n( "Ben Cooksley" ), i18n( "Author" ), "bcooksley@kde.org" );
d->aboutIcon->addAuthor( i18n( "Mathias Soeken" ), i18n( "Developer" ), "msoeken@informatik.uni-bremen.de" );
d->aboutIcon->setProgramIconName( "view-sidetree" );
qmlRegisterType<QAction>();
}
SidebarMode::~SidebarMode()
......@@ -346,16 +348,22 @@ void SidebarMode::initEvent()
moduleView()->setFaceType(KPageView::Plain);
}
void SidebarMode::triggerGlobalAction(const QString &name)
QAction *SidebarMode::action(const QString &name) const
{
if (!d->collection) {
return;
return nullptr;
}
QAction *action = d->collection->action(name);
if (action) {
action->trigger();
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 {
Q_OBJECT
......@@ -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 <kde@privat.broulik.de>
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
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 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: {
root.focusPreviousRequest()
}
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