Libplasma

containmentactions.cpp
1/*
2 SPDX-FileCopyrightText: 2009 Chani Armitage <chani@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "containmentactions.h"
8#include "containment.h"
9
10#include "private/containment_p.h"
11#include "private/containmentactions_p.h"
12
13#include <QContextMenuEvent>
14#include <QDebug>
15#include <QMetaEnum>
16#include <QMouseEvent>
17#include <QWheelEvent>
18
19#include <KLocalizedString>
20
21namespace Plasma
22{
24 : d(new ContainmentActionsPrivate({}, this))
25{
26 setParent(parentObject);
27}
28
29ContainmentActions::ContainmentActions(QObject *parentObject, const QVariantList &args)
30 : d(new ContainmentActionsPrivate(args.value(0), this))
31{
32 setParent(parentObject);
33
34 // now remove first item since those are managed by Wallpaper and subclasses shouldn't
35 // need to worry about them. yes, it violates the constness of this var, but it lets us add
36 // or remove items later while applets can just pretend that their args always start at 0
37 QVariantList &mutableArgs = const_cast<QVariantList &>(args);
38 if (!mutableArgs.isEmpty()) {
39 mutableArgs.removeFirst();
40 }
41}
42
43ContainmentActions::~ContainmentActions()
44{
45 delete d;
46}
47
49{
50 return d->containmentActionsDescription.pluginId();
51}
52
54{
55 return d->containmentActionsDescription.rawData().value(QStringLiteral("X-Plasma-HasConfigurationInterface")).toBool();
56}
57
59{
60 return d->containmentActionsDescription;
61}
62
64{
65 if (d->containment) {
66 return d->containment;
67 }
69}
70
72{
73 Q_UNUSED(config);
74}
75
77{
78 Q_UNUSED(config);
79}
80
86
88{
89 // do nothing by default
90}
91
93{
94 // do nothing by default, implement in subclasses
95}
96
98{
99 // do nothing by default, implement in subclasses
100}
101
106
108{
109 QString trigger;
110 Qt::KeyboardModifiers modifiers;
111
112 const auto &mo = Qt::staticMetaObject;
113
114 switch (event->type()) {
118 QMouseEvent *e = static_cast<QMouseEvent *>(event);
119 int m = mo.indexOfEnumerator("MouseButtons");
120 QMetaEnum mouse = mo.enumerator(m);
121 trigger += QString::fromLatin1(mouse.valueToKey(e->button()));
122 modifiers = e->modifiers();
123 break;
124 }
125 case QEvent::Wheel: {
126 QWheelEvent *e = static_cast<QWheelEvent *>(event);
127 trigger = QStringLiteral("wheel:%1")
128 .arg(std::abs(e->angleDelta().x()) > std::abs(e->angleDelta().y()) ? QStringLiteral("Horizontal") : QStringLiteral("Vertical"));
129 modifiers = e->modifiers();
130 break;
131 }
132 case QEvent::ContextMenu: {
133 int m = mo.indexOfEnumerator("MouseButtons");
134 QMetaEnum mouse = mo.enumerator(m);
136 modifiers = Qt::NoModifier;
137 break;
138 }
139 default:
140 return QString();
141 }
142
143 int k = mo.indexOfEnumerator("KeyboardModifiers");
144 QMetaEnum kbd = mo.enumerator(k);
145 trigger += QLatin1Char(';') + QString::fromLatin1(kbd.valueToKeys(modifiers));
146
147 return trigger;
148}
149
151{
152 d->containment = newContainment;
153}
154
155} // Plasma namespace
156
157#include "moc_containmentactions.cpp"
KPluginMetaData metadata() const
virtual void configurationAccepted()
This method is called when the user's configuration changes are accepted.
bool hasConfigurationInterface() const
Returns whether this plugin has a configuration UI.
virtual QWidget * createConfigurationInterface(QWidget *parent)
Returns the widget used in the configuration dialog.
virtual QList< QAction * > contextualActions()
Implement this to provide a list of actions that can be added to another menu for example,...
ContainmentActions(QObject *parent=nullptr)
Default constructor for an empty or null containmentactions.
virtual void restore(const KConfigGroup &config)
This method should be called once the plugin is loaded or settings are changed.
virtual void performPreviousAction()
Called when a "previous" action is triggered (e.g.
virtual void performNextAction()
Called when a "next" action is triggered (e.g.
QString id() const
Returns the ID of this plugin.
void setContainment(Containment *newContainment)
newContainment the containment the plugin should be associated with.
static QString eventToString(QEvent *event)
Turns a mouse or wheel event into a string suitable for a ContainmentActions.
virtual void save(KConfigGroup &config)
This method is called when settings need to be saved.
The base class for plugins that provide backgrounds and applet grouping containers.
Definition containment.h:47
Namespace for everything in libplasma.
MouseButtonPress
Qt::KeyboardModifiers modifiers() const const
const char * valueToKey(int value) const const
QByteArray valueToKeys(int value) const const
QObject(QObject *parent)
virtual bool event(QEvent *e)
QObject * parent() const const
T qobject_cast(QObject *object)
void setParent(QObject *parent)
int x() const const
int y() const const
Qt::MouseButton button() const const
QString arg(Args &&... args) const const
QString fromLatin1(QByteArrayView str)
typedef KeyboardModifiers
RightButton
QPoint angleDelta() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:48:23 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.