1
/***************************************************************************
3
* Copyright 2011 Sebastian Kügler <sebas@kde.org> *
4
* Copyright 2011 Marco Martin <mart@kde.org> *
6
* This program is free software; you can redistribute it and/or modify *
7
* it under the terms of the GNU General Public License as published by *
8
* the Free Software Foundation; either version 2 of the License, or *
9
* (at your option) any later version. *
11
* This program is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU General Public License for more details. *
16
* You should have received a copy of the GNU General Public License *
17
* along with this program; if not, write to the *
18
* Free Software Foundation, Inc., *
19
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
20
***************************************************************************/
22
#include "kdeclarativeview.h"
23
#include "dataenginebindings_p.h"
25
#include <QDeclarativeContext>
26
#include <QDeclarativeEngine>
27
#include <QDeclarativeItem>
32
#include <kdeclarative.h>
34
#include <Plasma/Package>
36
class KDeclarativeViewPrivate
39
KDeclarativeViewPrivate()
43
KDeclarative kdeclarative;
44
Plasma::PackageStructure::Ptr structure;
45
Plasma::Package *package;
50
KDeclarativeView::KDeclarativeView(QWidget *parent)
51
: QDeclarativeView(parent),
52
d(new KDeclarativeViewPrivate)
54
// avoid flicker on show
55
setAttribute(Qt::WA_OpaquePaintEvent);
56
setAttribute(Qt::WA_NoSystemBackground);
57
viewport()->setAttribute(Qt::WA_OpaquePaintEvent);
58
viewport()->setAttribute(Qt::WA_NoSystemBackground);
60
setResizeMode(QDeclarativeView::SizeRootObjectToView);
62
d->kdeclarative.setDeclarativeEngine(engine());
63
d->kdeclarative.initialize();
64
//binds things like kconfig and icons
65
d->kdeclarative.setupBindings();
66
QScriptEngine *scriptEngine = d->kdeclarative.scriptEngine();
67
registerDataEngineMetaTypes(scriptEngine);
69
d->structure = Plasma::PackageStructure::load("Plasma/Generic");
74
KDeclarativeView::~KDeclarativeView()
79
void KDeclarativeView::setPackageName(const QString &packageName)
81
d->package = new Plasma::Package(QString(), packageName, d->structure);
82
d->packageName = packageName;
83
setSource(QUrl(d->package->filePath("mainscript")));
86
QString KDeclarativeView::packageName() const
88
return d->packageName;
91
void KDeclarativeView::setPackage(Plasma::Package *package)
93
if (!package || package == d->package) {
98
d->packageName = package->metadata().pluginName();
99
setSource(QUrl(d->package->filePath("mainscript")));
102
Plasma::Package *KDeclarativeView::package() const
107
void KDeclarativeView::setUseGL(const bool on)
111
QGLWidget *glWidget = new QGLWidget;
112
glWidget->setAutoFillBackground(false);
113
setViewport(glWidget);
119
bool KDeclarativeView::useGL() const
124
QSize KDeclarativeView::sizeHint() const
126
return QSize(800, 600);
129
QScriptEngine *KDeclarativeView::scriptEngine() const
131
return d->kdeclarative.scriptEngine();
134
#include "kdeclarativeview.moc"