make minimumWidth/maximum/implicit exportable

both the applet and its compact representation can now export minimumWidth,implicitWidth etc and those are exported to the root graphics item.

the minimum width of the applet is used to collapse in popup
This commit is contained in:
Marco Martin 2013-08-05 15:37:21 +02:00
parent 16ad4d7a14
commit ea42678895
7 changed files with 162 additions and 8 deletions

View File

@ -108,7 +108,7 @@ void PlasmaComponentsPlugin::registerTypes(const char *uri)
qmlRegisterUncreatableType<DialogStatus>(uri, 2, 0, "DialogStatus", ""); qmlRegisterUncreatableType<DialogStatus>(uri, 2, 0, "DialogStatus", "");
qmlRegisterUncreatableType<PageOrientation>(uri, 2, 0, "PageOrientation", ""); qmlRegisterUncreatableType<PageOrientation>(uri, 2, 0, "PageOrientation", "");
qmlRegisterUncreatableType<PageStatus>(uri, 2, 0, "PageStatus", ""); qmlRegisterUncreatableType<PageStatus>(uri, 2, 0, "PageStatus", "");
qmlRegisterUncreatableType<Units>(uri, 0, 1, "Units", ""); qmlRegisterUncreatableType<Units>(uri, 2, 0, "Units", "");
} }

View File

@ -467,6 +467,59 @@ int AppletInterface::apiVersion() const
return offers.first()->property("X-KDE-PluginInfo-Version", QVariant::Int).toInt(); 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<qreal>()) {
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) void AppletInterface::debug(const QString &msg)
{ {
qDebug() << msg; qDebug() << msg;
@ -521,8 +574,17 @@ void AppletInterface::geometryChanged(const QRectF &newGeometry, const QRectF &o
return; 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<qreal>()) {
minHint.setWidth(m_qmlObject->rootObject()->property("minimumWidth").toReal());
}
if (m_qmlObject->rootObject()->property("minimumHeight").canConvert<qreal>()) {
minHint.setHeight(m_qmlObject->rootObject()->property("minimumHeight").toReal());
}
//TODO: completely arbitrary for now //TODO: completely arbitrary for now
if (newGeometry.width() < 100 || newGeometry.height() < 100) { if (newGeometry.width() < minHint.width() || newGeometry.height() < minHint.height()) {
m_expanded = false; m_expanded = false;
//we are already an icon: nothing to do //we are already an icon: nothing to do
@ -567,6 +629,37 @@ void AppletInterface::geometryChanged(const QRectF &newGeometry, const QRectF &o
m_qmlObject->rootObject()->setProperty("parent", QVariant::fromValue(m_compactUiObject.data())); m_qmlObject->rootObject()->setProperty("parent", QVariant::fromValue(m_compactUiObject.data()));
m_compactUiObject.data()->setProperty("applet", QVariant::fromValue(m_qmlObject->rootObject())); 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 //failed to create UI, don't do anything, return in expanded status
} else { } else {
m_expanded = true; m_expanded = true;
@ -583,6 +676,35 @@ void AppletInterface::geometryChanged(const QRectF &newGeometry, const QRectF &o
return; 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_qmlObject->rootObject()->setProperty("parent", QVariant::fromValue(this));
m_compactUiObject.data()->deleteLater(); m_compactUiObject.data()->deleteLater();

View File

@ -68,6 +68,14 @@ class AppletInterface : public QQuickItem
Q_PROPERTY(Plasma::Types::ItemStatus status READ status WRITE setStatus NOTIFY statusChanged) Q_PROPERTY(Plasma::Types::ItemStatus status READ status WRITE setStatus NOTIFY statusChanged)
Q_PROPERTY(QString associatedApplication WRITE setAssociatedApplication READ associatedApplication) 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: public:
AppletInterface(DeclarativeAppletScript *script, QQuickItem *parent = 0); AppletInterface(DeclarativeAppletScript *script, QQuickItem *parent = 0);
~AppletInterface(); ~AppletInterface();
@ -142,6 +150,13 @@ public:
bool userConfiguring() const; bool userConfiguring() const;
int apiVersion() const; int apiVersion() const;
qreal minimumWidth() const;
qreal minimumHeight() const;
qreal maximumWidth() const;
qreal maximumHeight() const;
qreal implicitWidth() const;
qreal implicitHeight() const;
Q_SIGNALS: Q_SIGNALS:
void releaseVisualFocus(); void releaseVisualFocus();
void configNeedsSaving(); void configNeedsSaving();
@ -157,6 +172,13 @@ Q_SIGNALS:
void busyChanged(); void busyChanged();
void expandedChanged(); void expandedChanged();
void minimumWidthChanged();
void minimumHeightChanged();
void maximumWidthChanged();
void maximumHeightChanged();
void implicitWidthChanged();
void implicitHeightChanged();
protected: protected:
virtual void init(); virtual void init();
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
@ -165,6 +187,9 @@ protected:
DeclarativeAppletScript *m_appletScriptEngine; DeclarativeAppletScript *m_appletScriptEngine;
private: private:
//Helper for minimumWidth etc.
qreal readGraphicsObjectSizeHint(const char *hint) const;
QStringList m_actions; QStringList m_actions;
QSignalMapper *m_actionSignals; QSignalMapper *m_actionSignals;
QString m_currentConfig; QString m_currentConfig;

View File

@ -28,6 +28,8 @@ Rectangle {
height: 100 height: 100
radius: 10 radius: 10
smooth: true smooth: true
property int minimumWidth: units.gridUnit * 20
property int minimumHeight: column.implicitHeight
property Component compactRepresentation: Component { property Component compactRepresentation: Component {
Rectangle { Rectangle {
@ -39,6 +41,7 @@ Rectangle {
} }
Column { Column {
id: column
anchors.centerIn: parent anchors.centerIn: parent
Text { Text {
text: "I'm an applet" text: "I'm an applet"

View File

@ -28,6 +28,8 @@ Item {
width: 100 width: 100
height: 100 height: 100
clip: true clip: true
property int minimumWidth: units.gridUnit * 20
property int minimumHeight: units.gridUnit * 30
property int _s: theme.iconSizes.small property int _s: theme.iconSizes.small
property int _h: theme.iconSizes.desktop property int _h: theme.iconSizes.desktop

View File

@ -28,6 +28,8 @@ Item {
width: 400 width: 400
height: 400 height: 400
property int minimumWidth: units.gridUnit * 20
property int minimumHeight: units.gridUnit * 30
property int _s: theme.iconSizes.small property int _s: theme.iconSizes.small
property int _h: theme.iconSizes.desktop property int _h: theme.iconSizes.desktop
property int _m: 12 property int _m: 12

View File

@ -64,12 +64,12 @@ Item {
id: container id: container
visible: false visible: false
width: Math.min(root.width, root.height) Layout.preferredWidth: Math.min(root.width, root.height)
height: width Layout.preferredHeight: Layout.preferredWidth
property Item applet property Item applet
PlasmaComponents.BusyIndicator { PlasmaComponents.BusyIndicator {
z: 1000 z: 1000
visible: applet && applet.length > 0 && applet[0].busy visible: applet && applet.length > 0 && applet[0].busy