AppletContainer binding for containments
This adds a class to manipulate applets in more detail in context of containments. The type will only be available from Containments, not Applets or PopupApplets. This binds the necessary functionality of Applets to build fully features containments. The code has been moved from MobileComponents, untangling another piece there and putting the functionality where it belongs, into the specific component type bindings to allow this functionality also outside of plasma-mobile and further reduce the delta between the shell implementations. REVIEW:106817
This commit is contained in:
parent
e4cc7da085
commit
d6afd5b91a
@ -12,6 +12,7 @@ set(simple_javascript_engine_SRCS
|
|||||||
common/extension_io.cpp
|
common/extension_io.cpp
|
||||||
common/guiscriptenv.cpp
|
common/guiscriptenv.cpp
|
||||||
common/javascriptaddonpackagestructure.cpp
|
common/javascriptaddonpackagestructure.cpp
|
||||||
|
declarative/appletcontainer.cpp
|
||||||
plasmoid/abstractjsappletscript.cpp
|
plasmoid/abstractjsappletscript.cpp
|
||||||
plasmoid/appletauthorization.cpp
|
plasmoid/appletauthorization.cpp
|
||||||
plasmoid/jsappletinterface.cpp
|
plasmoid/jsappletinterface.cpp
|
||||||
@ -53,6 +54,7 @@ target_link_libraries(plasma_appletscript_simple_javascript
|
|||||||
${KDE4_KDECORE_LIBS}
|
${KDE4_KDECORE_LIBS}
|
||||||
${KDE4_KIO_LIBS}
|
${KDE4_KIO_LIBS}
|
||||||
${KDE4_PLASMA_LIBS}
|
${KDE4_PLASMA_LIBS}
|
||||||
|
${QT_QTDECLARATIVE_LIBRARY}
|
||||||
${QT_QTSCRIPT_LIBRARY}
|
${QT_QTSCRIPT_LIBRARY}
|
||||||
${QT_QTUITOOLS_LIBRARY}
|
${QT_QTUITOOLS_LIBRARY}
|
||||||
${QT_QTXML_LIBRARY}
|
${QT_QTXML_LIBRARY}
|
||||||
@ -129,6 +131,7 @@ set(declarative_appletscript_SRCS
|
|||||||
common/extension_io.cpp
|
common/extension_io.cpp
|
||||||
common/javascriptaddonpackagestructure.cpp
|
common/javascriptaddonpackagestructure.cpp
|
||||||
common/declarativescriptenv.cpp
|
common/declarativescriptenv.cpp
|
||||||
|
declarative/appletcontainer.cpp
|
||||||
declarative/declarativeitemcontainer.cpp
|
declarative/declarativeitemcontainer.cpp
|
||||||
declarative/packageaccessmanager.cpp
|
declarative/packageaccessmanager.cpp
|
||||||
declarative/packageaccessmanagerfactory.cpp
|
declarative/packageaccessmanagerfactory.cpp
|
||||||
|
204
scriptengines/javascript/declarative/appletcontainer.cpp
Normal file
204
scriptengines/javascript/declarative/appletcontainer.cpp
Normal file
@ -0,0 +1,204 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2011 Marco Martin <notmart@gmail.com>
|
||||||
|
|
||||||
|
This library 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 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library 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
|
||||||
|
Library General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Library General Public License
|
||||||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||||||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
|
Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "appletcontainer.h"
|
||||||
|
|
||||||
|
#include <QGraphicsLayout>
|
||||||
|
|
||||||
|
#include <KDebug>
|
||||||
|
|
||||||
|
#include <Plasma/Applet>
|
||||||
|
|
||||||
|
AppletContainer::AppletContainer(QDeclarativeItem *parent)
|
||||||
|
: QDeclarativeItem(parent)
|
||||||
|
{
|
||||||
|
setFlag(QGraphicsItem::ItemHasNoContents, true);
|
||||||
|
|
||||||
|
//the virtual geometryChanged is *NOT* called in case of change by the anchors
|
||||||
|
connect(this, SIGNAL(widthChanged()), this, SLOT(afterWidthChanged()), Qt::QueuedConnection);
|
||||||
|
connect(this, SIGNAL(heightChanged()), this, SLOT(afterHeightChanged()), Qt::QueuedConnection);
|
||||||
|
}
|
||||||
|
|
||||||
|
AppletContainer::~AppletContainer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QGraphicsWidget *AppletContainer::applet() const
|
||||||
|
{
|
||||||
|
return m_applet.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletContainer::setApplet(QGraphicsWidget *widget)
|
||||||
|
{
|
||||||
|
Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
|
||||||
|
if (!applet || applet == m_applet.data()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_applet) {
|
||||||
|
disconnect(m_applet.data(), 0, this, 0);
|
||||||
|
m_applet.data()->setParentItem(parentItem());
|
||||||
|
}
|
||||||
|
|
||||||
|
m_applet = applet;
|
||||||
|
|
||||||
|
connect(applet, SIGNAL(sizeHintChanged(Qt::SizeHint)), this, SLOT(sizeHintChanged(Qt::SizeHint)));
|
||||||
|
connect(applet, SIGNAL(newStatus(Plasma::ItemStatus)), this, SIGNAL(statusChanged()));
|
||||||
|
|
||||||
|
applet->setParentItem(this);
|
||||||
|
applet->setGeometry(0, 0, qMax((qreal)16, width()), qMax((qreal)16, height()));
|
||||||
|
applet->setFlag(QGraphicsItem::ItemIsMovable, false);
|
||||||
|
|
||||||
|
emit appletChanged(widget);
|
||||||
|
emit statusChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletContainer::sizeHintChanged(Qt::SizeHint which)
|
||||||
|
{
|
||||||
|
switch (which) {
|
||||||
|
case Qt::MinimumSize:
|
||||||
|
emit minimumWidthChanged(minimumWidth());
|
||||||
|
emit minimumHeightChanged(minimumHeight());
|
||||||
|
break;
|
||||||
|
case Qt::PreferredSize:
|
||||||
|
emit preferredWidthChanged(preferredWidth());
|
||||||
|
emit preferredHeightChanged(preferredHeight());
|
||||||
|
break;
|
||||||
|
case Qt::MaximumSize:
|
||||||
|
emit maximumWidthChanged(maximumWidth());
|
||||||
|
emit maximumHeightChanged(maximumHeight());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int AppletContainer::minimumWidth() const
|
||||||
|
{
|
||||||
|
if (!m_applet) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_applet.data()->effectiveSizeHint(Qt::MinimumSize).width();
|
||||||
|
}
|
||||||
|
|
||||||
|
int AppletContainer::minimumHeight() const
|
||||||
|
{
|
||||||
|
if (!m_applet) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_applet.data()->effectiveSizeHint(Qt::MinimumSize).height();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int AppletContainer::preferredWidth() const
|
||||||
|
{
|
||||||
|
if (!m_applet) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_applet.data()->effectiveSizeHint(Qt::PreferredSize).width();
|
||||||
|
}
|
||||||
|
|
||||||
|
int AppletContainer::preferredHeight() const
|
||||||
|
{
|
||||||
|
if (!m_applet) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_applet.data()->effectiveSizeHint(Qt::PreferredSize).height();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int AppletContainer::maximumWidth() const
|
||||||
|
{
|
||||||
|
if (!m_applet) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_applet.data()->effectiveSizeHint(Qt::MaximumSize).width();
|
||||||
|
}
|
||||||
|
|
||||||
|
int AppletContainer::maximumHeight() const
|
||||||
|
{
|
||||||
|
if (!m_applet) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_applet.data()->effectiveSizeHint(Qt::MaximumSize).height();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletContainer::setStatus(const AppletContainer::ItemStatus status)
|
||||||
|
{
|
||||||
|
if (!m_applet) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_applet.data()->setStatus((Plasma::ItemStatus)status);
|
||||||
|
}
|
||||||
|
|
||||||
|
AppletContainer::ItemStatus AppletContainer::status() const
|
||||||
|
{
|
||||||
|
if (!m_applet) {
|
||||||
|
return UnknownStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (AppletContainer::ItemStatus)((int)(m_applet.data()->status()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletContainer::afterWidthChanged()
|
||||||
|
{
|
||||||
|
if (!m_applet) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_applet.data()->resize(width(), height());
|
||||||
|
m_applet.data()->setPos(width()/2 - m_applet.data()->size().width()/2,
|
||||||
|
height()/2 - m_applet.data()->size().height()/2);
|
||||||
|
emit minimumWidthChanged(minimumWidth());
|
||||||
|
emit preferredWidthChanged(preferredWidth());
|
||||||
|
emit maximumWidthChanged(maximumWidth());
|
||||||
|
|
||||||
|
emit minimumHeightChanged(minimumHeight());
|
||||||
|
emit preferredHeightChanged(preferredHeight());
|
||||||
|
emit maximumHeightChanged(maximumHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppletContainer::afterHeightChanged()
|
||||||
|
{
|
||||||
|
if (!m_applet) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_applet.data()->resize(width(), height());
|
||||||
|
m_applet.data()->setPos(width()/2 - m_applet.data()->size().width()/2,
|
||||||
|
height()/2 - m_applet.data()->size().height()/2);
|
||||||
|
|
||||||
|
emit minimumWidthChanged(minimumWidth());
|
||||||
|
emit preferredWidthChanged(preferredWidth());
|
||||||
|
emit maximumWidthChanged(maximumWidth());
|
||||||
|
|
||||||
|
emit minimumHeightChanged(minimumHeight());
|
||||||
|
emit preferredHeightChanged(preferredHeight());
|
||||||
|
emit maximumHeightChanged(maximumHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#include "appletcontainer.moc"
|
97
scriptengines/javascript/declarative/appletcontainer.h
Normal file
97
scriptengines/javascript/declarative/appletcontainer.h
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2011 Marco Martin <notmart@gmail.com>
|
||||||
|
|
||||||
|
This library 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 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library 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
|
||||||
|
Library General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Library General Public License
|
||||||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||||||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
|
Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef APPLETCONTAINER_H
|
||||||
|
#define APPLETCONTAINER_H
|
||||||
|
|
||||||
|
#include <QDeclarativeItem>
|
||||||
|
|
||||||
|
namespace Plasma {
|
||||||
|
class Applet;
|
||||||
|
}
|
||||||
|
|
||||||
|
class AppletContainer : public QDeclarativeItem
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QGraphicsWidget *applet READ applet WRITE setApplet NOTIFY appletChanged)
|
||||||
|
|
||||||
|
Q_PROPERTY(int minimumWidth READ minimumWidth NOTIFY minimumWidthChanged)
|
||||||
|
Q_PROPERTY(int minimumHeight READ minimumHeight NOTIFY minimumHeightChanged)
|
||||||
|
|
||||||
|
Q_PROPERTY(int preferredWidth READ preferredWidth NOTIFY preferredWidthChanged)
|
||||||
|
Q_PROPERTY(int preferredHeight READ preferredHeight NOTIFY preferredHeightChanged)
|
||||||
|
|
||||||
|
Q_PROPERTY(int maximumWidth READ maximumWidth NOTIFY maximumWidthChanged)
|
||||||
|
Q_PROPERTY(int maximumHeight READ maximumHeight NOTIFY maximumHeightChanged)
|
||||||
|
|
||||||
|
Q_PROPERTY(ItemStatus status READ status WRITE setStatus NOTIFY statusChanged)
|
||||||
|
Q_ENUMS(ItemStatus)
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum ItemStatus {
|
||||||
|
UnknownStatus = 0, /**< The status is unknown **/
|
||||||
|
PassiveStatus = 1, /**< The Item is passive **/
|
||||||
|
ActiveStatus = 2, /**< The Item is active **/
|
||||||
|
NeedsAttentionStatus = 3, /**< The Item needs attention **/
|
||||||
|
AcceptingInputStatus = 4 /**< The Item is accepting input **/
|
||||||
|
};
|
||||||
|
|
||||||
|
AppletContainer(QDeclarativeItem *parent = 0);
|
||||||
|
~AppletContainer();
|
||||||
|
|
||||||
|
QGraphicsWidget *applet() const;
|
||||||
|
void setApplet(QGraphicsWidget *applet);
|
||||||
|
|
||||||
|
int minimumWidth() const;
|
||||||
|
int minimumHeight() const;
|
||||||
|
|
||||||
|
int preferredWidth() const;
|
||||||
|
int preferredHeight() const;
|
||||||
|
|
||||||
|
int maximumWidth() const;
|
||||||
|
int maximumHeight() const;
|
||||||
|
|
||||||
|
void setStatus(const ItemStatus status);
|
||||||
|
ItemStatus status() const;
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void appletChanged(QGraphicsWidget *applet);
|
||||||
|
|
||||||
|
void minimumWidthChanged(int);
|
||||||
|
void minimumHeightChanged(int);
|
||||||
|
|
||||||
|
void preferredWidthChanged(int);
|
||||||
|
void preferredHeightChanged(int);
|
||||||
|
|
||||||
|
void maximumWidthChanged(int);
|
||||||
|
void maximumHeightChanged(int);
|
||||||
|
|
||||||
|
void statusChanged();
|
||||||
|
|
||||||
|
|
||||||
|
protected Q_SLOTS:
|
||||||
|
void sizeHintChanged(Qt::SizeHint which);
|
||||||
|
void afterWidthChanged();
|
||||||
|
void afterHeightChanged();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QWeakPointer<Plasma::Applet> m_applet;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
#include "appletinterface.h"
|
#include "appletinterface.h"
|
||||||
|
|
||||||
|
#include "../declarative/appletcontainer.h"
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
@ -609,6 +611,9 @@ ContainmentInterface::ContainmentInterface(AbstractJsAppletScript *parent)
|
|||||||
connect(containment()->corona(), SIGNAL(availableScreenRegionChanged()),
|
connect(containment()->corona(), SIGNAL(availableScreenRegionChanged()),
|
||||||
this, SIGNAL(availableScreenRegionChanged()));
|
this, SIGNAL(availableScreenRegionChanged()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qmlRegisterType<AppletContainer>("org.kde.plasma.containments", 0, 1, "AppletContainer");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QScriptValue ContainmentInterface::applets()
|
QScriptValue ContainmentInterface::applets()
|
||||||
|
Loading…
Reference in New Issue
Block a user