23#include "private/dataengineconsumer_p.h"
24#include "private/packages_p.h"
25#include "private/containmentactions_p.h"
26#include "private/containment_p.h"
31#include <QGraphicsSceneContextMenuEvent>
32#include <QGraphicsSceneMouseEvent>
33#include <QGraphicsSceneWheelEvent>
37#include <kservicetypetrader.h>
38#include <kstandarddirs.h>
45PackageStructure::Ptr ContainmentActionsPrivate::s_packageStructure(0);
47ContainmentActions::ContainmentActions(
QObject * parentObject)
48 : d(new ContainmentActionsPrivate(KService::serviceByStorageId(QString()), this))
50 setParent(parentObject);
53ContainmentActions::ContainmentActions(
QObject *parentObject,
const QVariantList &args)
54 : d(new ContainmentActionsPrivate(KService::serviceByStorageId(args.count() > 0 ?
55 args[0].toString() : QString()), this))
60 QVariantList &mutableArgs =
const_cast<QVariantList &
>(args);
61 if (!mutableArgs.isEmpty()) {
62 mutableArgs.removeFirst();
65 setParent(parentObject);
68ContainmentActions::~ContainmentActions()
73KPluginInfo::List ContainmentActions::listContainmentActionsInfo()
77 KService::List offers = KServiceTypeTrader::self()->query(
"Plasma/ContainmentActions", constraint);
78 return KPluginInfo::fromServices(offers);
83 if (containmentActionsName.isEmpty()) {
87 QString constraint = QString(
"[X-KDE-PluginInfo-Name] == '%1'").arg(containmentActionsName);
88 KService::List offers = KServiceTypeTrader::self()->query(
"Plasma/ContainmentActions", constraint);
90 if (offers.isEmpty()) {
91 kDebug() <<
"offers is empty for " << containmentActionsName;
95 KService::Ptr offer = offers.first();
96 KPluginLoader plugin(*offer);
102 QVariantList allArgs;
103 allArgs << offer->storageId() << args;
107 if (!containmentActions) {
108 kDebug() <<
"Couldn't load containmentActions \"" << containmentActionsName <<
"\"! reason given: " << error;
111 return containmentActions;
116 if (!info.isValid()) {
124 if (!ContainmentActionsPrivate::s_packageStructure) {
128 return ContainmentActionsPrivate::s_packageStructure;
133 if (d->containment) {
134 return d->containment;
136 return qobject_cast<Containment*>(parent());
139QString ContainmentActions::name()
const
141 if (!d->containmentActionsDescription.isValid()) {
142 return i18n(
"Unknown ContainmentActions");
145 return d->containmentActionsDescription.name();
148QString ContainmentActions::icon()
const
150 if (!d->containmentActionsDescription.isValid()) {
154 return d->containmentActionsDescription.icon();
157QString ContainmentActions::pluginName()
const
159 if (!d->containmentActionsDescription.isValid()) {
163 return d->containmentActionsDescription.pluginName();
166bool ContainmentActions::isInitialized()
const
168 return d->initialized;
171void ContainmentActions::restore(
const KConfigGroup &config)
174 d->initialized =
true;
177void ContainmentActions::init(
const KConfigGroup &config)
182void ContainmentActions::save(KConfigGroup &config)
193void ContainmentActions::configurationAccepted()
198void ContainmentActions::contextEvent(QEvent *event)
203QList<QAction*> ContainmentActions::contextualActions()
206 return QList<QAction*>();
209DataEngine *ContainmentActions::dataEngine(
const QString &name)
const
211 return d->dataEngine(
name);
214bool ContainmentActions::configurationRequired()
const
216 return d->needsConfig;
219void ContainmentActions::setConfigurationRequired(
bool needsConfig)
222 d->needsConfig = needsConfig;
225QString ContainmentActions::eventToString(QEvent *event)
228 Qt::KeyboardModifiers modifiers;
230 switch (
event->type()) {
231 case QEvent::MouseButtonPress:
232 case QEvent::MouseButtonRelease:
234 QMouseEvent *e =
static_cast<QMouseEvent*
>(
event);
235 int m = QObject::staticQtMetaObject.indexOfEnumerator(
"MouseButtons");
236 QMetaEnum mouse = QObject::staticQtMetaObject.enumerator(m);
237 trigger += mouse.valueToKey(e->button());
238 modifiers = e->modifiers();
241 case QEvent::GraphicsSceneMousePress:
242 case QEvent::GraphicsSceneMouseRelease:
243 case QEvent::GraphicsSceneMouseDoubleClick:
245 QGraphicsSceneMouseEvent *e =
static_cast<QGraphicsSceneMouseEvent*
>(
event);
246 int m = QObject::staticQtMetaObject.indexOfEnumerator(
"MouseButtons");
247 QMetaEnum mouse = QObject::staticQtMetaObject.enumerator(m);
248 trigger += mouse.valueToKey(e->button());
249 modifiers = e->modifiers();
254 QWheelEvent *e =
static_cast<QWheelEvent*
>(
event);
255 int o = QObject::staticQtMetaObject.indexOfEnumerator(
"Orientations");
256 QMetaEnum orient = QObject::staticQtMetaObject.enumerator(o);
258 trigger += orient.valueToKey(e->orientation());
259 modifiers = e->modifiers();
262 case QEvent::GraphicsSceneWheel:
264 QGraphicsSceneWheelEvent *e =
static_cast<QGraphicsSceneWheelEvent*
>(
event);
265 int o = QObject::staticQtMetaObject.indexOfEnumerator(
"Orientations");
266 QMetaEnum orient = QObject::staticQtMetaObject.enumerator(o);
268 trigger += orient.valueToKey(e->orientation());
269 modifiers = e->modifiers();
272 case QEvent::GraphicsSceneContextMenu:
273 case QEvent::ContextMenu:
275 int m = QObject::staticQtMetaObject.indexOfEnumerator(
"MouseButtons");
276 QMetaEnum mouse = QObject::staticQtMetaObject.enumerator(m);
277 trigger = mouse.valueToKey(Qt::RightButton);
278 modifiers = Qt::NoModifier;
285 int k = QObject::staticQtMetaObject.indexOfEnumerator(
"KeyboardModifiers");
286 QMetaEnum kbd = QObject::staticQtMetaObject.enumerator(k);
288 trigger += kbd.valueToKeys(modifiers);
293void ContainmentActions::paste(QPointF scenePos, QPoint screenPos)
297 c->d->dropData(scenePos, screenPos);
303 switch (event->type()) {
304 case QEvent::GraphicsSceneMousePress:
305 case QEvent::GraphicsSceneMouseRelease:
306 case QEvent::GraphicsSceneMouseDoubleClick:
307 return static_cast<QGraphicsSceneMouseEvent*
>(event)->screenPos();
309 case QEvent::GraphicsSceneWheel:
310 return static_cast<QGraphicsSceneWheelEvent*
>(event)->screenPos();
312 case QEvent::GraphicsSceneContextMenu:
313 return static_cast<QGraphicsSceneContextMenuEvent*
>(event)->screenPos();
324 switch (event->type()) {
325 case QEvent::GraphicsSceneMousePress:
326 case QEvent::GraphicsSceneMouseRelease:
327 case QEvent::GraphicsSceneMouseDoubleClick:
328 return static_cast<QGraphicsSceneMouseEvent*
>(event)->scenePos();
330 case QEvent::GraphicsSceneWheel:
331 return static_cast<QGraphicsSceneWheelEvent*
>(event)->scenePos();
333 case QEvent::GraphicsSceneContextMenu:
334 return static_cast<QGraphicsSceneContextMenuEvent*
>(event)->scenePos();
345 return dynamic_cast<QGraphicsSceneEvent *
>(event) == 0;
348QPoint ContainmentActions::popupPosition(
const QSize &s, QEvent *event)
361 QPoint pos = screenPos;
362 if (applet &&
containment()->d->isPanelContainment()) {
364 if (
event->type() != QEvent::GraphicsSceneContextMenu ||
365 static_cast<QGraphicsSceneContextMenuEvent *
>(
event)->reason() == QGraphicsSceneContextMenuEvent::Mouse) {
369 if (pos.y() + s.height() < screenPos.y()) {
370 pos.setY(screenPos.y());
373 if (pos.x() + s.width() < screenPos.x()) {
374 pos.setX(screenPos.x());
383bool ContainmentActions::event(QEvent *)
389void ContainmentActions::setContainment(
Containment *newContainment) {
390 d->containment = newContainment;
395#include "containmentactions.moc"
virtual FormFactor formFactor() const
Returns the current form factor the applet is being displayed in.
QPoint popupPosition(const QSize &s) const
Reccomended position for a popup window like a menu or a tooltip given its size.
The base ContainmentActions class.
virtual void init(const KConfigGroup &config)
This method is called once the containmentactions is loaded or settings are changed.
friend class ContainmentActionsPackage
bool event(QEvent *e)
@reimplemented
static ContainmentActions * load(Containment *parent, const QString &name, const QVariantList &args=QVariantList())
Attempts to load a containmentactions.
Containment * containment()
The base class for plugins that provide backgrounds and applet grouping containers.
Data provider for plasmoids (Plasma plugins)
KSharedPtr< PackageStructure > Ptr
Namespace for everything in libplasma.
bool isNonSceneEvent(QEvent *event)
QPoint screenPosFromEvent(QEvent *event)
QPointF scenePosFromEvent(QEvent *event)
bool isPluginVersionCompatible(unsigned int version)
Verifies that a plugin is compatible with plasma.
@ Horizontal
The applet is constrained vertically, but can expand horizontally.
@ Vertical
The applet is constrained horizontally, but can expand vertically.