entation switching done by appletloader
This commit is contained in:
parent
866fe43120
commit
075d55c842
@ -18,14 +18,17 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import QtQuick 2.0
|
import QtQuick 2.0
|
||||||
|
import QtQuick.Layouts 1.1
|
||||||
import org.kde.plasma.components 2.0
|
import org.kde.plasma.components 2.0
|
||||||
import org.kde.shell 2.0
|
import org.kde.plasma.shell 2.0
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
property int minimumWidth: 300
|
Layout.minimumWidth: 300
|
||||||
property int minimumHeight: 400
|
Layout.minimumHeight: 400
|
||||||
|
|
||||||
AppletInterface.title: "bah"
|
Plasmoid.title: "bah"
|
||||||
|
Plasmoid.switchWidth: 300
|
||||||
|
Plasmoid.switchHeight: 400
|
||||||
|
|
||||||
ToolBar {
|
ToolBar {
|
||||||
id: toolBar
|
id: toolBar
|
||||||
|
@ -8,6 +8,9 @@ endif()
|
|||||||
|
|
||||||
#DECLARATIVE APPLET
|
#DECLARATIVE APPLET
|
||||||
set(declarative_appletscript_SRCS
|
set(declarative_appletscript_SRCS
|
||||||
|
plasmoid/declarativeappletscript.cpp
|
||||||
|
|
||||||
|
plasmoid/appletloader.cpp
|
||||||
plasmoid/appletinterface.cpp
|
plasmoid/appletinterface.cpp
|
||||||
plasmoid/containmentinterface.cpp
|
plasmoid/containmentinterface.cpp
|
||||||
plasmoid/declarativeappletscript.cpp
|
plasmoid/declarativeappletscript.cpp
|
||||||
|
@ -55,8 +55,7 @@ Q_DECLARE_METATYPE(AppletInterface*)
|
|||||||
QHash<QObject *, AppletInterface *> AppletInterface::s_rootObjects = QHash<QObject *, AppletInterface *>();
|
QHash<QObject *, AppletInterface *> AppletInterface::s_rootObjects = QHash<QObject *, AppletInterface *>();
|
||||||
|
|
||||||
AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *parent)
|
AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *parent)
|
||||||
: QQuickItem(parent),
|
: AppletLoader(script, parent),
|
||||||
m_appletScriptEngine(script),
|
|
||||||
m_actionSignals(0),
|
m_actionSignals(0),
|
||||||
m_backgroundHints(Plasma::Types::StandardBackground),
|
m_backgroundHints(Plasma::Types::StandardBackground),
|
||||||
m_busy(false),
|
m_busy(false),
|
||||||
@ -93,7 +92,7 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *pa
|
|||||||
|
|
||||||
m_collapseTimer = new QTimer(this);
|
m_collapseTimer = new QTimer(this);
|
||||||
m_collapseTimer->setSingleShot(true);
|
m_collapseTimer->setSingleShot(true);
|
||||||
connect(m_collapseTimer, &QTimer::timeout, this, &AppletInterface::compactRepresentationCheck);
|
//connect(m_collapseTimer, &QTimer::timeout, this, &AppletInterface::compactRepresentationCheck);
|
||||||
}
|
}
|
||||||
|
|
||||||
AppletInterface::~AppletInterface()
|
AppletInterface::~AppletInterface()
|
||||||
@ -103,6 +102,8 @@ AppletInterface::~AppletInterface()
|
|||||||
|
|
||||||
void AppletInterface::init()
|
void AppletInterface::init()
|
||||||
{
|
{
|
||||||
|
AppletLoader::init();
|
||||||
|
|
||||||
if (m_qmlObject->rootObject()) {
|
if (m_qmlObject->rootObject()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -239,7 +240,7 @@ void AppletInterface::setExpanded(bool expanded)
|
|||||||
{
|
{
|
||||||
//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_compactUiObject || qobject_cast<ContainmentInterface *>(this) || m_expanded == expanded) {
|
if (/*!m_compactUiObject ||*/ qobject_cast<ContainmentInterface *>(this) || m_expanded == expanded) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -610,11 +611,11 @@ void AppletInterface::geometryChanged(const QRectF &newGeometry, const QRectF &o
|
|||||||
{
|
{
|
||||||
Q_UNUSED(oldGeometry)
|
Q_UNUSED(oldGeometry)
|
||||||
|
|
||||||
QQuickItem::geometryChanged(newGeometry, oldGeometry);
|
AppletLoader::geometryChanged(newGeometry, oldGeometry);
|
||||||
m_collapseTimer->start(100);
|
m_collapseTimer->start(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppletInterface::compactRepresentationCheck()
|
void AppletInterface::_compactRepresentationCheck()
|
||||||
{
|
{
|
||||||
if (width() <= 0 || height() <= 0 || !m_qmlObject->rootObject() ||
|
if (width() <= 0 || height() <= 0 || !m_qmlObject->rootObject() ||
|
||||||
qobject_cast<ContainmentInterface *>(this)) {
|
qobject_cast<ContainmentInterface *>(this)) {
|
||||||
@ -839,7 +840,7 @@ void AppletInterface::itemChange(ItemChange change, const ItemChangeData &value)
|
|||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QQuickItem::itemChange(change, value);
|
AppletLoader::itemChange(change, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
KDeclarative::QmlObject *AppletInterface::qmlObject()
|
KDeclarative::QmlObject *AppletInterface::qmlObject()
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include <Plasma/Applet>
|
#include <Plasma/Applet>
|
||||||
#include <Plasma/Theme>
|
#include <Plasma/Theme>
|
||||||
|
|
||||||
|
#include "appletloader.h"
|
||||||
#include "declarativeappletscript.h"
|
#include "declarativeappletscript.h"
|
||||||
|
|
||||||
class QAction;
|
class QAction;
|
||||||
@ -48,7 +49,7 @@ namespace Plasma
|
|||||||
class ConfigLoader;
|
class ConfigLoader;
|
||||||
} // namespace Plasma
|
} // namespace Plasma
|
||||||
|
|
||||||
class AppletInterface : public QQuickItem
|
class AppletInterface : public AppletLoader
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -335,13 +336,13 @@ protected:
|
|||||||
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
|
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
|
||||||
void itemChange(ItemChange change, const ItemChangeData &value);
|
void itemChange(ItemChange change, const ItemChangeData &value);
|
||||||
|
|
||||||
DeclarativeAppletScript *m_appletScriptEngine;
|
|
||||||
|
|
||||||
protected Q_SLOTS:
|
protected Q_SLOTS:
|
||||||
virtual void init();
|
virtual void init();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void compactRepresentationCheck();
|
void _compactRepresentationCheck();
|
||||||
void updatePopupSize();
|
void updatePopupSize();
|
||||||
void updateImplicitWidth();
|
void updateImplicitWidth();
|
||||||
void updateImplicitHeight();
|
void updateImplicitHeight();
|
||||||
@ -359,7 +360,6 @@ private:
|
|||||||
KDeclarative::ConfigPropertyMap *m_configuration;
|
KDeclarative::ConfigPropertyMap *m_configuration;
|
||||||
|
|
||||||
//UI-specific members ------------------
|
//UI-specific members ------------------
|
||||||
KDeclarative::QmlObject *m_qmlObject;
|
|
||||||
QWeakPointer<QObject> m_compactUiObject;
|
QWeakPointer<QObject> m_compactUiObject;
|
||||||
|
|
||||||
QTimer *m_collapseTimer;
|
QTimer *m_collapseTimer;
|
||||||
|
532
src/scriptengines/qml/plasmoid/appletloader.cpp
Normal file
532
src/scriptengines/qml/plasmoid/appletloader.cpp
Normal file
@ -0,0 +1,532 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "appletloader.h"
|
||||||
|
|
||||||
|
#include <QQmlComponent>
|
||||||
|
#include <QQmlExpression>
|
||||||
|
#include <QQmlEngine>
|
||||||
|
#include <QQmlProperty>
|
||||||
|
#include <QQmlContext>
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include <Plasma/Applet>
|
||||||
|
#include <Plasma/Containment>
|
||||||
|
#include <Plasma/Corona>
|
||||||
|
#include <Plasma/Package>
|
||||||
|
#include <kdeclarative/qmlobject.h>
|
||||||
|
#include <plasma/scripting/appletscript.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
AppletLoader::AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent)
|
||||||
|
: QQuickItem(parent),
|
||||||
|
m_switchWidth(-1),
|
||||||
|
m_switchHeight(-1),
|
||||||
|
m_appletScriptEngine(script)
|
||||||
|
{
|
||||||
|
m_compactRepresentationCheckTimer.setSingleShot(true);
|
||||||
|
m_compactRepresentationCheckTimer.setInterval(250);
|
||||||
|
connect (&m_compactRepresentationCheckTimer, SIGNAL(timeout()),
|
||||||
|
this, SLOT(compactRepresentationCheck()));
|
||||||
|
m_compactRepresentationCheckTimer.start();
|
||||||
|
|
||||||
|
m_fullRepresentationResizeTimer.setSingleShot(true);
|
||||||
|
m_fullRepresentationResizeTimer.setInterval(250);
|
||||||
|
connect (&m_fullRepresentationResizeTimer, &QTimer::timeout,
|
||||||
|
[=]() {
|
||||||
|
KConfigGroup cg = applet()->config();
|
||||||
|
cg = KConfigGroup(&cg, "PopupApplet");
|
||||||
|
cg.writeEntry("DialogWidth", m_fullRepresentationItem.data()->property("width").toInt());
|
||||||
|
cg.writeEntry("DialogHeight", m_fullRepresentationItem.data()->property("height").toInt());
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
//hide all the children that aren't the known ones.
|
||||||
|
//all the UI is supposed to happen in the representations
|
||||||
|
/* connect (this, &QQuickItem::childrenChanged, [=]() {
|
||||||
|
foreach (QQuickItem *child, childItems()) {
|
||||||
|
if (child != m_compactRepresentationItem.data() &&
|
||||||
|
child != m_fullRepresentationItem.data() &&
|
||||||
|
child != m_compactRepresentationExpanderItem.data()) {
|
||||||
|
child->setVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
m_applet = m_appletScriptEngine->applet();
|
||||||
|
|
||||||
|
m_qmlObject = new KDeclarative::QmlObject(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
AppletLoader::~AppletLoader()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Plasma::Applet *AppletLoader::applet() const
|
||||||
|
{
|
||||||
|
return m_applet;
|
||||||
|
}
|
||||||
|
|
||||||
|
Plasma::AppletScript *AppletLoader::appletScript()
|
||||||
|
{
|
||||||
|
return m_appletScriptEngine;
|
||||||
|
}
|
||||||
|
|
||||||
|
int AppletLoader::switchWidth() const
|
||||||
|
{
|
||||||
|
return m_switchWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletLoader::setSwitchWidth(int width)
|
||||||
|
{
|
||||||
|
if (m_switchWidth == width) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_switchWidth = width;
|
||||||
|
emit switchWidthChanged(width);
|
||||||
|
}
|
||||||
|
|
||||||
|
int AppletLoader::switchHeight() const
|
||||||
|
{
|
||||||
|
return m_switchHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletLoader::setSwitchHeight(int width)
|
||||||
|
{
|
||||||
|
if (m_switchHeight == width) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_switchHeight = width;
|
||||||
|
emit switchHeightChanged(width);
|
||||||
|
}
|
||||||
|
|
||||||
|
QQmlComponent *AppletLoader::compactRepresentation()
|
||||||
|
{
|
||||||
|
return m_compactRepresentation.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletLoader::setCompactRepresentation(QQmlComponent *component)
|
||||||
|
{
|
||||||
|
if (m_compactRepresentation.data() == component) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_compactRepresentation = component;
|
||||||
|
emit compactRepresentationChanged(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QQmlComponent *AppletLoader::fullRepresentation()
|
||||||
|
{
|
||||||
|
return m_fullRepresentation.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletLoader::setFullRepresentation(QQmlComponent *component)
|
||||||
|
{
|
||||||
|
if (m_fullRepresentation.data() == component) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_fullRepresentation = component;
|
||||||
|
emit fullRepresentationChanged(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
QQmlComponent *AppletLoader::preferredRepresentation()
|
||||||
|
{
|
||||||
|
return m_preferredRepresentation.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletLoader::setPreferredRepresentation(QQmlComponent *component)
|
||||||
|
{
|
||||||
|
if (m_preferredRepresentation.data() == component) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_preferredRepresentation = component;
|
||||||
|
emit preferredRepresentationChanged(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////Internals
|
||||||
|
|
||||||
|
void AppletLoader::classBegin()
|
||||||
|
{
|
||||||
|
Q_ASSERT(m_qmlObject->engine());
|
||||||
|
m_qmlObject->engine()->rootContext()->setContextProperty("plasmoid", this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletLoader::init()
|
||||||
|
{
|
||||||
|
//m_appletScriptEngine = property("_plasma_appletscript").value<Plasma::AppletScript *>();
|
||||||
|
|
||||||
|
Q_ASSERT(m_appletScriptEngine);
|
||||||
|
// m_applet = m_appletScriptEngine->applet();
|
||||||
|
Q_ASSERT(m_applet);
|
||||||
|
|
||||||
|
// m_qmlObject = new KDeclarative::QmlObject(m_qmlObject->engine(), this);
|
||||||
|
|
||||||
|
//default m_compactRepresentation is a simple icon provided by the shell package
|
||||||
|
if (!m_compactRepresentation) {
|
||||||
|
m_compactRepresentation = new QQmlComponent(m_qmlObject->engine(), this);
|
||||||
|
m_compactRepresentation.data()->loadUrl(QUrl::fromLocalFile(m_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_applet->containment()->corona()->package().filePath("appleterror")));
|
||||||
|
}*/
|
||||||
|
|
||||||
|
//default m_compactRepresentationExpander is the popup in which fullRepresentation goes
|
||||||
|
if (!m_compactRepresentationExpander) {
|
||||||
|
m_compactRepresentationExpander = new QQmlComponent(m_qmlObject->engine(), this);
|
||||||
|
m_compactRepresentationExpander.data()->loadUrl(QUrl::fromLocalFile(m_applet->containment()->corona()->package().filePath("compactapplet")));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
KDeclarative::QmlObject *AppletLoader::qmlObject()
|
||||||
|
{
|
||||||
|
return m_qmlObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
QObject *AppletLoader::compactRepresentationItem()
|
||||||
|
{
|
||||||
|
return m_compactRepresentationItem.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
QObject *AppletLoader::fullRepresentationItem()
|
||||||
|
{
|
||||||
|
return m_fullRepresentationItem.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
QObject *AppletLoader::compactRepresentationExpanderItem()
|
||||||
|
{
|
||||||
|
return m_compactRepresentationExpanderItem.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
QObject *AppletLoader::createCompactRepresentationItem()
|
||||||
|
{
|
||||||
|
if (!m_compactRepresentation) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_compactRepresentationItem) {
|
||||||
|
return m_compactRepresentationItem.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_compactRepresentationItem = m_qmlObject->createObjectFromComponent(m_compactRepresentation.data(), QtQml::qmlContext(m_qmlObject->rootObject()));
|
||||||
|
|
||||||
|
emit compactRepresentationItemChanged(m_compactRepresentationItem.data());
|
||||||
|
|
||||||
|
return m_compactRepresentationItem.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
QObject *AppletLoader::createFullRepresentationItem()
|
||||||
|
{
|
||||||
|
if (m_fullRepresentationItem) {
|
||||||
|
return m_fullRepresentationItem.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_fullRepresentation) {
|
||||||
|
m_fullRepresentationItem = m_qmlObject->createObjectFromComponent(m_fullRepresentation.data(), QtQml::qmlContext(m_qmlObject->rootObject()));
|
||||||
|
} else {
|
||||||
|
m_fullRepresentationItem = m_qmlObject->rootObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
QQuickItem *graphicsObj = qobject_cast<QQuickItem *>(m_fullRepresentationItem.data());
|
||||||
|
connect (graphicsObj, &QQuickItem::widthChanged, [=]() {
|
||||||
|
m_fullRepresentationResizeTimer.start();
|
||||||
|
});
|
||||||
|
connect (graphicsObj, &QQuickItem::heightChanged, [=]() {
|
||||||
|
m_fullRepresentationResizeTimer.start();
|
||||||
|
});
|
||||||
|
|
||||||
|
emit fullRepresentationItemChanged(m_fullRepresentationItem.data());
|
||||||
|
|
||||||
|
return m_fullRepresentationItem.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
QObject *AppletLoader::createCompactRepresentationExpanderItem()
|
||||||
|
{
|
||||||
|
if (!m_compactRepresentationExpander) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_compactRepresentationExpanderItem) {
|
||||||
|
return m_compactRepresentationExpanderItem.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_compactRepresentationExpanderItem = m_qmlObject->createObjectFromComponent(m_compactRepresentationExpander.data(), QtQml::qmlContext(m_qmlObject->rootObject()));
|
||||||
|
|
||||||
|
emit compactRepresentationExpanderItemChanged(m_compactRepresentationExpanderItem.data());
|
||||||
|
|
||||||
|
return m_compactRepresentationExpanderItem.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletLoader::connectLayoutAttached(QObject *item)
|
||||||
|
{
|
||||||
|
QObject *layout = 0;
|
||||||
|
|
||||||
|
//Extract the representation's Layout, if any
|
||||||
|
//No Item?
|
||||||
|
if (!item) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Search a child that has the needed Layout properties
|
||||||
|
//HACK: here we are not type safe, but is the only way to access to a pointer of Layout
|
||||||
|
foreach (QObject *child, item->children()) {
|
||||||
|
//find for the needed property of Layout: minimum/maximum/preferred sizes and fillWidth/fillHeight
|
||||||
|
if (child->property("minimumWidth").isValid() && child->property("minimumHeight").isValid() &&
|
||||||
|
child->property("preferredWidth").isValid() && child->property("preferredHeight").isValid() &&
|
||||||
|
child->property("maximumWidth").isValid() && child->property("maximumHeight").isValid() &&
|
||||||
|
child->property("fillWidth").isValid() && child->property("fillHeight").isValid()
|
||||||
|
) {
|
||||||
|
layout = child;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!layout) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//propagate all the size hints
|
||||||
|
propagateSizeHint("minimumWidth");
|
||||||
|
propagateSizeHint("minimumHeight");
|
||||||
|
propagateSizeHint("preferredWidth");
|
||||||
|
propagateSizeHint("preferredHeight");
|
||||||
|
propagateSizeHint("maximumWidth");
|
||||||
|
propagateSizeHint("maximumHeight");
|
||||||
|
propagateSizeHint("fillWidth");
|
||||||
|
propagateSizeHint("fillHeight");
|
||||||
|
|
||||||
|
//HACK: check the Layout properties we wrote
|
||||||
|
QQmlProperty p(this, "Layout.minimumWidth", QtQml::qmlContext(m_qmlObject->rootObject()));
|
||||||
|
QObject *ownLayout = p.object();
|
||||||
|
|
||||||
|
//this should never happen, since we ask to create it if doesn't exists
|
||||||
|
if (!ownLayout) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//if the representation didn't change, don't do anything
|
||||||
|
if (m_representationLayout.data() == layout ||
|
||||||
|
m_ownLayout.data() == ownLayout) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
disconnect(layout, 0, this, 0);
|
||||||
|
|
||||||
|
//Here we can't use the new connect syntax because we can't link against QtQuick layouts
|
||||||
|
connect(layout, SIGNAL(minimumWidthChanged()),
|
||||||
|
this, SLOT(minimumWidthChanged()));
|
||||||
|
connect(layout, SIGNAL(minimumHeightChanged()),
|
||||||
|
this, SLOT(minimumHeightChanged()));
|
||||||
|
|
||||||
|
connect(layout, SIGNAL(preferredWidthChanged()),
|
||||||
|
this, SLOT(preferredWidthChanged()));
|
||||||
|
connect(layout, SIGNAL(preferredHeightChanged()),
|
||||||
|
this, SLOT(preferredHeightChanged()));
|
||||||
|
|
||||||
|
connect(layout, SIGNAL(maximumWidthChanged()),
|
||||||
|
this, SLOT(maximumWidthChanged()));
|
||||||
|
connect(layout, SIGNAL(maximumHeightChanged()),
|
||||||
|
this, SLOT(maximumHeightChanged()));
|
||||||
|
|
||||||
|
connect(layout, SIGNAL(fillWidthChanged()),
|
||||||
|
this, SLOT(fillWidthChanged()));
|
||||||
|
connect(layout, SIGNAL(fillHeightChanged()),
|
||||||
|
this, SLOT(fillHeightChanged()));
|
||||||
|
|
||||||
|
m_representationLayout = layout;
|
||||||
|
m_ownLayout = ownLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletLoader::propagateSizeHint(const QByteArray &layoutProperty)
|
||||||
|
{
|
||||||
|
if (!m_currentRepresentationItem) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QQmlExpression *expr = new QQmlExpression(QtQml::qmlContext(m_currentRepresentationItem.data()), m_currentRepresentationItem.data(), "Layout."+layoutProperty);
|
||||||
|
QQmlProperty prop(this, "Layout."+layoutProperty, QtQml::qmlContext(m_currentRepresentationItem.data()));
|
||||||
|
prop.write(expr->evaluate());
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletLoader::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
|
||||||
|
{
|
||||||
|
Q_UNUSED(oldGeometry)
|
||||||
|
|
||||||
|
QQuickItem::geometryChanged(newGeometry, oldGeometry);
|
||||||
|
m_compactRepresentationCheckTimer.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletLoader::itemChange(ItemChange change, const ItemChangeData &value)
|
||||||
|
{
|
||||||
|
if (change == QQuickItem::ItemSceneChange) {
|
||||||
|
//we have a window: create the representations if needed
|
||||||
|
if (value.window) {
|
||||||
|
m_compactRepresentationCheckTimer.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QQuickItem::itemChange(change, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//// Slots
|
||||||
|
|
||||||
|
void AppletLoader::compactRepresentationCheck()
|
||||||
|
{
|
||||||
|
//ignore 0,0 sizes;
|
||||||
|
if (width() <= 0 && height() <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool full = false;
|
||||||
|
|
||||||
|
if (applet()->isContainment()) {
|
||||||
|
full = true;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (m_switchWidth > 0 && m_switchHeight > 0) {
|
||||||
|
full = width() > m_switchWidth && height() > m_switchHeight;
|
||||||
|
//if a size to switch wasn't set, determine what representation to always chose
|
||||||
|
} else {
|
||||||
|
//preferred representation set?
|
||||||
|
if (m_preferredRepresentation) {
|
||||||
|
full = m_preferredRepresentation.data() == m_fullRepresentation.data();
|
||||||
|
//Otherwise, base on FormFactor
|
||||||
|
} else {
|
||||||
|
full = (m_applet->formFactor() != Plasma::Types::Horizontal && m_applet->formFactor() != Plasma::Types::Vertical);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((full && m_fullRepresentationItem && m_fullRepresentationItem.data() == m_currentRepresentationItem.data()) ||
|
||||||
|
(!full && m_compactRepresentationItem && m_compactRepresentationItem.data() == m_currentRepresentationItem.data())
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Expanded
|
||||||
|
if (full) {
|
||||||
|
QQuickItem *item = qobject_cast<QQuickItem *>(createFullRepresentationItem());
|
||||||
|
|
||||||
|
if (item) {
|
||||||
|
item->setParentItem(this);
|
||||||
|
{
|
||||||
|
//set anchors
|
||||||
|
QQmlExpression expr(QtQml::qmlContext(m_qmlObject->rootObject()), item, "parent");
|
||||||
|
QQmlProperty prop(item, "anchors.fill");
|
||||||
|
prop.write(expr.evaluate());
|
||||||
|
}
|
||||||
|
if (m_compactRepresentationItem) {
|
||||||
|
m_compactRepresentationItem.data()->setProperty("visible", false);
|
||||||
|
}
|
||||||
|
if (m_compactRepresentationExpanderItem) {
|
||||||
|
m_compactRepresentationExpanderItem.data()->setProperty("compactRepresentation", QVariant());
|
||||||
|
m_compactRepresentationExpanderItem.data()->setProperty("fullRepresentation", QVariant());
|
||||||
|
}
|
||||||
|
|
||||||
|
m_currentRepresentationItem = item;
|
||||||
|
connectLayoutAttached(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Icon
|
||||||
|
} else {
|
||||||
|
QQuickItem *fullItem = qobject_cast<QQuickItem *>(createFullRepresentationItem());
|
||||||
|
QQuickItem *compactItem = qobject_cast<QQuickItem *>(createCompactRepresentationItem());
|
||||||
|
QObject *compactExpanderItem = createCompactRepresentationExpanderItem();
|
||||||
|
|
||||||
|
if (fullItem && compactItem && compactExpanderItem) {
|
||||||
|
//set the root item as the main visible item
|
||||||
|
compactItem->setParentItem(this);
|
||||||
|
compactItem->setVisible(true);
|
||||||
|
{
|
||||||
|
//set anchors
|
||||||
|
QQmlExpression expr(QtQml::qmlContext(m_qmlObject->rootObject()), compactItem, "parent");
|
||||||
|
QQmlProperty prop(compactItem, "anchors.fill");
|
||||||
|
prop.write(expr.evaluate());
|
||||||
|
}
|
||||||
|
|
||||||
|
compactExpanderItem->setProperty("compactRepresentation", QVariant::fromValue(compactItem));
|
||||||
|
compactExpanderItem->setProperty("fullRepresentation", QVariant::fromValue(fullItem));
|
||||||
|
m_currentRepresentationItem = compactItem;
|
||||||
|
connectLayoutAttached(compactItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletLoader::minimumWidthChanged()
|
||||||
|
{
|
||||||
|
propagateSizeHint("minimumWidth");
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletLoader::minimumHeightChanged()
|
||||||
|
{
|
||||||
|
propagateSizeHint("minimumHeight");
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletLoader::preferredWidthChanged()
|
||||||
|
{
|
||||||
|
propagateSizeHint("preferredWidth");
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletLoader::preferredHeightChanged()
|
||||||
|
{
|
||||||
|
propagateSizeHint("preferredHeight");
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletLoader::maximumWidthChanged()
|
||||||
|
{
|
||||||
|
propagateSizeHint("maximumWidth");
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletLoader::maximumHeightChanged()
|
||||||
|
{
|
||||||
|
propagateSizeHint("maximumHeight");
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletLoader::fillWidthChanged()
|
||||||
|
{
|
||||||
|
propagateSizeHint("fillWidth");
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletLoader::fillHeightChanged()
|
||||||
|
{
|
||||||
|
propagateSizeHint("fillHeight");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "moc_appletloader.cpp"
|
||||||
|
|
169
src/scriptengines/qml/plasmoid/appletloader.h
Normal file
169
src/scriptengines/qml/plasmoid/appletloader.h
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
/*
|
||||||
|
* 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 APPLETLOADER_P
|
||||||
|
#define APPLETLOADER_P
|
||||||
|
|
||||||
|
#include <QQuickItem>
|
||||||
|
#include <QWeakPointer>
|
||||||
|
#include <QQmlComponent>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
#include "declarativeappletscript.h"
|
||||||
|
|
||||||
|
class QQmlComponent;
|
||||||
|
|
||||||
|
namespace Plasma {
|
||||||
|
class Applet;
|
||||||
|
class AppletScript;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace KDeclarative {
|
||||||
|
class QmlObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class AppletLoader : public QQuickItem
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY(int switchWidth READ switchWidth WRITE setSwitchWidth NOTIFY switchWidthChanged)
|
||||||
|
Q_PROPERTY(int switchHeight READ switchHeight WRITE setSwitchHeight NOTIFY switchHeightChanged)
|
||||||
|
|
||||||
|
Q_PROPERTY(QQmlComponent *compactRepresentation READ compactRepresentation WRITE setCompactRepresentation NOTIFY compactRepresentationChanged)
|
||||||
|
Q_PROPERTY(QObject *compactRepresentationItem READ compactRepresentationItem NOTIFY compactRepresentationItemChanged)
|
||||||
|
|
||||||
|
Q_PROPERTY(QQmlComponent *fullRepresentation READ fullRepresentation WRITE setFullRepresentation NOTIFY fullRepresentationChanged)
|
||||||
|
Q_PROPERTY(QObject *fullRepresentationItem READ fullRepresentationItem NOTIFY fullRepresentationItemChanged)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this is supposed to be either one between compactRepresentation or fullRepresentation
|
||||||
|
*/
|
||||||
|
Q_PROPERTY(QQmlComponent *preferredRepresentation READ preferredRepresentation WRITE setPreferredRepresentation NOTIFY preferredRepresentationChanged)
|
||||||
|
|
||||||
|
//FIXME: is it wise to expose this?
|
||||||
|
Q_PROPERTY(QQmlComponent *compactRepresentation READ compactRepresentation WRITE setCompactRepresentation NOTIFY compactRepresentationChanged)
|
||||||
|
|
||||||
|
public:
|
||||||
|
AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent = 0);
|
||||||
|
~AppletLoader();
|
||||||
|
|
||||||
|
Plasma::Applet *applet() const;
|
||||||
|
Plasma::AppletScript *appletScript();
|
||||||
|
|
||||||
|
int switchWidth() const;
|
||||||
|
void setSwitchWidth(int width);
|
||||||
|
|
||||||
|
int switchHeight() const;
|
||||||
|
void setSwitchHeight(int width);
|
||||||
|
|
||||||
|
|
||||||
|
QQmlComponent *compactRepresentation();
|
||||||
|
void setCompactRepresentation(QQmlComponent *component);
|
||||||
|
|
||||||
|
QQmlComponent *fullRepresentation();
|
||||||
|
void setFullRepresentation(QQmlComponent *component);
|
||||||
|
|
||||||
|
QQmlComponent *preferredRepresentation();
|
||||||
|
void setPreferredRepresentation(QQmlComponent *component);
|
||||||
|
|
||||||
|
|
||||||
|
QQmlComponent *compactRepresentationExpander();
|
||||||
|
void setCompactRepresentationExpander(QQmlComponent *component);
|
||||||
|
|
||||||
|
QObject *compactRepresentationItem();
|
||||||
|
QObject *fullRepresentationItem();
|
||||||
|
QObject *compactRepresentationExpanderItem();
|
||||||
|
|
||||||
|
//Reimplemented
|
||||||
|
virtual void classBegin();
|
||||||
|
virtual void init();
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void switchWidthChanged(int width);
|
||||||
|
void switchHeightChanged(int height);
|
||||||
|
|
||||||
|
void compactRepresentationChanged(QQmlComponent *compactRepresentation);
|
||||||
|
void fullRepresentationChanged(QQmlComponent *fullRepresentation);
|
||||||
|
void preferredRepresentationChanged(QQmlComponent *preferredRepresentation);
|
||||||
|
|
||||||
|
void compactRepresentationExpanderChanged(QQmlComponent *compactRepresentationExpander);
|
||||||
|
|
||||||
|
void compactRepresentationItemChanged(QObject *compactRepresentationItem);
|
||||||
|
void fullRepresentationItemChanged(QObject *fullRepresentationItem);
|
||||||
|
void compactRepresentationExpanderItemChanged(QObject *compactRepresentationExpanderItem);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
KDeclarative::QmlObject *qmlObject();
|
||||||
|
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
|
||||||
|
void itemChange(ItemChange change, const ItemChangeData &value);
|
||||||
|
|
||||||
|
QObject *createCompactRepresentationItem();
|
||||||
|
QObject *createFullRepresentationItem();
|
||||||
|
QObject *createCompactRepresentationExpanderItem();
|
||||||
|
|
||||||
|
//look into item, and return the Layout attached property, if found
|
||||||
|
void connectLayoutAttached(QObject *item);
|
||||||
|
void propagateSizeHint(const QByteArray &layoutProperty);
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void compactRepresentationCheck();
|
||||||
|
|
||||||
|
//handlers of Layout signals
|
||||||
|
void minimumWidthChanged();
|
||||||
|
void minimumHeightChanged();
|
||||||
|
void preferredWidthChanged();
|
||||||
|
void preferredHeightChanged();
|
||||||
|
void maximumWidthChanged();
|
||||||
|
void maximumHeightChanged();
|
||||||
|
void fillWidthChanged();
|
||||||
|
void fillHeightChanged();
|
||||||
|
|
||||||
|
//FIXME:
|
||||||
|
protected:
|
||||||
|
DeclarativeAppletScript *m_appletScriptEngine;
|
||||||
|
KDeclarative::QmlObject *m_qmlObject;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_switchWidth;
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -55,8 +55,8 @@ DeclarativeAppletScript::DeclarativeAppletScript(QObject *parent, const QVariant
|
|||||||
m_interface(0)
|
m_interface(0)
|
||||||
{
|
{
|
||||||
//qmlRegisterType<AppletInterface>();
|
//qmlRegisterType<AppletInterface>();
|
||||||
qmlRegisterUncreatableType<AppletInterface>("org.kde.shell", 2, 0, "AppletInterface",
|
qmlRegisterUncreatableType<AppletInterface>("org.kde.plasma.shell", 2, 0, "Plasmoid",
|
||||||
QLatin1String("Do not create objects of type AppletInterface"));
|
QLatin1String("Do not create objects of type Plasmoid"));
|
||||||
qmlRegisterType<KDeclarative::ConfigPropertyMap>();
|
qmlRegisterType<KDeclarative::ConfigPropertyMap>();
|
||||||
Q_UNUSED(args);
|
Q_UNUSED(args);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user