move private members in AppletQuickItemPrivate
This commit is contained in:
parent
c196f8b748
commit
7e53c7276a
@ -37,100 +37,109 @@
|
|||||||
|
|
||||||
#include <packageurlinterceptor.h>
|
#include <packageurlinterceptor.h>
|
||||||
|
|
||||||
QHash<QObject *, AppletQuickItem *> AppletQuickItem::s_rootObjects = QHash<QObject *, AppletQuickItem *>();
|
QHash<QObject *, AppletQuickItem *> AppletQuickItemPrivate::s_rootObjects = QHash<QObject *, AppletQuickItem *>();
|
||||||
|
|
||||||
|
AppletQuickItemPrivate::AppletQuickItemPrivate(Plasma::Applet *a)
|
||||||
|
: switchWidth(-1),
|
||||||
|
switchHeight(-1),
|
||||||
|
applet(a),
|
||||||
|
expanded(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AppletQuickItem::AppletQuickItem(Plasma::Applet *applet, QQuickItem *parent)
|
AppletQuickItem::AppletQuickItem(Plasma::Applet *applet, QQuickItem *parent)
|
||||||
: QQuickItem(parent),
|
: QQuickItem(parent),
|
||||||
m_switchWidth(-1),
|
d(new AppletQuickItemPrivate(applet))
|
||||||
m_switchHeight(-1),
|
|
||||||
m_applet(applet),
|
|
||||||
m_expanded(false)
|
|
||||||
{
|
{
|
||||||
m_appletPackage = m_applet->package();
|
if (d->applet) {
|
||||||
if (m_applet && m_applet->containment() && m_applet->containment()->corona()) {
|
d->appletPackage = d->applet->package();
|
||||||
m_coronaPackage = m_applet->containment()->corona()->package();
|
}
|
||||||
|
if (d->applet && d->applet->containment() && d->applet->containment()->corona()) {
|
||||||
|
d->coronaPackage = d->applet->containment()->corona()->package();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_compactRepresentationCheckTimer.setSingleShot(true);
|
d->compactRepresentationCheckTimer.setSingleShot(true);
|
||||||
m_compactRepresentationCheckTimer.setInterval(250);
|
d->compactRepresentationCheckTimer.setInterval(250);
|
||||||
connect (&m_compactRepresentationCheckTimer, SIGNAL(timeout()),
|
connect (&d->compactRepresentationCheckTimer, SIGNAL(timeout()),
|
||||||
this, SLOT(compactRepresentationCheck()));
|
this, SLOT(compactRepresentationCheck()));
|
||||||
m_compactRepresentationCheckTimer.start();
|
d->compactRepresentationCheckTimer.start();
|
||||||
|
|
||||||
m_fullRepresentationResizeTimer.setSingleShot(true);
|
d->fullRepresentationResizeTimer.setSingleShot(true);
|
||||||
m_fullRepresentationResizeTimer.setInterval(250);
|
d->fullRepresentationResizeTimer.setInterval(250);
|
||||||
connect (&m_fullRepresentationResizeTimer, &QTimer::timeout,
|
connect (&d->fullRepresentationResizeTimer, &QTimer::timeout,
|
||||||
[=]() {
|
[=]() {
|
||||||
KConfigGroup cg = m_applet->config();
|
KConfigGroup cg = d->applet->config();
|
||||||
cg = KConfigGroup(&cg, "PopupApplet");
|
cg = KConfigGroup(&cg, "PopupApplet");
|
||||||
cg.writeEntry("DialogWidth", m_fullRepresentationItem.data()->property("width").toInt());
|
cg.writeEntry("DialogWidth", d->fullRepresentationItem.data()->property("width").toInt());
|
||||||
cg.writeEntry("DialogHeight", m_fullRepresentationItem.data()->property("height").toInt());
|
cg.writeEntry("DialogHeight", d->fullRepresentationItem.data()->property("height").toInt());
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
m_qmlObject = new KDeclarative::QmlObject(this);
|
d->qmlObject = new KDeclarative::QmlObject(this);
|
||||||
m_qmlObject->setInitializationDelayed(true);
|
d->qmlObject->setInitializationDelayed(true);
|
||||||
|
|
||||||
// set the graphicObject dynamic property on applet
|
// set the graphicObject dynamic property on applet
|
||||||
m_applet->setProperty("_plasma_graphicObject", QVariant::fromValue(this));
|
d->applet->setProperty("_plasma_graphicObject", QVariant::fromValue(this));
|
||||||
setProperty("_plasma_applet", QVariant::fromValue(applet));
|
setProperty("_plasma_applet", QVariant::fromValue(applet));
|
||||||
}
|
}
|
||||||
|
|
||||||
AppletQuickItem::~AppletQuickItem()
|
AppletQuickItem::~AppletQuickItem()
|
||||||
{
|
{
|
||||||
//Here the order is important
|
//Here the order is important
|
||||||
delete m_compactRepresentationItem.data();
|
delete d->compactRepresentationItem.data();
|
||||||
delete m_fullRepresentationItem.data();
|
delete d->fullRepresentationItem.data();
|
||||||
delete m_compactRepresentationExpanderItem.data();
|
delete d->compactRepresentationExpanderItem.data();
|
||||||
|
|
||||||
s_rootObjects.remove(m_qmlObject->engine());
|
AppletQuickItemPrivate::s_rootObjects.remove(d->qmlObject->engine());
|
||||||
}
|
}
|
||||||
|
|
||||||
Plasma::Applet *AppletQuickItem::applet() const
|
Plasma::Applet *AppletQuickItem::applet() const
|
||||||
{
|
{
|
||||||
return m_applet;
|
return d->applet;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppletQuickItem::init()
|
void AppletQuickItem::init()
|
||||||
{
|
{
|
||||||
if (s_rootObjects.contains(this)) {
|
if (AppletQuickItemPrivate::s_rootObjects.contains(this)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
s_rootObjects[m_qmlObject->engine()] = this;
|
AppletQuickItemPrivate::s_rootObjects[d->qmlObject->engine()] = this;
|
||||||
|
|
||||||
Q_ASSERT(m_applet);
|
Q_ASSERT(d->applet);
|
||||||
|
|
||||||
//Initialize the main QML file
|
//Initialize the main QML file
|
||||||
QQmlEngine *engine = m_qmlObject->engine();
|
QQmlEngine *engine = d->qmlObject->engine();
|
||||||
|
|
||||||
PackageUrlInterceptor *interceptor = new PackageUrlInterceptor(engine, m_applet->package());
|
PackageUrlInterceptor *interceptor = new PackageUrlInterceptor(engine, d->applet->package());
|
||||||
interceptor->addAllowedPath(m_coronaPackage.path());
|
interceptor->addAllowedPath(d->coronaPackage.path());
|
||||||
engine->setUrlInterceptor(interceptor);
|
engine->setUrlInterceptor(interceptor);
|
||||||
|
|
||||||
m_qmlObject->setSource(QUrl::fromLocalFile(m_applet->package().filePath("mainscript")));
|
d->qmlObject->setSource(QUrl::fromLocalFile(d->applet->package().filePath("mainscript")));
|
||||||
|
|
||||||
if (!engine || !engine->rootContext() || !engine->rootContext()->isValid() || m_qmlObject->mainComponent()->isError()) {
|
if (!engine || !engine->rootContext() || !engine->rootContext()->isValid() || d->qmlObject->mainComponent()->isError()) {
|
||||||
QString reason;
|
QString reason;
|
||||||
foreach (QQmlError error, m_qmlObject->mainComponent()->errors()) {
|
foreach (QQmlError error, d->qmlObject->mainComponent()->errors()) {
|
||||||
reason += error.toString()+'\n';
|
reason += error.toString()+'\n';
|
||||||
}
|
}
|
||||||
reason = i18n("Error loading QML file: %1", reason);
|
reason = i18n("Error loading QML file: %1", reason);
|
||||||
|
|
||||||
m_qmlObject->setSource(QUrl::fromLocalFile(m_coronaPackage.filePath("appleterror")));
|
d->qmlObject->setSource(QUrl::fromLocalFile(d->coronaPackage.filePath("appleterror")));
|
||||||
m_qmlObject->completeInitialization();
|
d->qmlObject->completeInitialization();
|
||||||
|
|
||||||
|
|
||||||
//even the error message QML may fail
|
//even the error message QML may fail
|
||||||
if (m_qmlObject->mainComponent()->isError()) {
|
if (d->qmlObject->mainComponent()->isError()) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
m_qmlObject->rootObject()->setProperty("reason", reason);
|
d->qmlObject->rootObject()->setProperty("reason", reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_applet->setLaunchErrorMessage(reason);
|
d->applet->setLaunchErrorMessage(reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
engine->rootContext()->setContextProperty("plasmoid", this);
|
engine->rootContext()->setContextProperty("plasmoid", this);
|
||||||
@ -139,148 +148,148 @@ void AppletQuickItem::init()
|
|||||||
QVariantHash initialProperties;
|
QVariantHash initialProperties;
|
||||||
initialProperties["width"] = width();
|
initialProperties["width"] = width();
|
||||||
initialProperties["height"] = height();
|
initialProperties["height"] = height();
|
||||||
m_qmlObject->completeInitialization(initialProperties);
|
d->qmlObject->completeInitialization(initialProperties);
|
||||||
|
|
||||||
//default fullrepresentation is our root main component, if none specified
|
//default fullrepresentation is our root main component, if none specified
|
||||||
if (!m_fullRepresentation) {
|
if (!d->fullRepresentation) {
|
||||||
m_fullRepresentation = m_qmlObject->mainComponent();
|
d->fullRepresentation = d->qmlObject->mainComponent();
|
||||||
m_fullRepresentationItem = m_qmlObject->rootObject();
|
d->fullRepresentationItem = d->qmlObject->rootObject();
|
||||||
emit fullRepresentationChanged(m_fullRepresentation.data());
|
emit fullRepresentationChanged(d->fullRepresentation.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
//default m_compactRepresentation is a simple icon provided by the shell package
|
//default d->compactRepresentation is a simple icon provided by the shell package
|
||||||
if (!m_compactRepresentation) {
|
if (!d->compactRepresentation) {
|
||||||
m_compactRepresentation = new QQmlComponent(engine, this);
|
d->compactRepresentation = new QQmlComponent(engine, this);
|
||||||
m_compactRepresentation.data()->loadUrl(QUrl::fromLocalFile(m_coronaPackage.filePath("defaultcompactrepresentation")));
|
d->compactRepresentation.data()->loadUrl(QUrl::fromLocalFile(d->coronaPackage.filePath("defaultcompactrepresentation")));
|
||||||
emit compactRepresentationChanged(m_compactRepresentation.data());
|
emit compactRepresentationChanged(d->compactRepresentation.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
//default m_compactRepresentationExpander is the popup in which fullRepresentation goes
|
//default d->compactRepresentationExpander is the popup in which fullRepresentation goes
|
||||||
if (!m_compactRepresentationExpander) {
|
if (!d->compactRepresentationExpander) {
|
||||||
m_compactRepresentationExpander = new QQmlComponent(engine, this);
|
d->compactRepresentationExpander = new QQmlComponent(engine, this);
|
||||||
m_compactRepresentationExpander.data()->loadUrl(QUrl::fromLocalFile(m_coronaPackage.filePath("compactapplet")));
|
d->compactRepresentationExpander.data()->loadUrl(QUrl::fromLocalFile(d->coronaPackage.filePath("compactapplet")));
|
||||||
emit compactRepresentationExpanderItemChanged(m_compactRepresentationExpander.data());
|
emit compactRepresentationExpanderItemChanged(d->compactRepresentationExpander.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Plasma::Package AppletQuickItem::appletPackage() const
|
Plasma::Package AppletQuickItem::appletPackage() const
|
||||||
{
|
{
|
||||||
return m_appletPackage;
|
return d->appletPackage;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppletQuickItem::setAppletPackage(const Plasma::Package &package)
|
void AppletQuickItem::setAppletPackage(const Plasma::Package &package)
|
||||||
{
|
{
|
||||||
m_appletPackage = package;
|
d->appletPackage = package;
|
||||||
}
|
}
|
||||||
|
|
||||||
Plasma::Package AppletQuickItem::coronaPackage() const
|
Plasma::Package AppletQuickItem::coronaPackage() const
|
||||||
{
|
{
|
||||||
return m_coronaPackage;
|
return d->coronaPackage;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppletQuickItem::setCoronaPackage(const Plasma::Package &package)
|
void AppletQuickItem::setCoronaPackage(const Plasma::Package &package)
|
||||||
{
|
{
|
||||||
m_coronaPackage = package;
|
d->coronaPackage = package;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AppletQuickItem::switchWidth() const
|
int AppletQuickItem::switchWidth() const
|
||||||
{
|
{
|
||||||
return m_switchWidth;
|
return d->switchWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppletQuickItem::setSwitchWidth(int width)
|
void AppletQuickItem::setSwitchWidth(int width)
|
||||||
{
|
{
|
||||||
if (m_switchWidth == width) {
|
if (d->switchWidth == width) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_switchWidth = width;
|
d->switchWidth = width;
|
||||||
emit switchWidthChanged(width);
|
emit switchWidthChanged(width);
|
||||||
}
|
}
|
||||||
|
|
||||||
int AppletQuickItem::switchHeight() const
|
int AppletQuickItem::switchHeight() const
|
||||||
{
|
{
|
||||||
return m_switchHeight;
|
return d->switchHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppletQuickItem::setSwitchHeight(int width)
|
void AppletQuickItem::setSwitchHeight(int width)
|
||||||
{
|
{
|
||||||
if (m_switchHeight == width) {
|
if (d->switchHeight == width) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_switchHeight = width;
|
d->switchHeight = width;
|
||||||
emit switchHeightChanged(width);
|
emit switchHeightChanged(width);
|
||||||
}
|
}
|
||||||
|
|
||||||
QQmlComponent *AppletQuickItem::compactRepresentation()
|
QQmlComponent *AppletQuickItem::compactRepresentation()
|
||||||
{
|
{
|
||||||
return m_compactRepresentation.data();
|
return d->compactRepresentation.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppletQuickItem::setCompactRepresentation(QQmlComponent *component)
|
void AppletQuickItem::setCompactRepresentation(QQmlComponent *component)
|
||||||
{
|
{
|
||||||
if (m_compactRepresentation.data() == component) {
|
if (d->compactRepresentation.data() == component) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_compactRepresentation = component;
|
d->compactRepresentation = component;
|
||||||
emit compactRepresentationChanged(component);
|
emit compactRepresentationChanged(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QQmlComponent *AppletQuickItem::fullRepresentation()
|
QQmlComponent *AppletQuickItem::fullRepresentation()
|
||||||
{
|
{
|
||||||
return m_fullRepresentation.data();
|
return d->fullRepresentation.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppletQuickItem::setFullRepresentation(QQmlComponent *component)
|
void AppletQuickItem::setFullRepresentation(QQmlComponent *component)
|
||||||
{
|
{
|
||||||
if (m_fullRepresentation.data() == component) {
|
if (d->fullRepresentation.data() == component) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_fullRepresentation = component;
|
d->fullRepresentation = component;
|
||||||
emit fullRepresentationChanged(component);
|
emit fullRepresentationChanged(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
QQmlComponent *AppletQuickItem::preferredRepresentation()
|
QQmlComponent *AppletQuickItem::preferredRepresentation()
|
||||||
{
|
{
|
||||||
return m_preferredRepresentation.data();
|
return d->preferredRepresentation.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppletQuickItem::setPreferredRepresentation(QQmlComponent *component)
|
void AppletQuickItem::setPreferredRepresentation(QQmlComponent *component)
|
||||||
{
|
{
|
||||||
if (m_preferredRepresentation.data() == component) {
|
if (d->preferredRepresentation.data() == component) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_preferredRepresentation = component;
|
d->preferredRepresentation = component;
|
||||||
emit preferredRepresentationChanged(component);
|
emit preferredRepresentationChanged(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AppletQuickItem::isExpanded() const
|
bool AppletQuickItem::isExpanded() const
|
||||||
{
|
{
|
||||||
return m_expanded;
|
return d->expanded;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppletQuickItem::setExpanded(bool expanded)
|
void AppletQuickItem::setExpanded(bool expanded)
|
||||||
{
|
{
|
||||||
if (m_applet->isContainment()) {
|
if (d->applet->isContainment()) {
|
||||||
expanded = true;
|
expanded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if there is no compact representation it means it's always expanded
|
//if there is no compact representation it means it's always expanded
|
||||||
//Containnments are always expanded
|
//Containnments are always expanded
|
||||||
if (m_expanded == expanded) {
|
if (d->expanded == expanded) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
createFullRepresentationItem();
|
createFullRepresentationItem();
|
||||||
createCompactRepresentationExpanderItem();
|
createCompactRepresentationExpanderItem();
|
||||||
|
|
||||||
m_expanded = expanded;
|
d->expanded = expanded;
|
||||||
emit expandedChanged(expanded);
|
emit expandedChanged(expanded);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,89 +298,89 @@ void AppletQuickItem::setExpanded(bool expanded)
|
|||||||
|
|
||||||
KDeclarative::QmlObject *AppletQuickItem::qmlObject()
|
KDeclarative::QmlObject *AppletQuickItem::qmlObject()
|
||||||
{
|
{
|
||||||
return m_qmlObject;
|
return d->qmlObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject *AppletQuickItem::compactRepresentationItem()
|
QObject *AppletQuickItem::compactRepresentationItem()
|
||||||
{
|
{
|
||||||
return m_compactRepresentationItem.data();
|
return d->compactRepresentationItem.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject *AppletQuickItem::fullRepresentationItem()
|
QObject *AppletQuickItem::fullRepresentationItem()
|
||||||
{
|
{
|
||||||
return m_fullRepresentationItem.data();
|
return d->fullRepresentationItem.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject *AppletQuickItem::compactRepresentationExpanderItem()
|
QObject *AppletQuickItem::compactRepresentationExpanderItem()
|
||||||
{
|
{
|
||||||
return m_compactRepresentationExpanderItem.data();
|
return d->compactRepresentationExpanderItem.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QObject *AppletQuickItem::createCompactRepresentationItem()
|
QObject *AppletQuickItem::createCompactRepresentationItem()
|
||||||
{
|
{
|
||||||
if (!m_compactRepresentation) {
|
if (!d->compactRepresentation) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_compactRepresentationItem) {
|
if (d->compactRepresentationItem) {
|
||||||
return m_compactRepresentationItem.data();
|
return d->compactRepresentationItem.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_compactRepresentationItem = m_qmlObject->createObjectFromComponent(m_compactRepresentation.data(), QtQml::qmlContext(m_qmlObject->rootObject()));
|
d->compactRepresentationItem = d->qmlObject->createObjectFromComponent(d->compactRepresentation.data(), QtQml::qmlContext(d->qmlObject->rootObject()));
|
||||||
|
|
||||||
emit compactRepresentationItemChanged(m_compactRepresentationItem.data());
|
emit compactRepresentationItemChanged(d->compactRepresentationItem.data());
|
||||||
|
|
||||||
return m_compactRepresentationItem.data();
|
return d->compactRepresentationItem.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject *AppletQuickItem::createFullRepresentationItem()
|
QObject *AppletQuickItem::createFullRepresentationItem()
|
||||||
{
|
{
|
||||||
if (m_fullRepresentationItem) {
|
if (d->fullRepresentationItem) {
|
||||||
return m_fullRepresentationItem.data();
|
return d->fullRepresentationItem.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_fullRepresentation) {
|
if (d->fullRepresentation) {
|
||||||
m_fullRepresentationItem = m_qmlObject->createObjectFromComponent(m_fullRepresentation.data(), QtQml::qmlContext(m_qmlObject->rootObject()));
|
d->fullRepresentationItem = d->qmlObject->createObjectFromComponent(d->fullRepresentation.data(), QtQml::qmlContext(d->qmlObject->rootObject()));
|
||||||
} else {
|
} else {
|
||||||
m_fullRepresentation = m_qmlObject->mainComponent();
|
d->fullRepresentation = d->qmlObject->mainComponent();
|
||||||
m_fullRepresentationItem = m_qmlObject->rootObject();
|
d->fullRepresentationItem = d->qmlObject->rootObject();
|
||||||
emit fullRepresentationChanged(m_fullRepresentation.data());
|
emit fullRepresentationChanged(d->fullRepresentation.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
QQuickItem *graphicsObj = qobject_cast<QQuickItem *>(m_fullRepresentationItem.data());
|
QQuickItem *graphicsObj = qobject_cast<QQuickItem *>(d->fullRepresentationItem.data());
|
||||||
connect (graphicsObj, &QQuickItem::widthChanged, [=]() {
|
connect (graphicsObj, &QQuickItem::widthChanged, [=]() {
|
||||||
m_fullRepresentationResizeTimer.start();
|
d->fullRepresentationResizeTimer.start();
|
||||||
});
|
});
|
||||||
connect (graphicsObj, &QQuickItem::heightChanged, [=]() {
|
connect (graphicsObj, &QQuickItem::heightChanged, [=]() {
|
||||||
m_fullRepresentationResizeTimer.start();
|
d->fullRepresentationResizeTimer.start();
|
||||||
});
|
});
|
||||||
|
|
||||||
emit fullRepresentationItemChanged(m_fullRepresentationItem.data());
|
emit fullRepresentationItemChanged(d->fullRepresentationItem.data());
|
||||||
|
|
||||||
return m_fullRepresentationItem.data();
|
return d->fullRepresentationItem.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject *AppletQuickItem::createCompactRepresentationExpanderItem()
|
QObject *AppletQuickItem::createCompactRepresentationExpanderItem()
|
||||||
{
|
{
|
||||||
if (!m_compactRepresentationExpander) {
|
if (!d->compactRepresentationExpander) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_compactRepresentationExpanderItem) {
|
if (d->compactRepresentationExpanderItem) {
|
||||||
return m_compactRepresentationExpanderItem.data();
|
return d->compactRepresentationExpanderItem.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_compactRepresentationExpanderItem = m_qmlObject->createObjectFromComponent(m_compactRepresentationExpander.data(), QtQml::qmlContext(m_qmlObject->rootObject()));
|
d->compactRepresentationExpanderItem = d->qmlObject->createObjectFromComponent(d->compactRepresentationExpander.data(), QtQml::qmlContext(d->qmlObject->rootObject()));
|
||||||
|
|
||||||
|
|
||||||
m_compactRepresentationExpanderItem.data()->setProperty("compactRepresentation", QVariant::fromValue(createCompactRepresentationItem()));
|
d->compactRepresentationExpanderItem.data()->setProperty("compactRepresentation", QVariant::fromValue(createCompactRepresentationItem()));
|
||||||
m_compactRepresentationExpanderItem.data()->setProperty("fullRepresentation", QVariant::fromValue(createFullRepresentationItem()));
|
d->compactRepresentationExpanderItem.data()->setProperty("fullRepresentation", QVariant::fromValue(createFullRepresentationItem()));
|
||||||
|
|
||||||
emit compactRepresentationExpanderItemChanged(m_compactRepresentationExpanderItem.data());
|
emit compactRepresentationExpanderItemChanged(d->compactRepresentationExpanderItem.data());
|
||||||
|
|
||||||
return m_compactRepresentationExpanderItem.data();
|
return d->compactRepresentationExpanderItem.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppletQuickItem::connectLayoutAttached(QObject *item)
|
void AppletQuickItem::connectLayoutAttached(QObject *item)
|
||||||
@ -412,7 +421,7 @@ void AppletQuickItem::connectLayoutAttached(QObject *item)
|
|||||||
propagateSizeHint("fillHeight");
|
propagateSizeHint("fillHeight");
|
||||||
|
|
||||||
//HACK: check the Layout properties we wrote
|
//HACK: check the Layout properties we wrote
|
||||||
QQmlProperty p(this, "Layout.minimumWidth", QtQml::qmlContext(m_qmlObject->rootObject()));
|
QQmlProperty p(this, "Layout.minimumWidth", QtQml::qmlContext(d->qmlObject->rootObject()));
|
||||||
|
|
||||||
QObject *ownLayout = 0;
|
QObject *ownLayout = 0;
|
||||||
|
|
||||||
@ -433,12 +442,12 @@ void AppletQuickItem::connectLayoutAttached(QObject *item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//if the representation didn't change, don't do anything
|
//if the representation didn't change, don't do anything
|
||||||
if (m_representationLayout.data() == layout) {
|
if (d->representationLayout.data() == layout) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_representationLayout) {
|
if (d->representationLayout) {
|
||||||
disconnect(m_representationLayout.data(), 0, this, 0);
|
disconnect(d->representationLayout.data(), 0, this, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Here we can't use the new connect syntax because we can't link against QtQuick layouts
|
//Here we can't use the new connect syntax because we can't link against QtQuick layouts
|
||||||
@ -462,8 +471,8 @@ void AppletQuickItem::connectLayoutAttached(QObject *item)
|
|||||||
connect(layout, SIGNAL(fillHeightChanged()),
|
connect(layout, SIGNAL(fillHeightChanged()),
|
||||||
this, SLOT(fillHeightChanged()));
|
this, SLOT(fillHeightChanged()));
|
||||||
|
|
||||||
m_representationLayout = layout;
|
d->representationLayout = layout;
|
||||||
m_ownLayout = ownLayout;
|
d->ownLayout = ownLayout;
|
||||||
|
|
||||||
propagateSizeHint("minimumWidth");
|
propagateSizeHint("minimumWidth");
|
||||||
propagateSizeHint("minimumHeight");
|
propagateSizeHint("minimumHeight");
|
||||||
@ -477,8 +486,8 @@ void AppletQuickItem::connectLayoutAttached(QObject *item)
|
|||||||
|
|
||||||
void AppletQuickItem::propagateSizeHint(const QByteArray &layoutProperty)
|
void AppletQuickItem::propagateSizeHint(const QByteArray &layoutProperty)
|
||||||
{
|
{
|
||||||
if (m_ownLayout && m_representationLayout) {
|
if (d->ownLayout && d->representationLayout) {
|
||||||
m_ownLayout.data()->setProperty(layoutProperty, m_representationLayout.data()->property(layoutProperty));
|
d->ownLayout.data()->setProperty(layoutProperty, d->representationLayout.data()->property(layoutProperty));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,7 +496,7 @@ void AppletQuickItem::geometryChanged(const QRectF &newGeometry, const QRectF &o
|
|||||||
Q_UNUSED(oldGeometry)
|
Q_UNUSED(oldGeometry)
|
||||||
|
|
||||||
QQuickItem::geometryChanged(newGeometry, oldGeometry);
|
QQuickItem::geometryChanged(newGeometry, oldGeometry);
|
||||||
m_compactRepresentationCheckTimer.start();
|
d->compactRepresentationCheckTimer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppletQuickItem::itemChange(ItemChange change, const ItemChangeData &value)
|
void AppletQuickItem::itemChange(ItemChange change, const ItemChangeData &value)
|
||||||
@ -514,25 +523,25 @@ void AppletQuickItem::compactRepresentationCheck()
|
|||||||
|
|
||||||
bool full = false;
|
bool full = false;
|
||||||
|
|
||||||
if (m_applet->isContainment()) {
|
if (d->applet->isContainment()) {
|
||||||
full = true;
|
full = true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (m_switchWidth > 0 && m_switchHeight > 0) {
|
if (d->switchWidth > 0 && d->switchHeight > 0) {
|
||||||
full = width() > m_switchWidth && height() > m_switchHeight;
|
full = width() > d->switchWidth && height() > d->switchHeight;
|
||||||
//if a size to switch wasn't set, determine what representation to always chose
|
//if a size to switch wasn't set, determine what representation to always chose
|
||||||
} else {
|
} else {
|
||||||
//preferred representation set?
|
//preferred representation set?
|
||||||
if (m_preferredRepresentation) {
|
if (d->preferredRepresentation) {
|
||||||
full = m_preferredRepresentation.data() == m_fullRepresentation.data();
|
full = d->preferredRepresentation.data() == d->fullRepresentation.data();
|
||||||
//Otherwise, base on FormFactor
|
//Otherwise, base on FormFactor
|
||||||
} else {
|
} else {
|
||||||
full = (m_applet->formFactor() != Plasma::Types::Horizontal && m_applet->formFactor() != Plasma::Types::Vertical);
|
full = (d->applet->formFactor() != Plasma::Types::Horizontal && d->applet->formFactor() != Plasma::Types::Vertical);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((full && m_fullRepresentationItem && m_fullRepresentationItem.data() == m_currentRepresentationItem.data()) ||
|
if ((full && d->fullRepresentationItem && d->fullRepresentationItem.data() == d->currentRepresentationItem.data()) ||
|
||||||
(!full && m_compactRepresentationItem && m_compactRepresentationItem.data() == m_currentRepresentationItem.data())
|
(!full && d->compactRepresentationItem && d->compactRepresentationItem.data() == d->currentRepresentationItem.data())
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -546,19 +555,19 @@ void AppletQuickItem::compactRepresentationCheck()
|
|||||||
item->setParentItem(this);
|
item->setParentItem(this);
|
||||||
{
|
{
|
||||||
//set anchors
|
//set anchors
|
||||||
QQmlExpression expr(QtQml::qmlContext(m_qmlObject->rootObject()), item, "parent");
|
QQmlExpression expr(QtQml::qmlContext(d->qmlObject->rootObject()), item, "parent");
|
||||||
QQmlProperty prop(item, "anchors.fill");
|
QQmlProperty prop(item, "anchors.fill");
|
||||||
prop.write(expr.evaluate());
|
prop.write(expr.evaluate());
|
||||||
}
|
}
|
||||||
if (m_compactRepresentationItem) {
|
if (d->compactRepresentationItem) {
|
||||||
m_compactRepresentationItem.data()->setProperty("visible", false);
|
d->compactRepresentationItem.data()->setProperty("visible", false);
|
||||||
}
|
}
|
||||||
if (m_compactRepresentationExpanderItem) {
|
if (d->compactRepresentationExpanderItem) {
|
||||||
m_compactRepresentationExpanderItem.data()->setProperty("compactRepresentation", QVariant());
|
d->compactRepresentationExpanderItem.data()->setProperty("compactRepresentation", QVariant());
|
||||||
m_compactRepresentationExpanderItem.data()->setProperty("fullRepresentation", QVariant());
|
d->compactRepresentationExpanderItem.data()->setProperty("fullRepresentation", QVariant());
|
||||||
}
|
}
|
||||||
|
|
||||||
m_currentRepresentationItem = item;
|
d->currentRepresentationItem = item;
|
||||||
connectLayoutAttached(item);
|
connectLayoutAttached(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -572,21 +581,21 @@ void AppletQuickItem::compactRepresentationCheck()
|
|||||||
compactItem->setVisible(true);
|
compactItem->setVisible(true);
|
||||||
{
|
{
|
||||||
//set anchors
|
//set anchors
|
||||||
QQmlExpression expr(QtQml::qmlContext(m_qmlObject->rootObject()), compactItem, "parent");
|
QQmlExpression expr(QtQml::qmlContext(d->qmlObject->rootObject()), compactItem, "parent");
|
||||||
QQmlProperty prop(compactItem, "anchors.fill");
|
QQmlProperty prop(compactItem, "anchors.fill");
|
||||||
prop.write(expr.evaluate());
|
prop.write(expr.evaluate());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_fullRepresentationItem) {
|
if (d->fullRepresentationItem) {
|
||||||
m_fullRepresentationItem.data()->setProperty("parent", QVariant());
|
d->fullRepresentationItem.data()->setProperty("parent", QVariant());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_compactRepresentationExpanderItem) {
|
if (d->compactRepresentationExpanderItem) {
|
||||||
m_compactRepresentationExpanderItem.data()->setProperty("compactRepresentation", QVariant::fromValue(compactItem));
|
d->compactRepresentationExpanderItem.data()->setProperty("compactRepresentation", QVariant::fromValue(compactItem));
|
||||||
m_compactRepresentationExpanderItem.data()->setProperty("fullRepresentation", QVariant::fromValue(createFullRepresentationItem()));
|
d->compactRepresentationExpanderItem.data()->setProperty("fullRepresentation", QVariant::fromValue(createFullRepresentationItem()));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_currentRepresentationItem = compactItem;
|
d->currentRepresentationItem = compactItem;
|
||||||
connectLayoutAttached(compactItem);
|
connectLayoutAttached(compactItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,8 @@
|
|||||||
|
|
||||||
#include <Plasma/Package>
|
#include <Plasma/Package>
|
||||||
|
|
||||||
class QQmlComponent;
|
#include "appletquickitem_p.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Plasma {
|
namespace Plasma {
|
||||||
class Applet;
|
class Applet;
|
||||||
@ -39,7 +40,6 @@ namespace KDeclarative {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class AppletQuickItem : public QQuickItem
|
class AppletQuickItem : public QQuickItem
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -110,8 +110,8 @@ public:
|
|||||||
{
|
{
|
||||||
//at the moment of the attached object creation, the root item is the only one that hasn't a parent
|
//at the moment of the attached object creation, the root item is the only one that hasn't a parent
|
||||||
//only way to avoid creation of this attached for everybody but the root item
|
//only way to avoid creation of this attached for everybody but the root item
|
||||||
if (!object->parent() && s_rootObjects.contains(QtQml::qmlEngine(object))) {
|
if (!object->parent() && AppletQuickItemPrivate::s_rootObjects.contains(QtQml::qmlEngine(object))) {
|
||||||
return s_rootObjects.value(QtQml::qmlEngine(object));
|
return AppletQuickItemPrivate::s_rootObjects.value(QtQml::qmlEngine(object));
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -161,35 +161,7 @@ private Q_SLOTS:
|
|||||||
void fillHeightChanged();
|
void fillHeightChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_switchWidth;
|
AppletQuickItemPrivate *const d;
|
||||||
int m_switchHeight;
|
|
||||||
|
|
||||||
QWeakPointer<QQmlComponent> m_compactRepresentation;
|
|
||||||
QWeakPointer<QQmlComponent> m_fullRepresentation;
|
|
||||||
QWeakPointer<QQmlComponent> m_preferredRepresentation;
|
|
||||||
QWeakPointer<QQmlComponent> m_compactRepresentationExpander;
|
|
||||||
|
|
||||||
QWeakPointer<QObject> m_compactRepresentationItem;
|
|
||||||
QWeakPointer<QObject> m_fullRepresentationItem;
|
|
||||||
QWeakPointer<QObject> m_compactRepresentationExpanderItem;
|
|
||||||
QWeakPointer<QObject> m_currentRepresentationItem;
|
|
||||||
|
|
||||||
//Attached layout objects: own and the representation's one
|
|
||||||
QWeakPointer<QObject> m_representationLayout;
|
|
||||||
QWeakPointer<QObject> m_ownLayout;
|
|
||||||
|
|
||||||
QTimer m_compactRepresentationCheckTimer;
|
|
||||||
QTimer m_fullRepresentationResizeTimer;
|
|
||||||
|
|
||||||
Plasma::Applet *m_applet;
|
|
||||||
KDeclarative::QmlObject *m_qmlObject;
|
|
||||||
|
|
||||||
Plasma::Package m_appletPackage;
|
|
||||||
Plasma::Package m_coronaPackage;
|
|
||||||
|
|
||||||
bool m_expanded : 1;
|
|
||||||
|
|
||||||
static QHash<QObject *, AppletQuickItem *> s_rootObjects;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
QML_DECLARE_TYPEINFO(AppletQuickItem, QML_HAS_ATTACHED_PROPERTIES)
|
QML_DECLARE_TYPEINFO(AppletQuickItem, QML_HAS_ATTACHED_PROPERTIES)
|
||||||
|
71
src/scriptengines/qml/plasmoid/appletquickitem_p.h
Normal file
71
src/scriptengines/qml/plasmoid/appletquickitem_p.h
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014 Marco Martin <mart@kde.org>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Library General Public License as
|
||||||
|
* published by the Free Software Foundation; either version 2, 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 Library 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef APPLETQUICKITEM_H
|
||||||
|
#define APPLETQUICKITEM_H
|
||||||
|
|
||||||
|
#include <QQmlComponent>
|
||||||
|
|
||||||
|
namespace Plasma {
|
||||||
|
class Applet;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace KDeclarative {
|
||||||
|
class QmlObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
class AppletQuickItem;
|
||||||
|
|
||||||
|
class AppletQuickItemPrivate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AppletQuickItemPrivate(Plasma::Applet *a);
|
||||||
|
|
||||||
|
int switchWidth;
|
||||||
|
int switchHeight;
|
||||||
|
|
||||||
|
QWeakPointer<QQmlComponent> compactRepresentation;
|
||||||
|
QWeakPointer<QQmlComponent> fullRepresentation;
|
||||||
|
QWeakPointer<QQmlComponent> preferredRepresentation;
|
||||||
|
QWeakPointer<QQmlComponent> compactRepresentationExpander;
|
||||||
|
|
||||||
|
QWeakPointer<QObject> compactRepresentationItem;
|
||||||
|
QWeakPointer<QObject> fullRepresentationItem;
|
||||||
|
QWeakPointer<QObject> compactRepresentationExpanderItem;
|
||||||
|
QWeakPointer<QObject> currentRepresentationItem;
|
||||||
|
|
||||||
|
//Attached layout objects: own and the representation's one
|
||||||
|
QWeakPointer<QObject> representationLayout;
|
||||||
|
QWeakPointer<QObject> ownLayout;
|
||||||
|
|
||||||
|
QTimer compactRepresentationCheckTimer;
|
||||||
|
QTimer fullRepresentationResizeTimer;
|
||||||
|
|
||||||
|
Plasma::Applet *applet;
|
||||||
|
KDeclarative::QmlObject *qmlObject;
|
||||||
|
|
||||||
|
Plasma::Package appletPackage;
|
||||||
|
Plasma::Package coronaPackage;
|
||||||
|
|
||||||
|
bool expanded : 1;
|
||||||
|
|
||||||
|
static QHash<QObject *, AppletQuickItem *> s_rootObjects;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user