Make AppletQuickItem return QQuickItems
It was returning QObjects on most places and it didn't make much sense since since it was just expecting the API users to qobject_cast to QQuickItem to do anything with these. Considering that fullRepresentation can be anything other than a graphic item doesn't sound good anyway.
This commit is contained in:
parent
ee3deabb48
commit
3d77ac5008
@ -160,7 +160,7 @@ void AppletQuickItemPrivate::propagateSizeHint(const QByteArray &layoutProperty)
|
||||
}
|
||||
}
|
||||
|
||||
QObject *AppletQuickItemPrivate::createCompactRepresentationItem()
|
||||
QQuickItem *AppletQuickItemPrivate::createCompactRepresentationItem()
|
||||
{
|
||||
if (!compactRepresentation) {
|
||||
return 0;
|
||||
@ -170,24 +170,24 @@ QObject *AppletQuickItemPrivate::createCompactRepresentationItem()
|
||||
return compactRepresentationItem.data();
|
||||
}
|
||||
|
||||
compactRepresentationItem = qmlObject->createObjectFromComponent(compactRepresentation.data(), QtQml::qmlContext(qmlObject->rootObject()));
|
||||
compactRepresentationItem = qobject_cast<QQuickItem*>(qmlObject->createObjectFromComponent(compactRepresentation.data(), QtQml::qmlContext(qmlObject->rootObject())));
|
||||
|
||||
emit q->compactRepresentationItemChanged(compactRepresentationItem.data());
|
||||
|
||||
return compactRepresentationItem.data();
|
||||
}
|
||||
|
||||
QObject *AppletQuickItemPrivate::createFullRepresentationItem()
|
||||
QQuickItem *AppletQuickItemPrivate::createFullRepresentationItem()
|
||||
{
|
||||
if (fullRepresentationItem) {
|
||||
return fullRepresentationItem.data();
|
||||
}
|
||||
|
||||
if (fullRepresentation && fullRepresentation.data() != qmlObject->mainComponent()) {
|
||||
fullRepresentationItem = qmlObject->createObjectFromComponent(fullRepresentation.data(), QtQml::qmlContext(qmlObject->rootObject()));
|
||||
fullRepresentationItem = qobject_cast<QQuickItem*>(qmlObject->createObjectFromComponent(fullRepresentation.data(), QtQml::qmlContext(qmlObject->rootObject())));
|
||||
} else {
|
||||
fullRepresentation = qmlObject->mainComponent();
|
||||
fullRepresentationItem = qmlObject->rootObject();
|
||||
fullRepresentationItem = qobject_cast<QQuickItem*>(qmlObject->rootObject());
|
||||
emit q->fullRepresentationChanged(fullRepresentation.data());
|
||||
}
|
||||
|
||||
@ -195,7 +195,7 @@ QObject *AppletQuickItemPrivate::createFullRepresentationItem()
|
||||
return 0;
|
||||
}
|
||||
|
||||
QQuickItem *graphicsObj = qobject_cast<QQuickItem *>(fullRepresentationItem.data());
|
||||
QQuickItem *graphicsObj = fullRepresentationItem.data();
|
||||
|
||||
QObject::connect(graphicsObj, &QQuickItem::widthChanged, [ = ]() {
|
||||
fullRepresentationResizeTimer.start();
|
||||
@ -209,7 +209,7 @@ QObject *AppletQuickItemPrivate::createFullRepresentationItem()
|
||||
return fullRepresentationItem.data();
|
||||
}
|
||||
|
||||
QObject *AppletQuickItemPrivate::createCompactRepresentationExpanderItem()
|
||||
QQuickItem *AppletQuickItemPrivate::createCompactRepresentationExpanderItem()
|
||||
{
|
||||
if (!compactRepresentationExpander) {
|
||||
return 0;
|
||||
@ -219,7 +219,7 @@ QObject *AppletQuickItemPrivate::createCompactRepresentationExpanderItem()
|
||||
return compactRepresentationExpanderItem.data();
|
||||
}
|
||||
|
||||
compactRepresentationExpanderItem = qmlObject->createObjectFromComponent(compactRepresentationExpander.data(), QtQml::qmlContext(qmlObject->rootObject()));
|
||||
compactRepresentationExpanderItem = qobject_cast<QQuickItem*>(qmlObject->createObjectFromComponent(compactRepresentationExpander.data(), QtQml::qmlContext(qmlObject->rootObject())));
|
||||
|
||||
if (!compactRepresentationExpanderItem) {
|
||||
return 0;
|
||||
@ -269,14 +269,14 @@ void AppletQuickItemPrivate::compactRepresentationCheck()
|
||||
|
||||
//Expanded
|
||||
if (full) {
|
||||
QQuickItem *item = qobject_cast<QQuickItem *>(createFullRepresentationItem());
|
||||
QQuickItem *item = createFullRepresentationItem();
|
||||
|
||||
if (item) {
|
||||
//unwire with the expander
|
||||
if (compactRepresentationExpanderItem) {
|
||||
compactRepresentationExpanderItem.data()->setProperty("fullRepresentation", QVariant());
|
||||
compactRepresentationExpanderItem.data()->setProperty("compactRepresentation", QVariant());
|
||||
compactRepresentationExpanderItem.data()->setProperty("visible", false);
|
||||
compactRepresentationExpanderItem.data()->setVisible(false);
|
||||
}
|
||||
|
||||
item->setParentItem(q);
|
||||
@ -288,7 +288,7 @@ void AppletQuickItemPrivate::compactRepresentationCheck()
|
||||
}
|
||||
|
||||
if (compactRepresentationItem) {
|
||||
compactRepresentationItem.data()->setProperty("visible", false);
|
||||
compactRepresentationItem.data()->setVisible(false);
|
||||
}
|
||||
|
||||
currentRepresentationItem = item;
|
||||
@ -299,8 +299,8 @@ void AppletQuickItemPrivate::compactRepresentationCheck()
|
||||
|
||||
//Icon
|
||||
} else {
|
||||
QQuickItem *compactItem = qobject_cast<QQuickItem *>(createCompactRepresentationItem());
|
||||
QQuickItem *compactExpanderItem = qobject_cast<QQuickItem *>(createCompactRepresentationExpanderItem());
|
||||
QQuickItem *compactItem = createCompactRepresentationItem();
|
||||
QQuickItem *compactExpanderItem = createCompactRepresentationExpanderItem();
|
||||
|
||||
if (compactItem && compactExpanderItem) {
|
||||
//set the root item as the main visible item
|
||||
@ -398,8 +398,8 @@ AppletQuickItem::AppletQuickItem(Plasma::Applet *applet, QQuickItem *parent)
|
||||
if (!d->applet->isContainment()) {
|
||||
KConfigGroup cg = d->applet->config();
|
||||
cg = KConfigGroup(&cg, "PopupApplet");
|
||||
cg.writeEntry("DialogWidth", d->fullRepresentationItem.data()->property("width").toInt());
|
||||
cg.writeEntry("DialogHeight", d->fullRepresentationItem.data()->property("height").toInt());
|
||||
cg.writeEntry("DialogWidth", d->fullRepresentationItem.data()->width());
|
||||
cg.writeEntry("DialogHeight", d->fullRepresentationItem.data()->height());
|
||||
}
|
||||
});
|
||||
|
||||
@ -494,10 +494,10 @@ void AppletQuickItem::init()
|
||||
//default fullrepresentation is our root main component, if none specified
|
||||
if (!d->fullRepresentation) {
|
||||
d->fullRepresentation = d->qmlObject->mainComponent();
|
||||
d->fullRepresentationItem = d->qmlObject->rootObject();
|
||||
d->fullRepresentationItem = qobject_cast<QQuickItem*>(d->qmlObject->rootObject());
|
||||
|
||||
if (d->qmlObject->rootObject()) {
|
||||
QQuickItem *graphicsObj = qobject_cast<QQuickItem *>(d->fullRepresentationItem.data());
|
||||
QQuickItem *graphicsObj = d->fullRepresentationItem.data();
|
||||
QObject::connect(graphicsObj, &QQuickItem::widthChanged, [ = ]() {
|
||||
d->fullRepresentationResizeTimer.start();
|
||||
});
|
||||
@ -648,8 +648,8 @@ void AppletQuickItem::setExpanded(bool expanded)
|
||||
const int width = cg.readEntry("DialogWidth", -1);
|
||||
const int height = cg.readEntry("DialogHeight", -1);
|
||||
if (width > 0 && height > 0) {
|
||||
d->fullRepresentationItem.data()->setProperty("width", width);
|
||||
d->fullRepresentationItem.data()->setProperty("height", height);
|
||||
d->fullRepresentationItem.data()->setWidth(width);
|
||||
d->fullRepresentationItem.data()->setHeight(height);
|
||||
}
|
||||
|
||||
if (d->compactRepresentationExpanderItem) {
|
||||
@ -670,12 +670,12 @@ KDeclarative::QmlObject *AppletQuickItem::qmlObject()
|
||||
return d->qmlObject;
|
||||
}
|
||||
|
||||
QObject *AppletQuickItem::compactRepresentationItem()
|
||||
QQuickItem *AppletQuickItem::compactRepresentationItem()
|
||||
{
|
||||
return d->compactRepresentationItem.data();
|
||||
}
|
||||
|
||||
QObject *AppletQuickItem::fullRepresentationItem()
|
||||
QQuickItem *AppletQuickItem::fullRepresentationItem()
|
||||
{
|
||||
return d->fullRepresentationItem.data();
|
||||
}
|
||||
|
@ -64,10 +64,10 @@ class PLASMAQUICK_EXPORT AppletQuickItem : public QQuickItem
|
||||
Q_PROPERTY(int switchHeight READ switchHeight WRITE setSwitchHeight NOTIFY switchHeightChanged)
|
||||
|
||||
Q_PROPERTY(QQmlComponent *compactRepresentation READ compactRepresentation WRITE setCompactRepresentation NOTIFY compactRepresentationChanged)
|
||||
Q_PROPERTY(QObject *compactRepresentationItem READ compactRepresentationItem NOTIFY compactRepresentationItemChanged)
|
||||
Q_PROPERTY(QQuickItem *compactRepresentationItem READ compactRepresentationItem NOTIFY compactRepresentationItemChanged)
|
||||
|
||||
Q_PROPERTY(QQmlComponent *fullRepresentation READ fullRepresentation WRITE setFullRepresentation NOTIFY fullRepresentationChanged)
|
||||
Q_PROPERTY(QObject *fullRepresentationItem READ fullRepresentationItem NOTIFY fullRepresentationItemChanged)
|
||||
Q_PROPERTY(QQuickItem *fullRepresentationItem READ fullRepresentationItem NOTIFY fullRepresentationItemChanged)
|
||||
|
||||
/**
|
||||
* this is supposed to be either one between compactRepresentation or fullRepresentation
|
||||
@ -102,8 +102,8 @@ public:
|
||||
Plasma::Package coronaPackage() const;
|
||||
void setCoronaPackage(const Plasma::Package &package);
|
||||
|
||||
QObject *compactRepresentationItem();
|
||||
QObject *fullRepresentationItem();
|
||||
QQuickItem *compactRepresentationItem();
|
||||
QQuickItem *fullRepresentationItem();
|
||||
QObject *rootItem();
|
||||
|
||||
////PROPERTY ACCESSORS
|
||||
|
@ -21,6 +21,7 @@
|
||||
#define APPLETQUICKITEM_P_H
|
||||
|
||||
#include <QQmlComponent>
|
||||
#include <qquickitem.h>
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
@ -53,9 +54,9 @@ class AppletQuickItemPrivate
|
||||
public:
|
||||
AppletQuickItemPrivate(Plasma::Applet *a, AppletQuickItem *item);
|
||||
|
||||
QObject *createCompactRepresentationItem();
|
||||
QObject *createFullRepresentationItem();
|
||||
QObject *createCompactRepresentationExpanderItem();
|
||||
QQuickItem *createCompactRepresentationItem();
|
||||
QQuickItem *createFullRepresentationItem();
|
||||
QQuickItem *createCompactRepresentationExpanderItem();
|
||||
|
||||
//look into item, and return the Layout attached property, if found
|
||||
void connectLayoutAttached(QObject *item);
|
||||
@ -82,10 +83,10 @@ public:
|
||||
QWeakPointer<QQmlComponent> preferredRepresentation;
|
||||
QWeakPointer<QQmlComponent> compactRepresentationExpander;
|
||||
|
||||
QWeakPointer<QObject> compactRepresentationItem;
|
||||
QWeakPointer<QObject> fullRepresentationItem;
|
||||
QWeakPointer<QObject> compactRepresentationExpanderItem;
|
||||
QWeakPointer<QObject> currentRepresentationItem;
|
||||
QWeakPointer<QQuickItem> compactRepresentationItem;
|
||||
QWeakPointer<QQuickItem> fullRepresentationItem;
|
||||
QWeakPointer<QQuickItem> compactRepresentationExpanderItem;
|
||||
QWeakPointer<QQuickItem> currentRepresentationItem;
|
||||
|
||||
//Attached layout objects: own and the representation's one
|
||||
QWeakPointer<QObject> representationLayout;
|
||||
|
Loading…
Reference in New Issue
Block a user