Libplasma

action.cpp
1/*
2 SPDX-FileCopyrightText: 2023 Marco Martin <mart@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "action.h"
8#include <QMenu>
9
10IconGroup::IconGroup(ActionExtension *parent)
11 : QObject(parent)
12 , m_action(parent->action())
13{
14}
15
16IconGroup::~IconGroup()
17{
18}
19
20void IconGroup::setName(const QString &name)
21{
22 if (name == m_name) {
23 return;
24 }
25
26 m_name = name;
27 m_action->setIcon(QIcon::fromTheme(name));
28 Q_EMIT nameChanged();
29}
30
31QString IconGroup::name() const
32{
33 return m_name;
34}
35
36void IconGroup::setIcon(const QIcon &icon)
37{
38 m_action->setIcon(icon);
39 Q_EMIT iconChanged();
40}
41
42QIcon IconGroup::icon() const
43{
44 return m_action->icon();
45}
46
47ActionExtension::ActionExtension(QObject *parent)
48 : QObject(parent)
49 , m_action(qobject_cast<QAction *>(parent))
50 , m_iconGroup(new IconGroup(this))
51{
52}
53
54ActionExtension::~ActionExtension()
55{
56}
57
58bool ActionExtension::isSeparator() const
59{
60 return m_action->isSeparator();
61}
62
63void ActionExtension::setSeparator(bool separator)
64{
65 if (separator == m_action->isSeparator()) {
66 return;
67 }
68
69 m_action->setSeparator(separator);
70
71 Q_EMIT isSeparatorChanged();
72}
73
74void ActionExtension::setActionGroup(QActionGroup *group)
75{
76 if (group == m_action->actionGroup()) {
77 return;
78 }
79
80 m_action->setActionGroup(group);
81 Q_EMIT actionGroupChanged();
82}
83
84QActionGroup *ActionExtension::actionGroup() const
85{
86 return m_action->actionGroup();
87}
88
89static QKeySequence variantToKeySequence(const QVariant &var)
90{
91 if (var.metaType().id() == QMetaType::Int)
92 return QKeySequence(static_cast<QKeySequence::StandardKey>(var.toInt()));
93 return QKeySequence::fromString(var.toString());
94}
95
96QVariant ActionExtension::shortcut() const
97{
98 return m_action->shortcut();
99}
100
101void ActionExtension::setShortcut(const QVariant &var)
102{
103 const QKeySequence seq = variantToKeySequence(var);
104 if (seq == m_action->shortcut()) {
105 return;
106 }
107 m_action->setShortcut(seq);
108 Q_EMIT shortcutChanged();
109}
110
111void ActionExtension::setMenu(QMenu *menu)
112{
113 if (menu == m_action->menu()) {
114 return;
115 }
116
117 m_action->setMenu(menu);
118 Q_EMIT menuChanged();
119}
120
121QMenu *ActionExtension::menu()
122{
123 return m_action->menu();
124}
125
126QAction *ActionExtension::action() const
127{
128 return m_action;
129}
130
131#include "moc_action.cpp"
QString name(StandardAction id)
QActionGroup * actionGroup() const const
void setIcon(const QIcon &icon)
bool isSeparator() const const
QMenu * menu() const const
void setActionGroup(QActionGroup *group)
void setMenu(QMenu *menu)
void setSeparator(bool b)
void setShortcut(const QKeySequence &shortcut)
QIcon fromTheme(const QString &name)
QKeySequence fromString(const QString &str, SequenceFormat format)
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:35 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.