add a Wallpaper attached property for wallpapers
This commit is contained in:
parent
be4c13e627
commit
9275e84a99
@ -59,7 +59,6 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *pa
|
|||||||
m_busy(false),
|
m_busy(false),
|
||||||
m_hideOnDeactivate(true)
|
m_hideOnDeactivate(true)
|
||||||
{
|
{
|
||||||
qmlRegisterType<AppletInterface>();
|
|
||||||
qmlRegisterType<QAction>();
|
qmlRegisterType<QAction>();
|
||||||
|
|
||||||
connect(this, &AppletInterface::configNeedsSaving,
|
connect(this, &AppletInterface::configNeedsSaving,
|
||||||
|
@ -59,8 +59,6 @@ ContainmentInterface::ContainmentInterface(DeclarativeAppletScript *parent)
|
|||||||
{
|
{
|
||||||
setAcceptedMouseButtons(Qt::AllButtons);
|
setAcceptedMouseButtons(Qt::AllButtons);
|
||||||
|
|
||||||
qmlRegisterType<ContainmentInterface>();
|
|
||||||
|
|
||||||
connect(containment(), &Plasma::Containment::appletRemoved,
|
connect(containment(), &Plasma::Containment::appletRemoved,
|
||||||
this, &ContainmentInterface::appletRemovedForward);
|
this, &ContainmentInterface::appletRemovedForward);
|
||||||
connect(containment(), &Plasma::Containment::appletAdded,
|
connect(containment(), &Plasma::Containment::appletAdded,
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
|
|
||||||
#include "plasmoid/appletinterface.h"
|
#include "plasmoid/appletinterface.h"
|
||||||
#include "plasmoid/containmentinterface.h"
|
#include "plasmoid/containmentinterface.h"
|
||||||
|
#include "plasmoid/wallpaperinterface.h"
|
||||||
|
|
||||||
#include <kdeclarative/qmlobject.h>
|
#include <kdeclarative/qmlobject.h>
|
||||||
#include <kdeclarative/configpropertymap.h>
|
#include <kdeclarative/configpropertymap.h>
|
||||||
@ -60,6 +61,9 @@ DeclarativeAppletScript::DeclarativeAppletScript(QObject *parent, const QVariant
|
|||||||
qmlRegisterUncreatableType<ContainmentInterface>("org.kde.plasma.plasmoid", 2, 0, "Containment",
|
qmlRegisterUncreatableType<ContainmentInterface>("org.kde.plasma.plasmoid", 2, 0, "Containment",
|
||||||
QLatin1String("Do not create objects of type Containment"));
|
QLatin1String("Do not create objects of type Containment"));
|
||||||
|
|
||||||
|
qmlRegisterUncreatableType<WallpaperInterface>("org.kde.plasma.plasmoid", 2, 0, "Wallpaper",
|
||||||
|
QLatin1String("Do not create objects of type Wallpaper"));
|
||||||
|
|
||||||
qmlRegisterType<KDeclarative::ConfigPropertyMap>();
|
qmlRegisterType<KDeclarative::ConfigPropertyMap>();
|
||||||
Q_UNUSED(args);
|
Q_UNUSED(args);
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,8 @@
|
|||||||
#include <Plasma/ConfigLoader>
|
#include <Plasma/ConfigLoader>
|
||||||
#include <Plasma/PluginLoader>
|
#include <Plasma/PluginLoader>
|
||||||
|
|
||||||
|
QHash<QObject *, WallpaperInterface *> WallpaperInterface::s_rootObjects = QHash<QObject *, WallpaperInterface *>();
|
||||||
|
|
||||||
WallpaperInterface::WallpaperInterface(ContainmentInterface *parent)
|
WallpaperInterface::WallpaperInterface(ContainmentInterface *parent)
|
||||||
: QQuickItem(parent),
|
: QQuickItem(parent),
|
||||||
m_containmentInterface(parent),
|
m_containmentInterface(parent),
|
||||||
@ -55,7 +57,9 @@ WallpaperInterface::WallpaperInterface(ContainmentInterface *parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
WallpaperInterface::~WallpaperInterface()
|
WallpaperInterface::~WallpaperInterface()
|
||||||
{}
|
{
|
||||||
|
s_rootObjects.remove(m_qmlObject->engine());
|
||||||
|
}
|
||||||
|
|
||||||
KPluginInfo::List WallpaperInterface::listWallpaperInfoForMimetype(const QString &mimetype, const QString &formFactor)
|
KPluginInfo::List WallpaperInterface::listWallpaperInfoForMimetype(const QString &mimetype, const QString &formFactor)
|
||||||
{
|
{
|
||||||
@ -109,6 +113,7 @@ void WallpaperInterface::syncWallpaperPackage()
|
|||||||
|
|
||||||
if (!m_qmlObject) {
|
if (!m_qmlObject) {
|
||||||
m_qmlObject = new KDeclarative::QmlObject(this);
|
m_qmlObject = new KDeclarative::QmlObject(this);
|
||||||
|
s_rootObjects[m_qmlObject->engine()] = this;
|
||||||
m_qmlObject->setInitializationDelayed(true);
|
m_qmlObject->setInitializationDelayed(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,6 +147,7 @@ void WallpaperInterface::syncWallpaperPackage()
|
|||||||
|
|
||||||
} else if (m_qmlObject->mainComponent()) {
|
} else if (m_qmlObject->mainComponent()) {
|
||||||
qWarning() << "Error loading the wallpaper" << m_qmlObject->mainComponent()->errors();
|
qWarning() << "Error loading the wallpaper" << m_qmlObject->mainComponent()->errors();
|
||||||
|
s_rootObjects.remove(m_qmlObject->engine());
|
||||||
m_qmlObject->deleteLater();
|
m_qmlObject->deleteLater();
|
||||||
m_qmlObject = 0;
|
m_qmlObject = 0;
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#define WALLPAPERINTERFACE_H
|
#define WALLPAPERINTERFACE_H
|
||||||
|
|
||||||
#include <QQuickItem>
|
#include <QQuickItem>
|
||||||
|
#include <QQmlEngine>
|
||||||
|
|
||||||
#include <Plasma/Package>
|
#include <Plasma/Package>
|
||||||
|
|
||||||
@ -78,6 +79,17 @@ public:
|
|||||||
|
|
||||||
Q_INVOKABLE QAction *action(QString name) const;
|
Q_INVOKABLE QAction *action(QString name) const;
|
||||||
|
|
||||||
|
static WallpaperInterface *qmlAttachedProperties(QObject *object)
|
||||||
|
{
|
||||||
|
//at the moment of the attached object creation, the root item is the only one that hasn't a parent
|
||||||
|
//only way to avoid creation of this attached for everybody but the root item
|
||||||
|
if (!object->parent() && s_rootObjects.contains(QtQml::qmlEngine(object))) {
|
||||||
|
return s_rootObjects.value(QtQml::qmlEngine(object));
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void packageChanged();
|
void packageChanged();
|
||||||
void configurationChanged();
|
void configurationChanged();
|
||||||
@ -95,6 +107,10 @@ private:
|
|||||||
Plasma::ConfigLoader *m_configLoader;
|
Plasma::ConfigLoader *m_configLoader;
|
||||||
KActionCollection *m_actions;
|
KActionCollection *m_actions;
|
||||||
QSignalMapper *m_actionSignals;
|
QSignalMapper *m_actionSignals;
|
||||||
|
|
||||||
|
static QHash<QObject *, WallpaperInterface *> s_rootObjects;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
QML_DECLARE_TYPEINFO(WallpaperInterface, QML_HAS_ATTACHED_PROPERTIES)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user