~ubuntu-branches/ubuntu/raring/plasma-mobile/raring-proposed

« back to all changes in this revision

Viewing changes to applications/common/kdeclarativeview.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2012-07-17 12:04:43 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120717120443-q3ig9u2fnltx67yg
Tags: 2.0+git2012071701-0ubuntu1
* New upstream snapshot
* Remove build-dep on kde-runtime-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *                                                                         *
 
3
 *   Copyright 2011 Sebastian Kügler <sebas@kde.org>                       *
 
4
 *   Copyright 2011 Marco Martin <mart@kde.org>                            *
 
5
 *                                                                         *
 
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.                                   *
 
10
 *                                                                         *
 
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.                          *
 
15
 *                                                                         *
 
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
 ***************************************************************************/
 
21
 
 
22
#include "kdeclarativeview.h"
 
23
#include "dataenginebindings_p.h"
 
24
 
 
25
#include <QDeclarativeContext>
 
26
#include <QDeclarativeEngine>
 
27
#include <QDeclarativeItem>
 
28
#include <QGLWidget>
 
29
 
 
30
#include <KDebug>
 
31
 
 
32
#include  <kdeclarative.h>
 
33
 
 
34
#include <Plasma/Package>
 
35
 
 
36
class KDeclarativeViewPrivate
 
37
{
 
38
public:
 
39
    KDeclarativeViewPrivate()
 
40
        : useGL(false)
 
41
    {}
 
42
 
 
43
    KDeclarative kdeclarative;
 
44
    Plasma::PackageStructure::Ptr structure;
 
45
    Plasma::Package *package;
 
46
    QString packageName;
 
47
    bool useGL;
 
48
};
 
49
 
 
50
KDeclarativeView::KDeclarativeView(QWidget *parent)
 
51
    : QDeclarativeView(parent),
 
52
      d(new KDeclarativeViewPrivate)
 
53
{
 
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);
 
59
 
 
60
    setResizeMode(QDeclarativeView::SizeRootObjectToView);
 
61
 
 
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);
 
68
 
 
69
    d->structure = Plasma::PackageStructure::load("Plasma/Generic");
 
70
 
 
71
    show();
 
72
}
 
73
 
 
74
KDeclarativeView::~KDeclarativeView()
 
75
{
 
76
}
 
77
 
 
78
 
 
79
void KDeclarativeView::setPackageName(const QString &packageName)
 
80
{
 
81
    d->package = new Plasma::Package(QString(), packageName, d->structure);
 
82
    d->packageName = packageName;
 
83
    setSource(QUrl(d->package->filePath("mainscript")));
 
84
}
 
85
 
 
86
QString KDeclarativeView::packageName() const
 
87
{
 
88
    return d->packageName;
 
89
}
 
90
 
 
91
void KDeclarativeView::setPackage(Plasma::Package *package)
 
92
{
 
93
    if (!package || package == d->package) {
 
94
        return;
 
95
    }
 
96
 
 
97
    d->package = package;
 
98
    d->packageName = package->metadata().pluginName();
 
99
    setSource(QUrl(d->package->filePath("mainscript")));
 
100
}
 
101
 
 
102
Plasma::Package *KDeclarativeView::package() const
 
103
{
 
104
    return d->package;
 
105
}
 
106
 
 
107
void KDeclarativeView::setUseGL(const bool on)
 
108
{
 
109
#ifndef QT_NO_OPENGL
 
110
    if (on) {
 
111
      QGLWidget *glWidget = new QGLWidget;
 
112
      glWidget->setAutoFillBackground(false);
 
113
      setViewport(glWidget);
 
114
    }
 
115
#endif
 
116
    d->useGL = on;
 
117
}
 
118
 
 
119
bool KDeclarativeView::useGL() const
 
120
{
 
121
    return d->useGL;
 
122
}
 
123
 
 
124
QSize KDeclarativeView::sizeHint() const
 
125
{
 
126
    return QSize(800, 600);
 
127
}
 
128
 
 
129
QScriptEngine *KDeclarativeView::scriptEngine() const
 
130
{
 
131
    return d->kdeclarative.scriptEngine();
 
132
}
 
133
 
 
134
#include "kdeclarativeview.moc"