move the "icon" in another file

so applets will be able to provide their own compactRepresentation
This commit is contained in:
Marco Martin 2013-02-13 19:56:08 +01:00
parent 0a03157807
commit f51895ab91
6 changed files with 98 additions and 14 deletions

View File

@ -49,7 +49,8 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *pa
m_appletScriptEngine(script), m_appletScriptEngine(script),
m_actionSignals(0), m_actionSignals(0),
m_backgroundHints(Plasma::StandardBackground), m_backgroundHints(Plasma::StandardBackground),
m_busy(false) m_busy(false),
m_expanded(false)
{ {
qmlRegisterType<AppletInterface>(); qmlRegisterType<AppletInterface>();
connect(this, SIGNAL(releaseVisualFocus()), applet(), SIGNAL(releaseVisualFocus())); connect(this, SIGNAL(releaseVisualFocus()), applet(), SIGNAL(releaseVisualFocus()));
@ -120,6 +121,23 @@ void AppletInterface::setBusy(bool busy)
emit busyChanged(); emit busyChanged();
} }
bool AppletInterface::isExpanded() const
{
return m_expanded;
}
void AppletInterface::setExpanded(bool expanded)
{
//if there is no compact representation it means it's always expanded
//Containnments are always expanded
if (!m_compactUiObject || qobject_cast<ContainmentInterface *>(this) || m_expanded == expanded) {
return;
}
m_expanded = expanded;
emit expandedChanged();
}
AppletInterface::BackgroundHints AppletInterface::backgroundHints() const AppletInterface::BackgroundHints AppletInterface::backgroundHints() const
{ {
return (BackgroundHints)m_backgroundHints; return (BackgroundHints)m_backgroundHints;
@ -377,13 +395,15 @@ void AppletInterface::geometryChanged(const QRectF &newGeometry, const QRectF &o
Q_UNUSED(oldGeometry) Q_UNUSED(oldGeometry)
QQuickItem::geometryChanged(newGeometry, oldGeometry); QQuickItem::geometryChanged(newGeometry, oldGeometry);
if (!m_uiObject || qobject_cast<ContainmentInterface *>(this)) { if (!m_uiObject || qobject_cast<ContainmentInterface *>(this)) {
return; return;
} }
//TODO: completely arbitrary for now //TODO: completely arbitrary for now
if (newGeometry.width() < 100 || newGeometry.height() < 100) { if (newGeometry.width() < 100 || newGeometry.height() < 100) {
m_expanded = false;
//we are already an icon: nothing to do //we are already an icon: nothing to do
if (m_compactUiObject) { if (m_compactUiObject) {
return; return;
@ -391,12 +411,30 @@ void AppletInterface::geometryChanged(const QRectF &newGeometry, const QRectF &o
QQmlComponent *component = new QQmlComponent(m_appletScriptEngine->engine(), this); QQmlComponent *component = new QQmlComponent(m_appletScriptEngine->engine(), this);
component->loadUrl(QUrl::fromLocalFile(applet()->containment()->corona()->package().filePath("ui", "CompactApplet.qml"))); component->loadUrl(QUrl::fromLocalFile(applet()->containment()->corona()->package().filePath("ui", "CompactApplet.qml")));
m_compactUiObject = component->create(); m_compactUiObject = component->create(m_appletScriptEngine->engine()->rootContext());
QObject *compactRepresentation = 0;
//build the icon representation
if (m_compactUiObject) { if (m_compactUiObject) {
QQmlComponent *compactComponent = new QQmlComponent(m_appletScriptEngine->engine(), this);
compactComponent->loadUrl(QUrl::fromLocalFile(applet()->containment()->corona()->package().filePath("ui", "DefaultCompactRepresentation.qml")));
compactRepresentation = compactComponent->create(m_appletScriptEngine->engine()->rootContext());
if (compactRepresentation) {
compactComponent->setParent(compactRepresentation);
} else {
delete compactComponent;
}
}
if (m_compactUiObject && compactRepresentation) {
//for memory management //for memory management
component->setParent(m_compactUiObject.data()); component->setParent(m_compactUiObject.data());
//put compactRepresentation in the icon place
compactRepresentation->setProperty("parent", QVariant::fromValue(m_compactUiObject.data()));
m_compactUiObject.data()->setProperty("compactRepresentation", QVariant::fromValue(compactRepresentation));
//replace the full applet with the collapsed view //replace the full applet with the collapsed view
m_compactUiObject.data()->setProperty("visible", true); m_compactUiObject.data()->setProperty("visible", true);
m_compactUiObject.data()->setProperty("parent", QVariant::fromValue(this)); m_compactUiObject.data()->setProperty("parent", QVariant::fromValue(this));
@ -408,13 +446,19 @@ void AppletInterface::geometryChanged(const QRectF &newGeometry, const QRectF &o
m_uiObject.data()->setProperty("parent", QVariant::fromValue(m_compactUiObject.data())); m_uiObject.data()->setProperty("parent", QVariant::fromValue(m_compactUiObject.data()));
m_compactUiObject.data()->setProperty("applet", QVariant::fromValue(m_uiObject.data())); m_compactUiObject.data()->setProperty("applet", QVariant::fromValue(m_uiObject.data()));
//failed to create UI, don't do anything //failed to create UI, don't do anything, return in expanded status
} else { } else {
qWarning() << component->errors(); qWarning() << component->errors();
m_expanded = true;
delete component; delete component;
} }
emit expandedChanged();
} else { } else {
m_expanded = true;
emit expandedChanged();
//we are already expanded: nothing to do //we are already expanded: nothing to do
if (!m_compactUiObject) { if (!m_compactUiObject) {
return; return;

View File

@ -59,6 +59,7 @@ class AppletInterface : public QQuickItem
Q_PROPERTY(QString currentActivity READ currentActivity NOTIFY contextChanged) Q_PROPERTY(QString currentActivity READ currentActivity NOTIFY contextChanged)
Q_PROPERTY(QString activeConfig WRITE setActiveConfig READ activeConfig) Q_PROPERTY(QString activeConfig WRITE setActiveConfig READ activeConfig)
Q_PROPERTY(bool busy WRITE setBusy READ isBusy NOTIFY busyChanged) Q_PROPERTY(bool busy WRITE setBusy READ isBusy NOTIFY busyChanged)
Q_PROPERTY(bool expanded WRITE setExpanded READ isExpanded NOTIFY expandedChanged)
Q_PROPERTY(BackgroundHints backgroundHints WRITE setBackgroundHints READ backgroundHints NOTIFY backgroundHintsChanged) Q_PROPERTY(BackgroundHints backgroundHints WRITE setBackgroundHints READ backgroundHints NOTIFY backgroundHintsChanged)
Q_PROPERTY(bool immutable READ immutable NOTIFY immutableChanged) Q_PROPERTY(bool immutable READ immutable NOTIFY immutableChanged)
Q_PROPERTY(bool userConfiguring READ userConfiguring) // @since 4.5 Q_PROPERTY(bool userConfiguring READ userConfiguring) // @since 4.5
@ -185,6 +186,9 @@ enum IntervalAlignment {
bool isBusy() const; bool isBusy() const;
void setBusy(bool busy); void setBusy(bool busy);
bool isExpanded() const;
void setExpanded(bool expanded);
BackgroundHints backgroundHints() const; BackgroundHints backgroundHints() const;
void setBackgroundHints(BackgroundHints hint); void setBackgroundHints(BackgroundHints hint);
@ -213,6 +217,7 @@ Q_SIGNALS:
void statusChanged(); void statusChanged();
void backgroundHintsChanged(); void backgroundHintsChanged();
void busyChanged(); void busyChanged();
void expandedChanged();
protected: protected:
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
@ -232,6 +237,7 @@ private:
Plasma::BackgroundHints m_backgroundHints; Plasma::BackgroundHints m_backgroundHints;
bool m_busy : 1; bool m_busy : 1;
bool m_expanded : 1;
}; };

View File

@ -115,7 +115,6 @@ bool DeclarativeAppletScript::init()
Plasma::Containment *cont = qobject_cast<Plasma::Containment *>(a); Plasma::Containment *cont = qobject_cast<Plasma::Containment *>(a);
if (cont) { if (cont) {
m_interface = new ContainmentInterface(this); m_interface = new ContainmentInterface(this);
//fail? so it's a normal Applet //fail? so it's a normal Applet

View File

@ -22,24 +22,28 @@ import QtQuick.Window 2.0
import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.plasma.core 0.1 as PlasmaCore
import org.kde.plasma.components 0.1 as PlasmaComponents import org.kde.plasma.components 0.1 as PlasmaComponents
Rectangle { Item {
id: root id: root
color: "darkgreen"
property Item applet property Item applet
property Item compactRepresentation
onAppletChanged: applet.parent = appletParent onAppletChanged: applet.parent = appletParent
onCompactRepresentationChanged: {
compactRepresentation.parent = root
MouseArea { compactRepresentation.anchors.fill = root
anchors.fill: parent
onClicked: popupWindow.visible = !popupWindow.visible
} }
Window { Window {
id: popupWindow id: popupWindow
visible: false visible: plasmoid.expanded
onVisibleChanged: {
if (!visible) {
plasmoid.expanded = false
}
}
width: 200 width: 200
height: 200 height: 200
Item { Item {

View File

@ -0,0 +1,31 @@
/*
* Copyright 2013 Marco Martin <mart@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import QtQuick 2.0
import org.kde.plasma.core 0.1 as PlasmaCore
Rectangle {
id: root
color: "darkgreen"
MouseArea {
anchors.fill: parent
onClicked: plasmoid.expanded = !plasmoid.expanded
}
}

View File

@ -57,7 +57,7 @@ Rectangle {
height: large height: large
property alias applet: appletContainer.children property alias applet: appletContainer.children
property int small: 100 property int small: 90
property int large: root.width /2 property int large: root.width /2
imagePath: applet[0].backgroundHints == 0 ? "" : "widgets/background" imagePath: applet[0].backgroundHints == 0 ? "" : "widgets/background"
MouseArea { MouseArea {