fullrepresentation and the expander are created on demand

This commit is contained in:
Marco Martin 2014-01-29 17:09:43 +01:00
parent 2a37efbdb7
commit 428c10e24c
4 changed files with 65 additions and 58 deletions

View File

@ -57,7 +57,6 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *pa
m_actionSignals(0), m_actionSignals(0),
m_backgroundHints(Plasma::Types::StandardBackground), m_backgroundHints(Plasma::Types::StandardBackground),
m_busy(false), m_busy(false),
m_expanded(false),
m_hideOnDeactivate(true) m_hideOnDeactivate(true)
{ {
qmlRegisterType<AppletInterface>(); qmlRegisterType<AppletInterface>();
@ -179,23 +178,6 @@ 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 (qobject_cast<ContainmentInterface *>(this) || m_expanded == expanded) {
return;
}
m_expanded = expanded;
emit expandedChanged();
}
Plasma::Types::BackgroundHints AppletInterface::backgroundHints() const Plasma::Types::BackgroundHints AppletInterface::backgroundHints() const
{ {
return m_backgroundHints; return m_backgroundHints;
@ -469,15 +451,6 @@ QStringList AppletInterface::downloadedFiles() const
return dir.entryList(QDir::Files | QDir::NoSymLinks | QDir::Readable); return dir.entryList(QDir::Files | QDir::NoSymLinks | QDir::Readable);
} }
void AppletInterface::updatePopupSize()
{
KConfigGroup cg = applet()->config();
cg = KConfigGroup(&cg, "PopupApplet");
cg.writeEntry("DialogWidth", qmlObject()->rootObject()->property("width").toInt());
cg.writeEntry("DialogHeight", qmlObject()->rootObject()->property("height").toInt());
}
void AppletInterface::executeAction(const QString &name) void AppletInterface::executeAction(const QString &name)
{ {
if (qmlObject()->rootObject()) { if (qmlObject()->rootObject()) {

View File

@ -108,12 +108,6 @@ class AppletInterface : public AppletLoader
*/ */
Q_PROPERTY(bool busy WRITE setBusy READ isBusy NOTIFY busyChanged) Q_PROPERTY(bool busy WRITE setBusy READ isBusy NOTIFY busyChanged)
/**
* True when the applet is showing its full representation. either as the main only view, or in a popup.
* Setting it will open or close the popup if the plasmoid is iconified, however it won't have effect if the applet is open
*/
Q_PROPERTY(bool expanded WRITE setExpanded READ isExpanded NOTIFY expandedChanged)
/** /**
* How the applet wants its background to be drawn. The containment may chose to ignore this hint. * How the applet wants its background to be drawn. The containment may chose to ignore this hint.
*/ */
@ -249,9 +243,6 @@ public:
bool isBusy() const; bool isBusy() const;
void setBusy(bool busy); void setBusy(bool busy);
bool isExpanded() const;
void setExpanded(bool expanded);
Plasma::Types::BackgroundHints backgroundHints() const; Plasma::Types::BackgroundHints backgroundHints() const;
void setBackgroundHints(Plasma::Types::BackgroundHints hint); void setBackgroundHints(Plasma::Types::BackgroundHints hint);
@ -294,7 +285,6 @@ Q_SIGNALS:
void statusChanged(); void statusChanged();
void backgroundHintsChanged(); void backgroundHintsChanged();
void busyChanged(); void busyChanged();
void expandedChanged();
void screenChanged(); void screenChanged();
void hideOnWindowDeactivateChanged(); void hideOnWindowDeactivateChanged();
@ -303,9 +293,6 @@ Q_SIGNALS:
protected Q_SLOTS: protected Q_SLOTS:
virtual void init(); virtual void init();
private Q_SLOTS:
void updatePopupSize();
private: private:
QStringList m_actions; QStringList m_actions;
@ -321,7 +308,6 @@ private:
Plasma::Types::BackgroundHints m_backgroundHints; Plasma::Types::BackgroundHints m_backgroundHints;
bool m_busy : 1; bool m_busy : 1;
bool m_expanded : 1;
bool m_hideOnDeactivate : 1; bool m_hideOnDeactivate : 1;
friend class ContainmentInterface; friend class ContainmentInterface;
}; };

View File

@ -44,7 +44,8 @@ AppletLoader::AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent)
: QQuickItem(parent), : QQuickItem(parent),
m_switchWidth(-1), m_switchWidth(-1),
m_switchHeight(-1), m_switchHeight(-1),
m_appletScriptEngine(script) m_appletScriptEngine(script),
m_expanded(false)
{ {
m_compactRepresentationCheckTimer.setSingleShot(true); m_compactRepresentationCheckTimer.setSingleShot(true);
m_compactRepresentationCheckTimer.setInterval(250); m_compactRepresentationCheckTimer.setInterval(250);
@ -52,16 +53,16 @@ AppletLoader::AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent)
this, SLOT(compactRepresentationCheck())); this, SLOT(compactRepresentationCheck()));
m_compactRepresentationCheckTimer.start(); m_compactRepresentationCheckTimer.start();
/* m_fullRepresentationResizeTimer.setSingleShot(true); m_fullRepresentationResizeTimer.setSingleShot(true);
m_fullRepresentationResizeTimer.setInterval(250); m_fullRepresentationResizeTimer.setInterval(250);
connect (&m_fullRepresentationResizeTimer, &QTimer::timeout, connect (&m_fullRepresentationResizeTimer, &QTimer::timeout,
[=]() { [=]() {
KConfigGroup cg = applet()->config(); KConfigGroup cg = m_appletScriptEngine->applet()->config();
cg = KConfigGroup(&cg, "PopupApplet"); cg = KConfigGroup(&cg, "PopupApplet");
cg.writeEntry("DialogWidth", m_fullRepresentationItem.data()->property("width").toInt()); cg.writeEntry("DialogWidth", m_fullRepresentationItem.data()->property("width").toInt());
cg.writeEntry("DialogHeight", m_fullRepresentationItem.data()->property("height").toInt()); cg.writeEntry("DialogHeight", m_fullRepresentationItem.data()->property("height").toInt());
} }
);*/ );
@ -71,11 +72,20 @@ AppletLoader::AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent)
AppletLoader::~AppletLoader() AppletLoader::~AppletLoader()
{ {
//Here the order is important
delete m_compactRepresentationItem.data();
delete m_fullRepresentationItem.data();
delete m_compactRepresentationExpanderItem.data();
s_rootObjects.remove(m_qmlObject->engine()); s_rootObjects.remove(m_qmlObject->engine());
} }
void AppletLoader::init() void AppletLoader::init()
{ {
if (s_rootObjects.contains(this)) {
return;
}
s_rootObjects[m_qmlObject->engine()] = this; s_rootObjects[m_qmlObject->engine()] = this;
Q_ASSERT(m_appletScriptEngine); Q_ASSERT(m_appletScriptEngine);
@ -111,7 +121,6 @@ void AppletLoader::init()
appletScript()->setLaunchErrorMessage(reason); appletScript()->setLaunchErrorMessage(reason);
} }
qWarning()<<"AAAAAAAAAAA"<<m_qmlObject->mainComponent()->errors();
engine->rootContext()->setContextProperty("plasmoid", this); engine->rootContext()->setContextProperty("plasmoid", this);
//initialize size, so an useless resize less //initialize size, so an useless resize less
@ -119,7 +128,7 @@ qWarning()<<"AAAAAAAAAAA"<<m_qmlObject->mainComponent()->errors();
initialProperties["width"] = width(); initialProperties["width"] = width();
initialProperties["height"] = height(); initialProperties["height"] = height();
m_qmlObject->completeInitialization(initialProperties); m_qmlObject->completeInitialization(initialProperties);
qWarning()<<"BBBBB";
//default m_compactRepresentation is a simple icon provided by the shell package //default m_compactRepresentation is a simple icon provided by the shell package
@ -128,12 +137,6 @@ qWarning()<<"BBBBB";
m_compactRepresentation.data()->loadUrl(QUrl::fromLocalFile(m_appletScriptEngine->applet()->containment()->corona()->package().filePath("defaultcompactrepresentation"))); m_compactRepresentation.data()->loadUrl(QUrl::fromLocalFile(m_appletScriptEngine->applet()->containment()->corona()->package().filePath("defaultcompactrepresentation")));
} }
//we really want a full representation, default m_fullRepresentation is an error message
/* if (!m_fullRepresentation) {
m_fullRepresentation = new QQmlComponent(m_qmlObject->engine(), this);
m_fullRepresentation.data()->loadUrl(QUrl::fromLocalFile(m_appletScriptEngine->applet()->containment()->corona()->package().filePath("appleterror")));
}*/
//default m_compactRepresentationExpander is the popup in which fullRepresentation goes //default m_compactRepresentationExpander is the popup in which fullRepresentation goes
if (!m_compactRepresentationExpander) { if (!m_compactRepresentationExpander) {
m_compactRepresentationExpander = new QQmlComponent(engine, this); m_compactRepresentationExpander = new QQmlComponent(engine, this);
@ -223,6 +226,29 @@ void AppletLoader::setPreferredRepresentation(QQmlComponent *component)
emit preferredRepresentationChanged(component); emit preferredRepresentationChanged(component);
} }
bool AppletLoader::isExpanded() const
{
return m_expanded;
}
void AppletLoader::setExpanded(bool expanded)
{
if (m_appletScriptEngine->applet()->isContainment()) {
expanded = true;
}
//if there is no compact representation it means it's always expanded
//Containnments are always expanded
if (m_expanded == expanded) {
return;
}
createFullRepresentationItem();
createCompactRepresentationExpanderItem();
m_expanded = expanded;
emit expandedChanged();
}
////////////Internals ////////////Internals
@ -303,6 +329,10 @@ QObject *AppletLoader::createCompactRepresentationExpanderItem()
m_compactRepresentationExpanderItem = m_qmlObject->createObjectFromComponent(m_compactRepresentationExpander.data(), QtQml::qmlContext(m_qmlObject->rootObject())); m_compactRepresentationExpanderItem = m_qmlObject->createObjectFromComponent(m_compactRepresentationExpander.data(), QtQml::qmlContext(m_qmlObject->rootObject()));
m_compactRepresentationExpanderItem.data()->setProperty("compactRepresentation", QVariant::fromValue(createCompactRepresentationItem()));
m_compactRepresentationExpanderItem.data()->setProperty("fullRepresentation", QVariant::fromValue(createFullRepresentationItem()));
emit compactRepresentationExpanderItemChanged(m_compactRepresentationExpanderItem.data()); emit compactRepresentationExpanderItemChanged(m_compactRepresentationExpanderItem.data());
return m_compactRepresentationExpanderItem.data(); return m_compactRepresentationExpanderItem.data();
@ -480,11 +510,9 @@ void AppletLoader::compactRepresentationCheck()
//Icon //Icon
} else { } else {
QQuickItem *fullItem = qobject_cast<QQuickItem *>(createFullRepresentationItem());
QQuickItem *compactItem = qobject_cast<QQuickItem *>(createCompactRepresentationItem()); QQuickItem *compactItem = qobject_cast<QQuickItem *>(createCompactRepresentationItem());
QObject *compactExpanderItem = createCompactRepresentationExpanderItem();
if (fullItem && compactItem && compactExpanderItem) { if (compactItem) {
//set the root item as the main visible item //set the root item as the main visible item
compactItem->setParentItem(this); compactItem->setParentItem(this);
compactItem->setVisible(true); compactItem->setVisible(true);
@ -495,8 +523,15 @@ void AppletLoader::compactRepresentationCheck()
prop.write(expr.evaluate()); prop.write(expr.evaluate());
} }
compactExpanderItem->setProperty("compactRepresentation", QVariant::fromValue(compactItem)); if (m_fullRepresentationItem) {
compactExpanderItem->setProperty("fullRepresentation", QVariant::fromValue(fullItem)); m_fullRepresentationItem.data()->setProperty("parent", QVariant());
}
if (m_compactRepresentationExpanderItem) {
m_compactRepresentationExpanderItem.data()->setProperty("compactRepresentation", QVariant::fromValue(compactItem));
m_compactRepresentationExpanderItem.data()->setProperty("fullRepresentation", QVariant::fromValue(createFullRepresentationItem()));
}
m_currentRepresentationItem = compactItem; m_currentRepresentationItem = compactItem;
connectLayoutAttached(compactItem); connectLayoutAttached(compactItem);
} }

View File

@ -61,6 +61,12 @@ class AppletLoader : public QQuickItem
//FIXME: is it wise to expose this? //FIXME: is it wise to expose this?
Q_PROPERTY(QQmlComponent *compactRepresentation READ compactRepresentation WRITE setCompactRepresentation NOTIFY compactRepresentationChanged) Q_PROPERTY(QQmlComponent *compactRepresentation READ compactRepresentation WRITE setCompactRepresentation NOTIFY compactRepresentationChanged)
/**
* True when the applet is showing its full representation. either as the main only view, or in a popup.
* Setting it will open or close the popup if the plasmoid is iconified, however it won't have effect if the applet is open
*/
Q_PROPERTY(bool expanded WRITE setExpanded READ isExpanded NOTIFY expandedChanged)
public: public:
AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent = 0); AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent = 0);
~AppletLoader(); ~AppletLoader();
@ -105,6 +111,9 @@ public:
} }
} }
bool isExpanded() const;
void setExpanded(bool expanded);
Q_SIGNALS: Q_SIGNALS:
void switchWidthChanged(int width); void switchWidthChanged(int width);
void switchHeightChanged(int height); void switchHeightChanged(int height);
@ -119,6 +128,8 @@ Q_SIGNALS:
void fullRepresentationItemChanged(QObject *fullRepresentationItem); void fullRepresentationItemChanged(QObject *fullRepresentationItem);
void compactRepresentationExpanderItemChanged(QObject *compactRepresentationExpanderItem); void compactRepresentationExpanderItemChanged(QObject *compactRepresentationExpanderItem);
void expandedChanged();
protected: protected:
KDeclarative::QmlObject *qmlObject(); KDeclarative::QmlObject *qmlObject();
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
@ -169,6 +180,8 @@ private:
DeclarativeAppletScript *m_appletScriptEngine; DeclarativeAppletScript *m_appletScriptEngine;
KDeclarative::QmlObject *m_qmlObject; KDeclarative::QmlObject *m_qmlObject;
bool m_expanded : 1;
static QHash<QObject *, AppletLoader *> s_rootObjects; static QHash<QObject *, AppletLoader *> s_rootObjects;
}; };