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_actionSignals(0),
m_backgroundHints(Plasma::StandardBackground),
m_busy(false)
m_busy(false),
m_expanded(false)
{
qmlRegisterType<AppletInterface>();
connect(this, SIGNAL(releaseVisualFocus()), applet(), SIGNAL(releaseVisualFocus()));
@ -120,6 +121,23 @@ void AppletInterface::setBusy(bool busy)
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
{
return (BackgroundHints)m_backgroundHints;
@ -377,13 +395,15 @@ void AppletInterface::geometryChanged(const QRectF &newGeometry, const QRectF &o
Q_UNUSED(oldGeometry)
QQuickItem::geometryChanged(newGeometry, oldGeometry);
if (!m_uiObject || qobject_cast<ContainmentInterface *>(this)) {
return;
}
//TODO: completely arbitrary for now
if (newGeometry.width() < 100 || newGeometry.height() < 100) {
m_expanded = false;
//we are already an icon: nothing to do
if (m_compactUiObject) {
return;
@ -391,12 +411,30 @@ void AppletInterface::geometryChanged(const QRectF &newGeometry, const QRectF &o
QQmlComponent *component = new QQmlComponent(m_appletScriptEngine->engine(), this);
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) {
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
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
m_compactUiObject.data()->setProperty("visible", true);
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_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 {
qWarning() << component->errors();
m_expanded = true;
delete component;
}
emit expandedChanged();
} else {
m_expanded = true;
emit expandedChanged();
//we are already expanded: nothing to do
if (!m_compactUiObject) {
return;

View File

@ -59,6 +59,7 @@ class AppletInterface : public QQuickItem
Q_PROPERTY(QString currentActivity READ currentActivity NOTIFY contextChanged)
Q_PROPERTY(QString activeConfig WRITE setActiveConfig READ activeConfig)
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(bool immutable READ immutable NOTIFY immutableChanged)
Q_PROPERTY(bool userConfiguring READ userConfiguring) // @since 4.5
@ -185,6 +186,9 @@ enum IntervalAlignment {
bool isBusy() const;
void setBusy(bool busy);
bool isExpanded() const;
void setExpanded(bool expanded);
BackgroundHints backgroundHints() const;
void setBackgroundHints(BackgroundHints hint);
@ -213,6 +217,7 @@ Q_SIGNALS:
void statusChanged();
void backgroundHintsChanged();
void busyChanged();
void expandedChanged();
protected:
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
@ -232,6 +237,7 @@ private:
Plasma::BackgroundHints m_backgroundHints;
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);
if (cont) {
m_interface = new ContainmentInterface(this);
//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.components 0.1 as PlasmaComponents
Rectangle {
Item {
id: root
color: "darkgreen"
property Item applet
property Item compactRepresentation
onAppletChanged: applet.parent = appletParent
MouseArea {
anchors.fill: parent
onClicked: popupWindow.visible = !popupWindow.visible
onCompactRepresentationChanged: {
compactRepresentation.parent = root
compactRepresentation.anchors.fill = root
}
Window {
id: popupWindow
visible: false
visible: plasmoid.expanded
onVisibleChanged: {
if (!visible) {
plasmoid.expanded = false
}
}
width: 200
height: 200
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
property alias applet: appletContainer.children
property int small: 100
property int small: 90
property int large: root.width /2
imagePath: applet[0].backgroundHints == 0 ? "" : "widgets/background"
MouseArea {