diff --git a/src/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp b/src/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp index 25bee2a7e..961f8a4ce 100644 --- a/src/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp +++ b/src/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp @@ -108,7 +108,7 @@ void PlasmaComponentsPlugin::registerTypes(const char *uri) qmlRegisterUncreatableType(uri, 2, 0, "DialogStatus", ""); qmlRegisterUncreatableType(uri, 2, 0, "PageOrientation", ""); qmlRegisterUncreatableType(uri, 2, 0, "PageStatus", ""); - qmlRegisterUncreatableType(uri, 0, 1, "Units", ""); + qmlRegisterUncreatableType(uri, 2, 0, "Units", ""); } diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp index 7a2f7388f..8304347ad 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp @@ -467,6 +467,59 @@ int AppletInterface::apiVersion() const return offers.first()->property("X-KDE-PluginInfo-Version", QVariant::Int).toInt(); } +//private api, just an helper +qreal AppletInterface::readGraphicsObjectSizeHint(const char *hint) const +{ + if (!m_qmlObject->rootObject()) { + return -1; + } + + + QVariant prop; + + if (m_compactUiObject) { + prop = m_compactUiObject.data()->property(hint); + } else { + prop = m_qmlObject->rootObject()->property(hint); + } + + if (prop.isValid() && prop.canConvert()) { + return qMax(qreal(1), prop.toReal()); + } else { + return -1; + } +} + +qreal AppletInterface::minimumWidth() const +{ + return readGraphicsObjectSizeHint("minimumWidth"); +} + +qreal AppletInterface::minimumHeight() const +{ + return readGraphicsObjectSizeHint("minimumHeight"); +} + +qreal AppletInterface::maximumWidth() const +{ + return readGraphicsObjectSizeHint("maximumWidth"); +} + +qreal AppletInterface::maximumHeight() const +{ + return readGraphicsObjectSizeHint("maximumHeight"); +} + +qreal AppletInterface::implicitWidth() const +{ + return readGraphicsObjectSizeHint("implicitWidth"); +} + +qreal AppletInterface::implicitHeight() const +{ + return readGraphicsObjectSizeHint("implicitHeight"); +} + void AppletInterface::debug(const QString &msg) { qDebug() << msg; @@ -521,8 +574,17 @@ void AppletInterface::geometryChanged(const QRectF &newGeometry, const QRectF &o return; } + //Read the minimum width of the full representation, not our own, since we could be in collapsed mode + QSizeF minHint(-1, -1); + if (m_qmlObject->rootObject()->property("minimumWidth").canConvert()) { + minHint.setWidth(m_qmlObject->rootObject()->property("minimumWidth").toReal()); + } + if (m_qmlObject->rootObject()->property("minimumHeight").canConvert()) { + minHint.setHeight(m_qmlObject->rootObject()->property("minimumHeight").toReal()); + } + //TODO: completely arbitrary for now - if (newGeometry.width() < 100 || newGeometry.height() < 100) { + if (newGeometry.width() < minHint.width() || newGeometry.height() < minHint.height()) { m_expanded = false; //we are already an icon: nothing to do @@ -537,7 +599,7 @@ void AppletInterface::geometryChanged(const QRectF &newGeometry, const QRectF &o //build the icon representation if (m_compactUiObject) { QQmlComponent *compactComponent = m_qmlObject->rootObject()->property("compactRepresentation").value(); - + if (compactComponent) { compactRepresentation = compactComponent->create(m_qmlObject->engine()->rootContext()); } else { @@ -563,10 +625,41 @@ void AppletInterface::geometryChanged(const QRectF &newGeometry, const QRectF &o QQmlExpression expr(m_qmlObject->engine()->rootContext(), m_compactUiObject.data(), "parent"); QQmlProperty prop(m_compactUiObject.data(), "anchors.fill"); prop.write(expr.evaluate()); - + m_qmlObject->rootObject()->setProperty("parent", QVariant::fromValue(m_compactUiObject.data())); m_compactUiObject.data()->setProperty("applet", QVariant::fromValue(m_qmlObject->rootObject())); - + + //hook m_compactUiObject size hints to this size hint + //Here we have to use the old connect syntax, because we don't have access to the class type + if (m_qmlObject->rootObject()) { + disconnect(m_qmlObject->rootObject(), 0, this, 0); + } + if (m_compactUiObject.data()->property("minimumWidth").isValid()) { + connect(m_compactUiObject.data(), SIGNAL(minimumWidthChanged()), + this, SIGNAL(minimumWidthChanged())); + } + if (m_compactUiObject.data()->property("minimumHeight").isValid()) { + connect(m_compactUiObject.data(), SIGNAL(minimumHeightChanged()), + this, SIGNAL(minimumHeightChanged())); + } + + if (m_compactUiObject.data()->property("maximumWidth").isValid()) { + connect(m_compactUiObject.data(), SIGNAL(maximumWidthChanged()), + this, SIGNAL(maximumWidthChanged())); + } + if (m_compactUiObject.data()->property("maximumHeight").isValid()) { + connect(m_compactUiObject.data(), SIGNAL(maximumHeightChanged()), + this, SIGNAL(maximumHeightChanged())); + } + + if (m_compactUiObject.data()->property("implicitWidth").isValid()) { + connect(m_compactUiObject.data(), SIGNAL(implicitWidthChanged()), + this, SIGNAL(implicitWidthChanged())); + } + if (m_compactUiObject.data()->property("implicitHeight").isValid()) { + connect(m_compactUiObject.data(), SIGNAL(implicitHeightChanged()), + this, SIGNAL(implicitHeightChanged())); + } //failed to create UI, don't do anything, return in expanded status } else { m_expanded = true; @@ -583,6 +676,35 @@ void AppletInterface::geometryChanged(const QRectF &newGeometry, const QRectF &o return; } + disconnect(m_compactUiObject.data(), 0, this, 0); + //Here we have to use the old connect syntax, because we don't have access to the class type + if (m_qmlObject->rootObject()->property("minimumWidth").isValid()) { + connect(m_qmlObject->rootObject(), SIGNAL(minimumWidthChanged()), + this, SIGNAL(minimumWidthChanged())); + } + if (m_qmlObject->rootObject()->property("minimumHeight").isValid()) { + connect(m_qmlObject->rootObject(), SIGNAL(minimumHeightChanged()), + this, SIGNAL(minimumHeightChanged())); + } + + if (m_qmlObject->rootObject()->property("maximumWidth").isValid()) { + connect(m_qmlObject->rootObject(), SIGNAL(maximumWidthChanged()), + this, SIGNAL(maximumWidthChanged())); + } + if (m_qmlObject->rootObject()->property("maximumHeight").isValid()) { + connect(m_qmlObject->rootObject(), SIGNAL(maximumHeightChanged()), + this, SIGNAL(maximumHeightChanged())); + } + + if (m_qmlObject->rootObject()->property("implicitWidth").isValid()) { + connect(m_qmlObject->rootObject(), SIGNAL(implicitWidthChanged()), + this, SIGNAL(implicitWidthChanged())); + } + if (m_qmlObject->rootObject()->property("implicitHeight").isValid()) { + connect(m_qmlObject->rootObject(), SIGNAL(implicitHeightChanged()), + this, SIGNAL(implicitHeightChanged())); + } + m_qmlObject->rootObject()->setProperty("parent", QVariant::fromValue(this)); m_compactUiObject.data()->deleteLater(); diff --git a/src/scriptengines/qml/plasmoid/appletinterface.h b/src/scriptengines/qml/plasmoid/appletinterface.h index 58dfecf1d..8de54ad4c 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.h +++ b/src/scriptengines/qml/plasmoid/appletinterface.h @@ -68,6 +68,14 @@ class AppletInterface : public QQuickItem Q_PROPERTY(Plasma::Types::ItemStatus status READ status WRITE setStatus NOTIFY statusChanged) Q_PROPERTY(QString associatedApplication WRITE setAssociatedApplication READ associatedApplication) + //Size hints Note that the containments may chose to not respect them. + Q_PROPERTY(qreal minimumWidth READ minimumWidth NOTIFY minimumWidthChanged) + Q_PROPERTY(qreal minimumHeight READ minimumHeight NOTIFY minimumHeightChanged) + Q_PROPERTY(qreal maximumWidth READ maximumWidth NOTIFY maximumWidthChanged) + Q_PROPERTY(qreal maximumHeight READ maximumHeight NOTIFY maximumHeightChanged) + Q_PROPERTY(qreal implicitWidth READ implicitWidth NOTIFY implicitWidthChanged) + Q_PROPERTY(qreal implicitHeight READ implicitHeight NOTIFY implicitHeightChanged) + public: AppletInterface(DeclarativeAppletScript *script, QQuickItem *parent = 0); ~AppletInterface(); @@ -142,6 +150,13 @@ public: bool userConfiguring() const; int apiVersion() const; + qreal minimumWidth() const; + qreal minimumHeight() const; + qreal maximumWidth() const; + qreal maximumHeight() const; + qreal implicitWidth() const; + qreal implicitHeight() const; + Q_SIGNALS: void releaseVisualFocus(); void configNeedsSaving(); @@ -157,6 +172,13 @@ Q_SIGNALS: void busyChanged(); void expandedChanged(); + void minimumWidthChanged(); + void minimumHeightChanged(); + void maximumWidthChanged(); + void maximumHeightChanged(); + void implicitWidthChanged(); + void implicitHeightChanged(); + protected: virtual void init(); void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); @@ -165,6 +187,9 @@ protected: DeclarativeAppletScript *m_appletScriptEngine; private: + //Helper for minimumWidth etc. + qreal readGraphicsObjectSizeHint(const char *hint) const; + QStringList m_actions; QSignalMapper *m_actionSignals; QString m_currentConfig; diff --git a/src/shell/applets/testapplet/contents/ui/main.qml b/src/shell/applets/testapplet/contents/ui/main.qml index b1de00497..31681130c 100644 --- a/src/shell/applets/testapplet/contents/ui/main.qml +++ b/src/shell/applets/testapplet/contents/ui/main.qml @@ -28,6 +28,8 @@ Rectangle { height: 100 radius: 10 smooth: true + property int minimumWidth: units.gridUnit * 20 + property int minimumHeight: column.implicitHeight property Component compactRepresentation: Component { Rectangle { @@ -39,6 +41,7 @@ Rectangle { } Column { + id: column anchors.centerIn: parent Text { text: "I'm an applet" diff --git a/src/shell/applets/testcomponentsapplet/contents/ui/testcomponents.qml b/src/shell/applets/testcomponentsapplet/contents/ui/testcomponents.qml index 1ecb6795b..2c04eb6d2 100644 --- a/src/shell/applets/testcomponentsapplet/contents/ui/testcomponents.qml +++ b/src/shell/applets/testcomponentsapplet/contents/ui/testcomponents.qml @@ -28,6 +28,8 @@ Item { width: 100 height: 100 clip: true + property int minimumWidth: units.gridUnit * 20 + property int minimumHeight: units.gridUnit * 30 property int _s: theme.iconSizes.small property int _h: theme.iconSizes.desktop diff --git a/src/shell/applets/testshaderapplet/contents/ui/testshaderapplet.qml b/src/shell/applets/testshaderapplet/contents/ui/testshaderapplet.qml index 4648e0a39..f61ec9cb7 100644 --- a/src/shell/applets/testshaderapplet/contents/ui/testshaderapplet.qml +++ b/src/shell/applets/testshaderapplet/contents/ui/testshaderapplet.qml @@ -28,6 +28,8 @@ Item { width: 400 height: 400 + property int minimumWidth: units.gridUnit * 20 + property int minimumHeight: units.gridUnit * 30 property int _s: theme.iconSizes.small property int _h: theme.iconSizes.desktop property int _m: 12 diff --git a/src/shell/containments/testpanel/contents/ui/main.qml b/src/shell/containments/testpanel/contents/ui/main.qml index 86ed8fecb..389a38a9b 100644 --- a/src/shell/containments/testpanel/contents/ui/main.qml +++ b/src/shell/containments/testpanel/contents/ui/main.qml @@ -64,12 +64,12 @@ Item { id: container visible: false - width: Math.min(root.width, root.height) - height: width + Layout.preferredWidth: Math.min(root.width, root.height) + Layout.preferredHeight: Layout.preferredWidth + property Item applet - PlasmaComponents.BusyIndicator { z: 1000 visible: applet && applet.length > 0 && applet[0].busy