plasma-framework/src/plasmaquick/configview.cpp

171 lines
4.7 KiB
C++
Raw Normal View History

/*
* 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 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.
*/
2013-09-11 15:18:19 +02:00
#include "private/configcategory_p.h"
#include "configview.h"
2013-09-11 14:40:11 +02:00
#include "configmodel.h"
#include "Plasma/Applet"
#include "Plasma/Containment"
//#include "plasmoid/wallpaperinterface.h"
#include "kdeclarative/configpropertymap.h"
#include <QDebug>
2013-02-28 21:24:30 +01:00
#include <QDir>
#include <QQmlComponent>
#include <QQmlEngine>
#include <QQmlContext>
#include <QQuickItem>
2013-10-05 04:28:26 +02:00
#include <klocalizedstring.h>
#include <kdeclarative/kdeclarative.h>
#include <Plasma/Corona>
2013-02-28 21:24:30 +01:00
#include <Plasma/PluginLoader>
namespace PlasmaQuick
{
//////////////////////////////ConfigView
2013-08-27 21:07:55 +02:00
class ConfigViewPrivate
{
public:
ConfigViewPrivate(Plasma::Applet *appl, ConfigView *view);
~ConfigViewPrivate();
void init();
ConfigView *q;
QWeakPointer <Plasma::Applet> applet;
2013-08-27 21:07:55 +02:00
ConfigModel *configModel;
};
ConfigViewPrivate::ConfigViewPrivate(Plasma::Applet *appl, ConfigView *view)
: q(view),
applet(appl)
{
}
void ConfigViewPrivate::init()
{
applet.data()->setUserConfiguring(true);
2013-08-27 21:07:55 +02:00
2014-01-13 21:21:14 +01:00
KDeclarative::KDeclarative kdeclarative;
2013-08-27 21:07:55 +02:00
kdeclarative.setDeclarativeEngine(q->engine());
kdeclarative.setupBindings();
2013-03-14 11:11:15 +01:00
qmlRegisterType<ConfigModel>("org.kde.plasma.configuration", 2, 0, "ConfigModel");
qmlRegisterType<ConfigCategory>("org.kde.plasma.configuration", 2, 0, "ConfigCategory");
//FIXME: problem on nvidia, all windows should be transparent or won't show
2013-08-27 21:07:55 +02:00
q->setColor(Qt::transparent);
q->setTitle(i18n("%1 Settings", applet.data()->title()));
if (!applet.data()->containment()->corona()->package().isValid()) {
qWarning() << "Invalid home screen package";
}
2013-08-27 21:07:55 +02:00
q->setResizeMode(QQuickView::SizeViewToRootObject);
2013-02-28 21:24:30 +01:00
//config model local of the applet
QQmlComponent *component = new QQmlComponent(q->engine(), QUrl::fromLocalFile(applet.data()->package().filePath("configmodel")), q);
2013-08-27 21:07:55 +02:00
QObject *object = component->beginCreate(q->engine()->rootContext());
configModel = qobject_cast<ConfigModel *>(object);
if (configModel) {
configModel->setApplet(applet.data());
2013-02-27 18:31:13 +01:00
} else {
delete object;
}
q->engine()->rootContext()->setContextProperty("plasmoid", applet.data()->property("_plasma_graphicObject").value<QObject*>());
2013-08-27 21:07:55 +02:00
q->engine()->rootContext()->setContextProperty("configDialog", q);
2013-05-03 18:07:47 +02:00
component->completeCreate();
delete component;
}
2013-08-27 21:07:55 +02:00
ConfigView::ConfigView(Plasma::Applet *applet, QWindow *parent)
: QQuickView(parent),
d(new ConfigViewPrivate(applet, this))
{
d->init();
qmlRegisterType<ConfigModel>("org.kde.plasma.configuration", 2, 0, "ConfigModel");
qmlRegisterType<ConfigCategory>("org.kde.plasma.configuration", 2, 0, "ConfigCategory");
connect(applet, &QObject::destroyed, this, &ConfigView::close);
2013-08-27 21:07:55 +02:00
}
ConfigView::~ConfigView()
{
if (d->applet) {
d->applet.data()->setUserConfiguring(false);
}
}
void ConfigView::init()
{
setSource(QUrl::fromLocalFile(d->applet.data()->containment()->corona()->package().filePath("appletconfigurationui")));
}
ConfigModel *ConfigView::configModel() const
{
2013-08-27 21:07:55 +02:00
return d->configModel;
}
QString ConfigView::appletGlobalShortcut() const
{
if (!d->applet) {
return QString();
}
return d->applet.data()->globalShortcut().toString();
}
void ConfigView::setAppletGlobalShortcut(const QString &shortcut)
{
if (!d->applet || d->applet.data()->globalShortcut().toString().toLower() == shortcut.toLower()) {
return;
}
d->applet.data()->setGlobalShortcut(shortcut);
emit appletGlobalShortcutChanged();
}
//To emulate Qt::WA_DeleteOnClose that QWindow doesn't have
void ConfigView::hideEvent(QHideEvent *ev)
{
QQuickWindow::hideEvent(ev);
deleteLater();
}
void ConfigView::resizeEvent(QResizeEvent *re)
{
if (!rootObject()) {
return;
}
rootObject()->setWidth(re->size().width());
rootObject()->setHeight(re->size().height());
QQuickWindow::resizeEvent(re);
}
}
#include "moc_configview.cpp"