Plasma

containmentactions.cpp
1 /*
2  SPDX-FileCopyrightText: 2009 Chani Armitage <[email protected]>
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 
21 #include "version.h"
22 
23 namespace Plasma
24 {
26  : d(new ContainmentActionsPrivate({}, this))
27 {
28  setParent(parentObject);
29 }
30 
31 ContainmentActions::ContainmentActions(QObject *parentObject, const QVariantList &args)
32  : d(new ContainmentActionsPrivate(args.value(0), this))
33 {
34  setParent(parentObject);
35 
36  // now remove first item since those are managed by Wallpaper and subclasses shouldn't
37  // need to worry about them. yes, it violates the constness of this var, but it lets us add
38  // or remove items later while applets can just pretend that their args always start at 0
39  QVariantList &mutableArgs = const_cast<QVariantList &>(args);
40  if (!mutableArgs.isEmpty()) {
41  mutableArgs.removeFirst();
42  }
43 }
44 
45 ContainmentActions::~ContainmentActions()
46 {
47  delete d;
48 }
49 
50 #if PLASMA_BUILD_DEPRECATED_SINCE(5, 67)
52 {
53  return KPluginInfo(d->containmentActionsDescription);
54 }
55 #endif
56 
58 {
59  return d->containmentActionsDescription;
60 }
61 
63 {
64  if (d->containment) {
65  return d->containment;
66  }
67  return qobject_cast<Containment *>(parent());
68 }
69 
71 {
72  Q_UNUSED(config);
73 }
74 
76 {
77  Q_UNUSED(config);
78 }
79 
81 {
82  Q_UNUSED(parent);
83  return nullptr;
84 }
85 
87 {
88  // do nothing by default
89 }
90 
92 {
93  // do nothing by default, implement in subclasses
94 }
95 
97 {
98  // do nothing by default, implement in subclasses
99 }
100 
102 {
103  return QList<QAction *>();
104 }
105 
107 {
108  QString trigger;
109  Qt::KeyboardModifiers modifiers;
110 
111 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
112  const auto &mo = QObject::staticQtMetaObject;
113 #else
114  const auto &mo = Qt::staticMetaObject;
115 #endif
116 
117  switch (event->type()) {
121  QMouseEvent *e = static_cast<QMouseEvent *>(event);
122  int m = mo.indexOfEnumerator("MouseButtons");
123  QMetaEnum mouse = mo.enumerator(m);
124  trigger += QString::fromLatin1(mouse.valueToKey(e->button()));
125  modifiers = e->modifiers();
126  break;
127  }
128  case QEvent::Wheel: {
129  QWheelEvent *e = static_cast<QWheelEvent *>(event);
130  trigger = QStringLiteral("wheel:%1")
131  .arg(std::abs(e->angleDelta().x()) > std::abs(e->angleDelta().y()) ? QStringLiteral("Horizontal") : QStringLiteral("Vertical"));
132  modifiers = e->modifiers();
133  break;
134  }
135  case QEvent::ContextMenu: {
136  int m = mo.indexOfEnumerator("MouseButtons");
137  QMetaEnum mouse = mo.enumerator(m);
139  modifiers = Qt::NoModifier;
140  break;
141  }
142  default:
143  return QString();
144  }
145 
146  int k = mo.indexOfEnumerator("KeyboardModifiers");
147  QMetaEnum kbd = mo.enumerator(k);
148  trigger += QLatin1Char(';') + QString::fromLatin1(kbd.valueToKeys(modifiers));
149 
150  return trigger;
151 }
152 
154 {
155  d->containment = newContainment;
156 }
157 
158 } // Plasma namespace
159 
160 #include "moc_containmentactions.cpp"
MouseButtonPress
Namespace for everything in libplasma.
Definition: datamodel.cpp:14
Qt::MouseButton button() const const
QPoint angleDelta() const const
virtual void configurationAccepted()
This method is called when the user's configuration changes are accepted.
int x() const const
int y() const const
RightButton
virtual void performPreviousAction()
Called when a "previous" action is triggered (e.g.
ContainmentActions(QObject *parent=nullptr)
Default constructor for an empty or null containmentactions.
virtual void performNextAction()
Called when a "next" action is triggered (e.g.
virtual QWidget * createConfigurationInterface(QWidget *parent)
Returns the widget used in the configuration dialog.
virtual bool event(QEvent *e)
KPluginMetaData metadata() const
const char * valueToKey(int value) const const
void setContainment(Containment *newContainment)
newContainment the containment the plugin should be associated with.
Qt::KeyboardModifiers modifiers() const const
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString fromLatin1(const char *str, int size)
void setParent(QObject *parent)
KPluginInfo pluginInfo() const
virtual void save(KConfigGroup &config)
This method is called when settings need to be saved.
static QString eventToString(QEvent *event)
Turns a mouse or wheel event into a string suitable for a ContainmentActions.
QByteArray valueToKeys(int value) const const
typedef KeyboardModifiers
The base class for plugins that provide backgrounds and applet grouping containers.
Definition: containment.h:45
virtual QList< QAction * > contextualActions()
Implement this to provide a list of actions that can be added to another menu for example,...
QObject * parent() const const
virtual void restore(const KConfigGroup &config)
This method should be called once the plugin is loaded or settings are changed.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Mar 23 2023 04:18:16 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.