ntroduce a new class ContainmentView
replaces View, uses the shared engine view and uses the only global engine Change-Id: I3de71c38edc92a0609d6614bde819957819c66a4
This commit is contained in:
parent
1b5805ba02
commit
68104d38d4
@ -20,6 +20,7 @@ set(plasmaquick_LIB_SRC
|
||||
dialog.cpp
|
||||
dialogshadows.cpp
|
||||
view.cpp
|
||||
containmentview.cpp
|
||||
configmodel.cpp
|
||||
shellpluginloader.cpp
|
||||
configview.cpp
|
||||
|
275
src/plasmaquick/containmentview.cpp
Normal file
275
src/plasmaquick/containmentview.cpp
Normal file
@ -0,0 +1,275 @@
|
||||
/*
|
||||
* Copyright 2013 Marco Martin <mart@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, 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 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 "containmentview.h"
|
||||
#include "configview.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QQuickItem>
|
||||
#include <QQmlContext>
|
||||
#include <QTimer>
|
||||
#include <QScreen>
|
||||
#include <QQmlEngine>
|
||||
|
||||
#include "plasma/pluginloader.h"
|
||||
#include <packageurlinterceptor.h>
|
||||
#include <kdeclarative/kdeclarative.h>
|
||||
|
||||
namespace PlasmaQuick
|
||||
{
|
||||
|
||||
class ContainmentViewPrivate
|
||||
{
|
||||
public:
|
||||
|
||||
ContainmentViewPrivate(Plasma::Corona *corona, ContainmentView *view);
|
||||
~ContainmentViewPrivate();
|
||||
|
||||
void setContainment(Plasma::Containment *cont);
|
||||
Plasma::Types::FormFactor formFactor() const;
|
||||
Plasma::Types::Location location() const;
|
||||
void showConfigurationInterface(Plasma::Applet *applet);
|
||||
void updateDestroyed(bool destroyed);
|
||||
|
||||
ContainmentView *q;
|
||||
friend class ContainmentView;
|
||||
Plasma::Corona *corona;
|
||||
QPointer<Plasma::Containment> containment;
|
||||
QPointer<ConfigView> configContainmentView;
|
||||
};
|
||||
|
||||
ContainmentViewPrivate::ContainmentViewPrivate(Plasma::Corona *cor, ContainmentView *view)
|
||||
: q(view),
|
||||
corona(cor)
|
||||
{
|
||||
}
|
||||
|
||||
ContainmentViewPrivate::~ContainmentViewPrivate()
|
||||
{
|
||||
}
|
||||
|
||||
void ContainmentViewPrivate::setContainment(Plasma::Containment *cont)
|
||||
{
|
||||
if (containment == cont) {
|
||||
return;
|
||||
}
|
||||
|
||||
Plasma::Types::Location oldLoc = location();
|
||||
Plasma::Types::FormFactor oldForm = formFactor();
|
||||
|
||||
if (containment) {
|
||||
QObject::disconnect(containment, 0, q, 0);
|
||||
QObject *oldGraphicObject = containment->property("_plasma_graphicObject").value<QObject *>();
|
||||
if (oldGraphicObject) {
|
||||
// qDebug() << "Old graphics Object:" << oldGraphicObject << "Old containment" << containment.data();
|
||||
//make sure the graphic object won't die with us
|
||||
//FIXME:we need a way to reparent to *NO* graphics item, but this makes Qt crash
|
||||
oldGraphicObject->setParent(containment);
|
||||
}
|
||||
containment->reactToScreenChange();
|
||||
}
|
||||
|
||||
containment = cont;
|
||||
|
||||
if (oldLoc != location()) {
|
||||
emit q->locationChanged(location());
|
||||
}
|
||||
if (oldForm != formFactor()) {
|
||||
emit q->formFactorChanged(formFactor());
|
||||
}
|
||||
|
||||
emit q->containmentChanged();
|
||||
|
||||
if (cont) {
|
||||
cont->reactToScreenChange();
|
||||
QObject::connect(cont, &Plasma::Containment::locationChanged,
|
||||
q, &ContainmentView::locationChanged);
|
||||
QObject::connect(cont, &Plasma::Containment::formFactorChanged,
|
||||
q, &ContainmentView::formFactorChanged);
|
||||
QObject::connect(cont, &Plasma::Containment::configureRequested,
|
||||
q, &ContainmentView::showConfigurationInterface);
|
||||
QObject::connect(cont, SIGNAL(destroyedChanged(bool)),
|
||||
q, SLOT(updateDestroyed(bool)));
|
||||
if (cont->containmentType() == Plasma::Types::PanelContainment ||
|
||||
cont->containmentType() == Plasma::Types::CustomPanelContainment) {
|
||||
q->setVisible(!cont->destroyed() && cont->isUiReady());
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
QQuickItem *graphicObject = qobject_cast<QQuickItem *>(containment->property("_plasma_graphicObject").value<QObject *>());
|
||||
|
||||
if (graphicObject) {
|
||||
// qDebug() << "using as graphic containment" << graphicObject << containment.data();
|
||||
|
||||
//by resizing before adding, it will avoid some resizes in most cases
|
||||
graphicObject->setProperty("width", q->width());
|
||||
graphicObject->setProperty("height", q->height());
|
||||
graphicObject->setParentItem(q->rootObject());
|
||||
if (q->rootObject()) {
|
||||
q->rootObject()->setProperty("containment", QVariant::fromValue(graphicObject));
|
||||
QObject *wpGraphicObject = containment->property("wallpaperGraphicsObject").value<QObject *>();
|
||||
if (wpGraphicObject) {
|
||||
q->rootObject()->setProperty("wallpaper", QVariant::fromValue(wpGraphicObject));
|
||||
}
|
||||
} else {
|
||||
qWarning() << "Could not set containment property on rootObject";
|
||||
}
|
||||
} else {
|
||||
qWarning() << "Containment graphic object not valid";
|
||||
}
|
||||
}
|
||||
|
||||
Plasma::Types::Location ContainmentViewPrivate::location() const
|
||||
{
|
||||
if (!containment) {
|
||||
return Plasma::Types::Desktop;
|
||||
}
|
||||
return containment->location();
|
||||
}
|
||||
|
||||
Plasma::Types::FormFactor ContainmentViewPrivate::formFactor() const
|
||||
{
|
||||
if (!containment) {
|
||||
return Plasma::Types::Planar;
|
||||
}
|
||||
return containment->formFactor();
|
||||
}
|
||||
|
||||
void ContainmentViewPrivate::showConfigurationInterface(Plasma::Applet *applet)
|
||||
{
|
||||
if (configContainmentView) {
|
||||
if (configContainmentView->applet() != applet) {
|
||||
configContainmentView->hide();
|
||||
configContainmentView->deleteLater();
|
||||
} else {
|
||||
configContainmentView->requestActivate();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!applet || !applet->containment()) {
|
||||
return;
|
||||
}
|
||||
|
||||
configContainmentView = new ConfigView(applet);
|
||||
|
||||
configContainmentView->init();
|
||||
configContainmentView->show();
|
||||
}
|
||||
|
||||
void ContainmentViewPrivate::updateDestroyed(bool destroyed)
|
||||
{
|
||||
q->setVisible(!destroyed);
|
||||
}
|
||||
|
||||
ContainmentView::ContainmentView(Plasma::Corona *corona, QWindow *parent)
|
||||
: KQuickAddons::QuickViewSharedEngine(parent),
|
||||
d(new ContainmentViewPrivate(corona, this))
|
||||
{
|
||||
setColor(Qt::transparent);
|
||||
|
||||
QObject::connect(screen(), &QScreen::geometryChanged,
|
||||
this, &ContainmentView::screenGeometryChanged);
|
||||
|
||||
if (corona->package().isValid()) {
|
||||
KDeclarative::KDeclarative kdeclarative;
|
||||
kdeclarative.setDeclarativeEngine(engine());
|
||||
//binds things like kconfig and icons
|
||||
kdeclarative.setTranslationDomain("plasma_shell_" + corona->package().metadata().pluginName());
|
||||
kdeclarative.setupBindings();
|
||||
} else {
|
||||
qWarning() << "Invalid home screen package";
|
||||
}
|
||||
|
||||
//Force QtQuickControls to use the "Plasma" style for this engine.
|
||||
//this way is possible to mix QtQuickControls and plasma components in applets
|
||||
//while still having the desktop style in configuration dialogs
|
||||
QQmlComponent c(engine());
|
||||
c.setData("import QtQuick 2.1\n\
|
||||
import QtQuick.Controls 1.0\n\
|
||||
import QtQuick.Controls.Private 1.0\n \
|
||||
Item {\
|
||||
Component.onCompleted: {\
|
||||
Settings.styleName = \"Plasma\";\
|
||||
}\
|
||||
}", QUrl());
|
||||
QObject *o = c.create();
|
||||
o->deleteLater();
|
||||
|
||||
setResizeMode(ContainmentView::SizeRootObjectToView);
|
||||
}
|
||||
|
||||
ContainmentView::~ContainmentView()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
Plasma::Corona *ContainmentView::corona() const
|
||||
{
|
||||
return d->corona;
|
||||
}
|
||||
|
||||
KConfigGroup ContainmentView::config() const
|
||||
{
|
||||
if (!containment()) {
|
||||
return KConfigGroup();
|
||||
}
|
||||
KConfigGroup views(KSharedConfig::openConfig(), "PlasmaContainmentViews");
|
||||
return KConfigGroup(&views, QString::number(containment()->screen()));
|
||||
}
|
||||
|
||||
void ContainmentView::setContainment(Plasma::Containment *cont)
|
||||
{
|
||||
d->setContainment(cont);
|
||||
}
|
||||
|
||||
Plasma::Containment *ContainmentView::containment() const
|
||||
{
|
||||
return d->containment;
|
||||
}
|
||||
|
||||
void ContainmentView::setLocation(Plasma::Types::Location location)
|
||||
{
|
||||
d->containment->setLocation(location);
|
||||
}
|
||||
|
||||
Plasma::Types::Location ContainmentView::location() const
|
||||
{
|
||||
return d->location();
|
||||
}
|
||||
|
||||
Plasma::Types::FormFactor ContainmentView::formFactor() const
|
||||
{
|
||||
return d->formFactor();
|
||||
}
|
||||
|
||||
QRectF ContainmentView::screenGeometry()
|
||||
{
|
||||
return screen()->geometry();
|
||||
}
|
||||
|
||||
void ContainmentView::showConfigurationInterface(Plasma::Applet *applet)
|
||||
{
|
||||
d->showConfigurationInterface(applet);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include "moc_containmentview.cpp"
|
136
src/plasmaquick/containmentview.h
Normal file
136
src/plasmaquick/containmentview.h
Normal file
@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Copyright 2012 Marco Martin <mart@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, 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 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 PLASMAQUICKCONTAINMENTVIEW_H
|
||||
#define PLASMAQUICKCONTAINMENTVIEW_H
|
||||
|
||||
#include <kquickaddons/quickviewsharedengine.h>
|
||||
|
||||
#include <plasmaquick_export.h>
|
||||
#include "plasma/corona.h"
|
||||
#include "plasma/containment.h"
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the public Plasma API. It exists purely as an
|
||||
// implementation detail. This header file may change from version to
|
||||
// version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
namespace PlasmaQuick
|
||||
{
|
||||
|
||||
class ContainmentViewPrivate;
|
||||
|
||||
class PLASMAQUICK_EXPORT ContainmentView : public KQuickAddons::QuickViewSharedEngine
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(Plasma::Types::Location location READ location WRITE setLocation NOTIFY locationChanged)
|
||||
Q_PROPERTY(Plasma::Types::FormFactor formFactor READ formFactor NOTIFY formFactorChanged)
|
||||
Q_PROPERTY(QRectF screenGeometry READ screenGeometry NOTIFY screenGeometryChanged)
|
||||
|
||||
public:
|
||||
/**
|
||||
* @param corona the corona of this view
|
||||
* @param parent the QWindow this ContainmentView is parented to
|
||||
**/
|
||||
explicit ContainmentView(Plasma::Corona *corona, QWindow *parent = 0);
|
||||
virtual ~ContainmentView();
|
||||
|
||||
/**
|
||||
* @return the corona of this view
|
||||
**/
|
||||
Plasma::Corona *corona() const;
|
||||
|
||||
/**
|
||||
* @return the KConfigGroup of this view
|
||||
**/
|
||||
virtual KConfigGroup config() const;
|
||||
|
||||
/**
|
||||
* sets the containment for this view
|
||||
* @param cont the containment of this view
|
||||
**/
|
||||
void setContainment(Plasma::Containment *cont);
|
||||
|
||||
/**
|
||||
* @return the containment of this ContainmentView
|
||||
**/
|
||||
Plasma::Containment *containment() const;
|
||||
|
||||
/**
|
||||
* @return the location of this ContainmentView
|
||||
**/
|
||||
Plasma::Types::Location location() const;
|
||||
|
||||
/**
|
||||
* Sets the location of the ContainmentView
|
||||
* @param location the location of the ContainmentView
|
||||
**/
|
||||
void setLocation(Plasma::Types::Location location);
|
||||
|
||||
/**
|
||||
* @return the formfactor of the ContainmentView
|
||||
**/
|
||||
Plasma::Types::FormFactor formFactor() const;
|
||||
|
||||
/**
|
||||
* @return the screenGeometry of the ContainmentView
|
||||
**/
|
||||
QRectF screenGeometry();
|
||||
|
||||
protected Q_SLOTS:
|
||||
/**
|
||||
* It will be called when the configuration is requested
|
||||
*/
|
||||
virtual void showConfigurationInterface(Plasma::Applet *applet);
|
||||
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
* emitted when the location is changed
|
||||
**/
|
||||
void locationChanged(Plasma::Types::Location location);
|
||||
|
||||
/**
|
||||
* emitted when the formfactor is changed
|
||||
**/
|
||||
void formFactorChanged(Plasma::Types::FormFactor formFactor);
|
||||
|
||||
/**
|
||||
* emitted when the containment is changed
|
||||
**/
|
||||
void containmentChanged();
|
||||
|
||||
/**
|
||||
* emitted when the screenGeometry is changed
|
||||
**/
|
||||
void screenGeometryChanged();
|
||||
|
||||
private:
|
||||
ContainmentViewPrivate *const d;
|
||||
Q_PRIVATE_SLOT(d, void updateDestroyed(bool))
|
||||
friend class ContainmentViewPrivate;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // CONTAINMENTVIEW_H
|
@ -53,77 +53,77 @@ public:
|
||||
* @param corona the corona of this view
|
||||
* @param parent the QWindow this View is parented to
|
||||
**/
|
||||
explicit View(Plasma::Corona *corona, QWindow *parent = 0);
|
||||
virtual ~View();
|
||||
PLASMA_DEPRECATED explicit View(Plasma::Corona *corona, QWindow *parent = 0);
|
||||
PLASMA_DEPRECATED virtual ~View();
|
||||
|
||||
/**
|
||||
* @return the corona of this view
|
||||
**/
|
||||
Plasma::Corona *corona() const;
|
||||
PLASMA_DEPRECATED Plasma::Corona *corona() const;
|
||||
|
||||
/**
|
||||
* @return the KConfigGroup of this view
|
||||
**/
|
||||
virtual KConfigGroup config() const;
|
||||
PLASMA_DEPRECATED virtual KConfigGroup config() const;
|
||||
|
||||
/**
|
||||
* sets the containment for this view
|
||||
* @param cont the containment of this view
|
||||
**/
|
||||
void setContainment(Plasma::Containment *cont);
|
||||
PLASMA_DEPRECATED void setContainment(Plasma::Containment *cont);
|
||||
|
||||
/**
|
||||
* @return the containment of this View
|
||||
**/
|
||||
Plasma::Containment *containment() const;
|
||||
PLASMA_DEPRECATED Plasma::Containment *containment() const;
|
||||
|
||||
/**
|
||||
* @return the location of this View
|
||||
**/
|
||||
Plasma::Types::Location location() const;
|
||||
PLASMA_DEPRECATED Plasma::Types::Location location() const;
|
||||
|
||||
/**
|
||||
* Sets the location of the View
|
||||
* @param location the location of the View
|
||||
**/
|
||||
void setLocation(Plasma::Types::Location location);
|
||||
PLASMA_DEPRECATED void setLocation(Plasma::Types::Location location);
|
||||
|
||||
/**
|
||||
* @return the formfactor of the View
|
||||
**/
|
||||
Plasma::Types::FormFactor formFactor() const;
|
||||
PLASMA_DEPRECATED Plasma::Types::FormFactor formFactor() const;
|
||||
|
||||
/**
|
||||
* @return the screenGeometry of the View
|
||||
**/
|
||||
QRectF screenGeometry();
|
||||
PLASMA_DEPRECATED QRectF screenGeometry();
|
||||
|
||||
protected Q_SLOTS:
|
||||
/**
|
||||
* It will be called when the configuration is requested
|
||||
*/
|
||||
virtual void showConfigurationInterface(Plasma::Applet *applet);
|
||||
PLASMA_DEPRECATED virtual void showConfigurationInterface(Plasma::Applet *applet);
|
||||
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
* emitted when the location is changed
|
||||
**/
|
||||
void locationChanged(Plasma::Types::Location location);
|
||||
PLASMA_DEPRECATED void locationChanged(Plasma::Types::Location location);
|
||||
|
||||
/**
|
||||
* emitted when the formfactor is changed
|
||||
**/
|
||||
void formFactorChanged(Plasma::Types::FormFactor formFactor);
|
||||
PLASMA_DEPRECATED void formFactorChanged(Plasma::Types::FormFactor formFactor);
|
||||
|
||||
/**
|
||||
* emitted when the containment is changed
|
||||
**/
|
||||
void containmentChanged();
|
||||
PLASMA_DEPRECATED void containmentChanged();
|
||||
|
||||
/**
|
||||
* emitted when the screenGeometry is changed
|
||||
**/
|
||||
void screenGeometryChanged();
|
||||
PLASMA_DEPRECATED void screenGeometryChanged();
|
||||
|
||||
private:
|
||||
ViewPrivate *const d;
|
||||
|
Loading…
Reference in New Issue
Block a user