Plasma-framework

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;
51}
52
54{
55 if (d->containment) {
56 return d->containment;
57 }
58 return qobject_cast<Containment *>(parent());
59}
60
62{
63 Q_UNUSED(config);
64}
65
67{
68 Q_UNUSED(config);
69}
70
72{
73 Q_UNUSED(parent);
74 return nullptr;
75}
76
78{
79 // do nothing by default
80}
81
83{
84 // do nothing by default, implement in subclasses
85}
86
88{
89 // do nothing by default, implement in subclasses
90}
91
96
98{
99 QString trigger;
100 Qt::KeyboardModifiers modifiers;
101
102 const auto &mo = Qt::staticMetaObject;
103
104 switch (event->type()) {
108 QMouseEvent *e = static_cast<QMouseEvent *>(event);
109 int m = mo.indexOfEnumerator("MouseButtons");
110 QMetaEnum mouse = mo.enumerator(m);
111 trigger += QString::fromLatin1(mouse.valueToKey(e->button()));
112 modifiers = e->modifiers();
113 break;
114 }
115 case QEvent::Wheel: {
116 QWheelEvent *e = static_cast<QWheelEvent *>(event);
117 trigger = QStringLiteral("wheel:%1")
118 .arg(std::abs(e->angleDelta().x()) > std::abs(e->angleDelta().y()) ? QStringLiteral("Horizontal") : QStringLiteral("Vertical"));
119 modifiers = e->modifiers();
120 break;
121 }
122 case QEvent::ContextMenu: {
123 int m = mo.indexOfEnumerator("MouseButtons");
124 QMetaEnum mouse = mo.enumerator(m);
126 modifiers = Qt::NoModifier;
127 break;
128 }
129 default:
130 return QString();
131 }
132
133 int k = mo.indexOfEnumerator("KeyboardModifiers");
134 QMetaEnum kbd = mo.enumerator(k);
135 trigger += QLatin1Char(';') + QString::fromLatin1(kbd.valueToKeys(modifiers));
136
137 return trigger;
138}
139
141{
142 d->containment = newContainment;
143}
144
145} // Plasma namespace
146
147#include "moc_containmentactions.cpp"
KPluginMetaData metadata() const
virtual void configurationAccepted()
This method is called when the user's configuration changes are accepted.
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.
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
virtual bool event(QEvent *e)
QObject * parent() const const
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-2024 The KDE developers.
Generated on Fri May 17 2024 11:54:11 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.