Falkon Develop
Cross-platform Qt-based web browser
qmlaction.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "qmlaction.h"
19#include "qztools.h"
21#include "qml/qmlengine.h"
22#include "qml/qmlstaticdata.h"
23#include <QQmlEngine>
24
25QmlAction::QmlAction(QAction *action, QmlEngine *engine, QObject *parent)
26 : QObject(parent)
27 , m_action(action)
28{
29 auto *qmlEngine = qobject_cast<QmlEngine*>(engine);
30 m_pluginPath = qmlEngine->extensionPath();
31 connect(m_action, &QAction::triggered, this, &QmlAction::triggered);
32}
33
34void QmlAction::setProperties(const QVariantMap &map)
35{
36 if (!m_action) {
37 return;
38 }
39
40 for (auto it = map.cbegin(); it != map.cend(); it++) {
41 const QString key = it.key();
42 if (key == QSL("icon")) {
43 QString iconPath = map.value(key).toString();
44 QIcon icon = QmlStaticData::instance().getIcon(iconPath, m_pluginPath);
45 m_action->setIcon(icon);
46 } else if (key == QSL("shortcut")) {
47 m_action->setShortcut(QKeySequence(map.value(key).toString()));
48 } else {
49 m_action->setProperty(key.toUtf8().constData(), map.value(key));
50 }
51 }
52}
53
54void QmlAction::update(const QVariantMap &map)
55{
56 setProperties(map);
57}
void setProperties(const QVariantMap &map)
Definition: qmlaction.cpp:34
Q_INVOKABLE void update(const QVariantMap &map)
Updates the properties of the action.
Definition: qmlaction.cpp:54
QmlAction(QAction *action, QmlEngine *engine, QObject *parent=nullptr)
Definition: qmlaction.cpp:25
void triggered()
This signal is emitted when the action is triggered.
static QmlStaticData & instance()
QIcon getIcon(const QString &iconPath, const QString &pluginPath)
#define QSL(x)
Definition: qzcommon.h:40