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<PageOrientation>(uri, 2, 0, "PageOrientation", "");
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();
}
//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)
{
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<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
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<QQmlComponent *>();
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();

View File

@ -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;

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -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