~ubuntu-branches/ubuntu/wily/kdeclarative/wily-proposed

« back to all changes in this revision

Viewing changes to src/quickaddons/quickviewsharedengine.cpp

  • Committer: Package Import Robot
  • Author(s): Scarlett Clark, Scarlett Clark, José Manuel Santamaría Lema
  • Date: 2015-08-03 14:27:13 UTC
  • mfrom: (1.1.11) (6.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20150803142713-wtg3ud70lc8ok0pq
Tags: 5.12.0-0ubuntu1
[ Scarlett Clark ]
* New upstream release
* Fix merge, remove unused broken backport.

[ José Manuel Santamaría Lema ]
* Update symbols file:
  - Mark as optional the symbols gone after building with GCC 5
  - Add new symbols, mark as optional those sho doesn't show up
    after rebuilding with GCC 4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   This file is part of the KDE libraries
 
3
 
 
4
   Copyright (C) 2015 Marco Martin <mart@kde.org>
 
5
 
 
6
   This library is free software; you can redistribute it and/or
 
7
   modify it under the terms of the GNU Library General Public
 
8
   License as published by the Free Software Foundation; either
 
9
   version 2 of the License, or (at your option) any later version.
 
10
 
 
11
   This library 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 GNU
 
14
   Library General Public License for more details.
 
15
 
 
16
   You should have received a copy of the GNU Library General Public License
 
17
   along with this library; see the file COPYING.LIB.  If not, write to
 
18
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
19
   Boston, MA 02110-1301, USA.
 
20
 
 
21
*/
 
22
 
 
23
#include "quickviewsharedengine.h"
 
24
 
 
25
#include <QTimer>
 
26
#include <QDebug>
 
27
#include <QUrl>
 
28
#include <QQmlEngine>
 
29
#include <QQmlContext>
 
30
#include <QQuickItem>
 
31
#include <QQmlEngine>
 
32
#include <QQmlExpression>
 
33
#include <QQmlProperty>
 
34
 
 
35
#include <klocalizedstring.h>
 
36
#include <kdeclarative/qmlobjectsharedengine.h>
 
37
 
 
38
#include <KPackage/Package>
 
39
#include <KPackage/PackageLoader>
 
40
 
 
41
namespace KQuickAddons {
 
42
 
 
43
class QuickViewSharedEnginePrivate
 
44
{
 
45
public:
 
46
    QuickViewSharedEnginePrivate(QuickViewSharedEngine *module)
 
47
        : q(module),
 
48
          initialSize(0, 0)
 
49
    {
 
50
        qmlObject = new KDeclarative::QmlObjectSharedEngine(q);
 
51
        QObject::connect(qmlObject, &KDeclarative::QmlObject::statusChanged,
 
52
                         q, &QuickViewSharedEngine::statusChanged);
 
53
        QObject::connect(qmlObject, SIGNAL(finished()),
 
54
                         q, SLOT(executionFinished()));
 
55
    }
 
56
 
 
57
    void executionFinished();
 
58
    void syncResizeMode();
 
59
    void syncWidth();
 
60
    void syncHeight();
 
61
 
 
62
 
 
63
    QuickViewSharedEngine *q;
 
64
    KDeclarative::QmlObjectSharedEngine *qmlObject;
 
65
    QuickViewSharedEngine::ResizeMode resizeMode;
 
66
    QSize initialSize;
 
67
};
 
68
 
 
69
void QuickViewSharedEnginePrivate::executionFinished()
 
70
{
 
71
    if (!qmlObject->rootObject()) {
 
72
        return;
 
73
    }
 
74
 
 
75
    QQuickItem *item = qobject_cast<QQuickItem *>(qmlObject->rootObject());
 
76
 
 
77
    if (!item) {
 
78
        return;
 
79
    }
 
80
 
 
81
    item->setParentItem(q->contentItem());
 
82
    initialSize = QSize(item->width(), item ->height());
 
83
    q->resize(initialSize);
 
84
    q->contentItem()->setWidth(item->width());
 
85
    q->contentItem()->setHeight(item->height());
 
86
 
 
87
    syncResizeMode();
 
88
}
 
89
 
 
90
void QuickViewSharedEnginePrivate::syncResizeMode()
 
91
{
 
92
    QQuickItem *item = qobject_cast<QQuickItem *>(qmlObject->rootObject());
 
93
 
 
94
    if (!item) {
 
95
        return;
 
96
    }
 
97
 
 
98
    if (resizeMode == QuickViewSharedEngine::SizeRootObjectToView) {
 
99
        item->setWidth(q->width());
 
100
        item->setHeight(q->height());
 
101
 
 
102
        QObject::disconnect(item, SIGNAL(widthChanged()),
 
103
                            q, SLOT(syncWidth()));
 
104
        QObject::disconnect(item, SIGNAL(heightChanged()),
 
105
                            q, SLOT(syncHeight()));
 
106
 
 
107
    } else {
 
108
 
 
109
        QObject::connect(item, SIGNAL(widthChanged()),
 
110
                         q, SLOT(syncWidth()));
 
111
        QObject::connect(item, SIGNAL(heightChanged()),
 
112
                         q, SLOT(syncHeight()));
 
113
 
 
114
        syncWidth();
 
115
        syncHeight();
 
116
    }
 
117
}
 
118
 
 
119
void QuickViewSharedEnginePrivate::syncWidth()
 
120
{
 
121
    QQuickItem *item = qobject_cast<QQuickItem *>(qmlObject->rootObject());
 
122
 
 
123
    if (!item) {
 
124
        return;
 
125
    }
 
126
 
 
127
    q->setWidth(item->width());
 
128
}
 
129
 
 
130
void QuickViewSharedEnginePrivate::syncHeight()
 
131
{
 
132
    QQuickItem *item = qobject_cast<QQuickItem *>(qmlObject->rootObject());
 
133
 
 
134
    if (!item) {
 
135
        return;
 
136
    }
 
137
 
 
138
    q->setHeight(item->height());
 
139
}
 
140
 
 
141
 
 
142
 
 
143
QuickViewSharedEngine::QuickViewSharedEngine(QWindow *parent)
 
144
    : QQuickWindow(parent),
 
145
      d(new QuickViewSharedEnginePrivate(this))
 
146
{
 
147
}
 
148
 
 
149
QuickViewSharedEngine::~QuickViewSharedEngine()
 
150
{
 
151
}
 
152
 
 
153
 
 
154
QQmlEngine *QuickViewSharedEngine::engine() const
 
155
{
 
156
    return d->qmlObject->engine();
 
157
}
 
158
 
 
159
QList<QQmlError> QuickViewSharedEngine::errors() const
 
160
{
 
161
    QList<QQmlError> errs;
 
162
 
 
163
    if (d->qmlObject->mainComponent()) {
 
164
        errs = d->qmlObject->mainComponent()->errors();
 
165
    }
 
166
 
 
167
    return errs;
 
168
}
 
169
 
 
170
QSize QuickViewSharedEngine::sizeHint() const
 
171
{
 
172
    QQuickItem *item = qobject_cast<QQuickItem *>(d->qmlObject->rootObject());
 
173
    if (!item) {
 
174
        return QSize();
 
175
    }
 
176
 
 
177
    const QSizeF implicitSize(item->implicitWidth(), item->implicitHeight());
 
178
 
 
179
    if (!implicitSize.isEmpty()) {
 
180
        return implicitSize.toSize();
 
181
    }
 
182
 
 
183
    if (item) {
 
184
        return QSize(item->width(), item->height());
 
185
    } else {
 
186
        return size();
 
187
    }
 
188
}
 
189
 
 
190
QSize QuickViewSharedEngine::initialSize() const
 
191
{
 
192
    return d->initialSize;
 
193
}
 
194
 
 
195
QuickViewSharedEngine::ResizeMode QuickViewSharedEngine::resizeMode() const
 
196
{
 
197
    return d->resizeMode;
 
198
}
 
199
 
 
200
QQmlContext *QuickViewSharedEngine::rootContext() const
 
201
{
 
202
    return d->qmlObject->rootContext();
 
203
}
 
204
 
 
205
QQuickItem *QuickViewSharedEngine::rootObject() const
 
206
{
 
207
     return qobject_cast<QQuickItem *>(d->qmlObject->rootObject());
 
208
}
 
209
 
 
210
void QuickViewSharedEngine::setResizeMode(ResizeMode mode)
 
211
{
 
212
    if (d->resizeMode == mode) {
 
213
        return;
 
214
    }
 
215
 
 
216
    d->resizeMode = mode;
 
217
 
 
218
    emit resizeModeChanged(mode);
 
219
 
 
220
    QQuickItem *item = qobject_cast<QQuickItem *>(d->qmlObject->rootObject());
 
221
    if (!item) {
 
222
        return;
 
223
    }
 
224
 
 
225
    d->syncResizeMode();
 
226
}
 
227
 
 
228
void QuickViewSharedEngine::setSource(const QUrl &url)
 
229
{
 
230
    if (d->qmlObject->source() == url) {
 
231
        return;
 
232
    }
 
233
 
 
234
    d->qmlObject->setSource(url);
 
235
    emit sourceChanged(url);
 
236
}
 
237
 
 
238
QUrl QuickViewSharedEngine::source() const
 
239
{
 
240
    return d->qmlObject->source();
 
241
}
 
242
 
 
243
QQmlComponent::Status QuickViewSharedEngine::status() const
 
244
{
 
245
    if (!d->qmlObject->mainComponent()) {
 
246
        return QQmlComponent::Null;
 
247
    }
 
248
 
 
249
    return QQmlComponent::Status(d->qmlObject->status());
 
250
}
 
251
 
 
252
void QuickViewSharedEngine::resizeEvent(QResizeEvent *e)
 
253
{
 
254
    QQuickItem *item = qobject_cast<QQuickItem *>(d->qmlObject->rootObject());
 
255
    if (item && d->resizeMode == SizeRootObjectToView) {
 
256
        item->setWidth(e->size().width());
 
257
        item->setHeight(e->size().height());
 
258
    }
 
259
 
 
260
    QQuickWindow::resizeEvent(e);
 
261
}
 
262
 
 
263
}
 
264
 
 
265
#include "moc_quickviewsharedengine.cpp"
 
266