fullrepresentation and the expander are created on demand
This commit is contained in:
parent
2a37efbdb7
commit
428c10e24c
@ -57,7 +57,6 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *pa
|
||||
m_actionSignals(0),
|
||||
m_backgroundHints(Plasma::Types::StandardBackground),
|
||||
m_busy(false),
|
||||
m_expanded(false),
|
||||
m_hideOnDeactivate(true)
|
||||
{
|
||||
qmlRegisterType<AppletInterface>();
|
||||
@ -179,23 +178,6 @@ 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 (qobject_cast<ContainmentInterface *>(this) || m_expanded == expanded) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_expanded = expanded;
|
||||
emit expandedChanged();
|
||||
}
|
||||
|
||||
Plasma::Types::BackgroundHints AppletInterface::backgroundHints() const
|
||||
{
|
||||
return m_backgroundHints;
|
||||
@ -469,15 +451,6 @@ QStringList AppletInterface::downloadedFiles() const
|
||||
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)
|
||||
{
|
||||
if (qmlObject()->rootObject()) {
|
||||
|
@ -108,12 +108,6 @@ class AppletInterface : public AppletLoader
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
@ -249,9 +243,6 @@ public:
|
||||
bool isBusy() const;
|
||||
void setBusy(bool busy);
|
||||
|
||||
bool isExpanded() const;
|
||||
void setExpanded(bool expanded);
|
||||
|
||||
Plasma::Types::BackgroundHints backgroundHints() const;
|
||||
void setBackgroundHints(Plasma::Types::BackgroundHints hint);
|
||||
|
||||
@ -294,7 +285,6 @@ Q_SIGNALS:
|
||||
void statusChanged();
|
||||
void backgroundHintsChanged();
|
||||
void busyChanged();
|
||||
void expandedChanged();
|
||||
void screenChanged();
|
||||
void hideOnWindowDeactivateChanged();
|
||||
|
||||
@ -303,9 +293,6 @@ Q_SIGNALS:
|
||||
protected Q_SLOTS:
|
||||
virtual void init();
|
||||
|
||||
private Q_SLOTS:
|
||||
void updatePopupSize();
|
||||
|
||||
private:
|
||||
|
||||
QStringList m_actions;
|
||||
@ -321,7 +308,6 @@ private:
|
||||
|
||||
Plasma::Types::BackgroundHints m_backgroundHints;
|
||||
bool m_busy : 1;
|
||||
bool m_expanded : 1;
|
||||
bool m_hideOnDeactivate : 1;
|
||||
friend class ContainmentInterface;
|
||||
};
|
||||
|
@ -44,7 +44,8 @@ AppletLoader::AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent)
|
||||
: QQuickItem(parent),
|
||||
m_switchWidth(-1),
|
||||
m_switchHeight(-1),
|
||||
m_appletScriptEngine(script)
|
||||
m_appletScriptEngine(script),
|
||||
m_expanded(false)
|
||||
{
|
||||
m_compactRepresentationCheckTimer.setSingleShot(true);
|
||||
m_compactRepresentationCheckTimer.setInterval(250);
|
||||
@ -52,16 +53,16 @@ AppletLoader::AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent)
|
||||
this, SLOT(compactRepresentationCheck()));
|
||||
m_compactRepresentationCheckTimer.start();
|
||||
|
||||
/* m_fullRepresentationResizeTimer.setSingleShot(true);
|
||||
m_fullRepresentationResizeTimer.setSingleShot(true);
|
||||
m_fullRepresentationResizeTimer.setInterval(250);
|
||||
connect (&m_fullRepresentationResizeTimer, &QTimer::timeout,
|
||||
[=]() {
|
||||
KConfigGroup cg = applet()->config();
|
||||
KConfigGroup cg = m_appletScriptEngine->applet()->config();
|
||||
cg = KConfigGroup(&cg, "PopupApplet");
|
||||
cg.writeEntry("DialogWidth", m_fullRepresentationItem.data()->property("width").toInt());
|
||||
cg.writeEntry("DialogHeight", m_fullRepresentationItem.data()->property("height").toInt());
|
||||
}
|
||||
);*/
|
||||
);
|
||||
|
||||
|
||||
|
||||
@ -71,11 +72,20 @@ AppletLoader::AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent)
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
void AppletLoader::init()
|
||||
{
|
||||
if (s_rootObjects.contains(this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
s_rootObjects[m_qmlObject->engine()] = this;
|
||||
|
||||
Q_ASSERT(m_appletScriptEngine);
|
||||
@ -111,7 +121,6 @@ void AppletLoader::init()
|
||||
appletScript()->setLaunchErrorMessage(reason);
|
||||
}
|
||||
|
||||
qWarning()<<"AAAAAAAAAAA"<<m_qmlObject->mainComponent()->errors();
|
||||
engine->rootContext()->setContextProperty("plasmoid", this);
|
||||
|
||||
//initialize size, so an useless resize less
|
||||
@ -119,7 +128,7 @@ qWarning()<<"AAAAAAAAAAA"<<m_qmlObject->mainComponent()->errors();
|
||||
initialProperties["width"] = width();
|
||||
initialProperties["height"] = height();
|
||||
m_qmlObject->completeInitialization(initialProperties);
|
||||
qWarning()<<"BBBBB";
|
||||
|
||||
|
||||
|
||||
//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")));
|
||||
}
|
||||
|
||||
//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
|
||||
if (!m_compactRepresentationExpander) {
|
||||
m_compactRepresentationExpander = new QQmlComponent(engine, this);
|
||||
@ -223,6 +226,29 @@ void AppletLoader::setPreferredRepresentation(QQmlComponent *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
|
||||
|
||||
@ -303,6 +329,10 @@ QObject *AppletLoader::createCompactRepresentationExpanderItem()
|
||||
|
||||
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());
|
||||
|
||||
return m_compactRepresentationExpanderItem.data();
|
||||
@ -480,11 +510,9 @@ void AppletLoader::compactRepresentationCheck()
|
||||
|
||||
//Icon
|
||||
} else {
|
||||
QQuickItem *fullItem = qobject_cast<QQuickItem *>(createFullRepresentationItem());
|
||||
QQuickItem *compactItem = qobject_cast<QQuickItem *>(createCompactRepresentationItem());
|
||||
QObject *compactExpanderItem = createCompactRepresentationExpanderItem();
|
||||
|
||||
if (fullItem && compactItem && compactExpanderItem) {
|
||||
if (compactItem) {
|
||||
//set the root item as the main visible item
|
||||
compactItem->setParentItem(this);
|
||||
compactItem->setVisible(true);
|
||||
@ -495,8 +523,15 @@ void AppletLoader::compactRepresentationCheck()
|
||||
prop.write(expr.evaluate());
|
||||
}
|
||||
|
||||
compactExpanderItem->setProperty("compactRepresentation", QVariant::fromValue(compactItem));
|
||||
compactExpanderItem->setProperty("fullRepresentation", QVariant::fromValue(fullItem));
|
||||
if (m_fullRepresentationItem) {
|
||||
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;
|
||||
connectLayoutAttached(compactItem);
|
||||
}
|
||||
|
@ -61,6 +61,12 @@ class AppletLoader : public QQuickItem
|
||||
//FIXME: is it wise to expose this?
|
||||
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:
|
||||
AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent = 0);
|
||||
~AppletLoader();
|
||||
@ -105,6 +111,9 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
bool isExpanded() const;
|
||||
void setExpanded(bool expanded);
|
||||
|
||||
Q_SIGNALS:
|
||||
void switchWidthChanged(int width);
|
||||
void switchHeightChanged(int height);
|
||||
@ -119,6 +128,8 @@ Q_SIGNALS:
|
||||
void fullRepresentationItemChanged(QObject *fullRepresentationItem);
|
||||
void compactRepresentationExpanderItemChanged(QObject *compactRepresentationExpanderItem);
|
||||
|
||||
void expandedChanged();
|
||||
|
||||
protected:
|
||||
KDeclarative::QmlObject *qmlObject();
|
||||
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
|
||||
@ -169,6 +180,8 @@ private:
|
||||
DeclarativeAppletScript *m_appletScriptEngine;
|
||||
KDeclarative::QmlObject *m_qmlObject;
|
||||
|
||||
bool m_expanded : 1;
|
||||
|
||||
static QHash<QObject *, AppletLoader *> s_rootObjects;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user