Skip to content

Latest commit

 

History

History
2384 lines (1951 loc) · 77.1 KB

qquickcanvas.cpp

File metadata and controls

2384 lines (1951 loc) · 77.1 KB
 
Apr 27, 2011
Apr 27, 2011
1
2
/****************************************************************************
**
Jan 17, 2012
Jan 17, 2012
3
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
Jan 23, 2012
Jan 23, 2012
4
** Contact: http://www.qt-project.org/
Apr 27, 2011
Apr 27, 2011
5
**
Feb 24, 2012
Feb 24, 2012
6
** This file is part of the QtQml module of the Qt Toolkit.
Apr 27, 2011
Apr 27, 2011
7
8
9
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
Jul 8, 2011
Jul 8, 2011
10
11
12
13
14
15
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
Apr 27, 2011
Apr 27, 2011
16
17
**
** In addition, as a special exception, Nokia gives you certain additional
Jul 8, 2011
Jul 8, 2011
18
** rights. These rights are described in the Nokia Qt LGPL Exception
Apr 27, 2011
Apr 27, 2011
19
20
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
Jul 8, 2011
Jul 8, 2011
21
22
23
24
25
26
27
28
29
30
31
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
Apr 27, 2011
Apr 27, 2011
32
33
34
35
36
**
**
**
**
**
Jan 30, 2012
Jan 30, 2012
37
**
Apr 27, 2011
Apr 27, 2011
38
39
40
41
** $QT_END_LICENSE$
**
****************************************************************************/
Oct 21, 2011
Oct 21, 2011
42
43
#include "qquickcanvas.h"
#include "qquickcanvas_p.h"
Apr 27, 2011
Apr 27, 2011
44
Oct 21, 2011
Oct 21, 2011
45
46
#include "qquickitem.h"
#include "qquickitem_p.h"
Feb 10, 2012
Feb 10, 2012
47
#include "qquickevents_p_p.h"
Apr 27, 2011
Apr 27, 2011
48
Dec 12, 2011
Dec 12, 2011
49
50
51
52
#include <QtQuick/private/qsgrenderer_p.h>
#include <QtQuick/private/qsgtexture_p.h>
#include <QtQuick/private/qsgflashnode_p.h>
#include <QtQuick/qsgengine.h>
Dec 8, 2011
Dec 8, 2011
53
54
#include <private/qquickwindowmanager_p.h>
Apr 27, 2011
Apr 27, 2011
55
Aug 5, 2011
Aug 5, 2011
56
#include <private/qguiapplication_p.h>
Feb 10, 2012
Feb 10, 2012
57
#include <QtGui/QInputMethod>
Feb 20, 2012
Feb 20, 2012
58
#include <QtGui/QCursor>
Aug 5, 2011
Aug 5, 2011
59
May 2, 2011
May 2, 2011
60
61
#include <private/qabstractanimation_p.h>
Apr 27, 2011
Apr 27, 2011
62
#include <QtGui/qpainter.h>
Sep 1, 2011
Sep 1, 2011
63
#include <QtGui/qevent.h>
Apr 27, 2011
Apr 27, 2011
64
#include <QtGui/qmatrix4x4.h>
Feb 10, 2012
Feb 10, 2012
65
#include <QtGui/qstylehints.h>
Apr 27, 2011
Apr 27, 2011
66
67
#include <QtCore/qvarlengtharray.h>
#include <QtCore/qabstractanimation.h>
Feb 24, 2012
Feb 24, 2012
68
#include <QtQml/qqmlincubator.h>
Apr 27, 2011
Apr 27, 2011
69
Feb 24, 2012
Feb 24, 2012
70
#include <QtQuick/private/qquickpixmapcache_p.h>
Feb 15, 2012
Feb 15, 2012
71
Feb 24, 2012
Feb 24, 2012
72
#include <private/qqmlprofilerservice_p.h>
Apr 27, 2011
Apr 27, 2011
73
74
75
QT_BEGIN_NAMESPACE
Feb 10, 2012
Feb 10, 2012
76
DEFINE_BOOL_CONFIG_OPTION(qmlTranslateTouchToMouse, QML_TRANSLATE_TOUCH_TO_MOUSE)
Jun 6, 2011
Jun 6, 2011
77
Oct 21, 2011
Oct 21, 2011
78
void QQuickCanvasPrivate::updateFocusItemTransform()
Sep 8, 2011
Sep 8, 2011
79
{
Oct 21, 2011
Oct 21, 2011
80
81
Q_Q(QQuickCanvas);
QQuickItem *focus = q->activeFocusItem();
Feb 2, 2012
Feb 2, 2012
82
if (focus && qApp->focusObject() == focus)
Feb 10, 2012
Feb 10, 2012
83
qApp->inputMethod()->setInputItemTransform(QQuickItemPrivate::get(focus)->itemToCanvasTransform());
Sep 8, 2011
Sep 8, 2011
84
85
}
Feb 24, 2012
Feb 24, 2012
86
class QQuickCanvasIncubationController : public QObject, public QQmlIncubationController
Sep 30, 2011
Sep 30, 2011
87
88
{
public:
Oct 21, 2011
Oct 21, 2011
89
QQuickCanvasIncubationController(QQuickCanvasPrivate *canvas)
Sep 30, 2011
Sep 30, 2011
90
91
92
93
94
95
96
: m_canvas(canvas), m_eventSent(false) {}
protected:
virtual bool event(QEvent *e)
{
if (e->type() == QEvent::User) {
Q_ASSERT(m_eventSent);
Feb 28, 2012
Feb 28, 2012
97
volatile bool *amtp = m_canvas->windowManager->allowMainThreadProcessing();
Sep 30, 2011
Sep 30, 2011
98
99
while (incubatingObjectCount()) {
if (amtp)
Feb 28, 2012
Feb 28, 2012
100
incubateWhile(amtp, 2);
Sep 30, 2011
Sep 30, 2011
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
else
incubateFor(5);
QCoreApplication::processEvents();
}
m_eventSent = false;
}
return QObject::event(e);
}
virtual void incubatingObjectCountChanged(int count)
{
if (count && !m_eventSent) {
m_eventSent = true;
QCoreApplication::postEvent(this, new QEvent(QEvent::User));
}
Feb 28, 2012
Feb 28, 2012
117
118
// If no animations are running, the renderer may be waiting
m_canvas->windowManager->wakeup();
Sep 30, 2011
Sep 30, 2011
119
120
121
}
private:
Oct 21, 2011
Oct 21, 2011
122
QQuickCanvasPrivate *m_canvas;
Sep 30, 2011
Sep 30, 2011
123
124
125
bool m_eventSent;
};
Jan 2, 2012
Jan 2, 2012
126
127
128
129
QAccessibleInterface *QQuickCanvas::accessibleRoot() const
{
return QAccessible::queryAccessibleInterface(const_cast<QQuickCanvas*>(this));
}
Aug 29, 2011
Aug 29, 2011
130
131
Apr 27, 2011
Apr 27, 2011
132
133
134
135
/*
Focus behavior
==============
Aug 31, 2011
Aug 31, 2011
136
Prior to being added to a valid canvas items can set and clear focus with no
Apr 27, 2011
Apr 27, 2011
137
effect. Only once items are added to a canvas (by way of having a parent set that
Aug 31, 2011
Aug 31, 2011
138
already belongs to a canvas) do the focus rules apply. Focus goes back to
Apr 27, 2011
Apr 27, 2011
139
140
141
having no effect if an item is removed from a canvas.
When an item is moved into a new focus scope (either being added to a canvas
Aug 31, 2011
Aug 31, 2011
142
for the first time, or having its parent changed), if the focus scope already has
Apr 27, 2011
Apr 27, 2011
143
a scope focused item that takes precedence over the item being added. Otherwise,
Aug 31, 2011
Aug 31, 2011
144
the focus of the added tree is used. In the case of of a tree of items being
Apr 27, 2011
Apr 27, 2011
145
added to a canvas for the first time, which may have a conflicted focus state (two
Aug 31, 2011
Aug 31, 2011
146
or more items in one scope having focus set), the same rule is applied item by item -
Jun 6, 2011
Jun 6, 2011
147
thus the first item that has focus will get it (assuming the scope doesn't already
Apr 27, 2011
Apr 27, 2011
148
149
150
have a scope focused item), and the other items will have their focus cleared.
*/
Jun 6, 2011
Jun 6, 2011
151
Apr 27, 2011
Apr 27, 2011
152
153
154
155
156
// #define FOCUS_DEBUG
// #define MOUSE_DEBUG
// #define TOUCH_DEBUG
// #define DIRTY_DEBUG
Oct 21, 2011
Oct 21, 2011
157
QQuickItem::UpdatePaintNodeData::UpdatePaintNodeData()
Apr 27, 2011
Apr 27, 2011
158
159
160
161
: transformNode(0)
{
}
Oct 21, 2011
Oct 21, 2011
162
QQuickRootItem::QQuickRootItem()
Apr 27, 2011
Apr 27, 2011
163
164
165
{
}
Mar 6, 2012
Mar 6, 2012
166
/*! \reimp */
Oct 21, 2011
Oct 21, 2011
167
void QQuickCanvas::exposeEvent(QExposeEvent *)
Apr 27, 2011
Apr 27, 2011
168
{
Oct 21, 2011
Oct 21, 2011
169
Q_D(QQuickCanvas);
Mar 5, 2012
Mar 5, 2012
170
d->windowManager->exposureChanged(this);
Apr 27, 2011
Apr 27, 2011
171
172
}
Mar 6, 2012
Mar 6, 2012
173
/*! \reimp */
Oct 21, 2011
Oct 21, 2011
174
void QQuickCanvas::resizeEvent(QResizeEvent *)
Apr 27, 2011
Apr 27, 2011
175
{
Oct 21, 2011
Oct 21, 2011
176
Q_D(QQuickCanvas);
Dec 8, 2011
Dec 8, 2011
177
d->windowManager->resize(this, size());
Aug 29, 2011
Aug 29, 2011
178
179
}
Mar 6, 2012
Mar 6, 2012
180
/*! \reimp */
Oct 21, 2011
Oct 21, 2011
181
void QQuickCanvas::showEvent(QShowEvent *)
Apr 27, 2011
Apr 27, 2011
182
{
Dec 8, 2011
Dec 8, 2011
183
d_func()->windowManager->show(this);
Apr 27, 2011
Apr 27, 2011
184
185
}
Mar 6, 2012
Mar 6, 2012
186
/*! \reimp */
Oct 21, 2011
Oct 21, 2011
187
void QQuickCanvas::hideEvent(QHideEvent *)
Apr 27, 2011
Apr 27, 2011
188
{
Dec 8, 2011
Dec 8, 2011
189
d_func()->windowManager->hide(this);
Apr 27, 2011
Apr 27, 2011
190
191
}
Mar 6, 2012
Mar 6, 2012
192
/*! \reimp */
Oct 24, 2011
Oct 24, 2011
193
194
195
196
197
198
void QQuickCanvas::focusOutEvent(QFocusEvent *)
{
Q_D(QQuickCanvas);
d->rootItem->setFocus(false);
}
Mar 6, 2012
Mar 6, 2012
199
/*! \reimp */
Oct 24, 2011
Oct 24, 2011
200
201
202
203
void QQuickCanvas::focusInEvent(QFocusEvent *)
{
Q_D(QQuickCanvas);
d->rootItem->setFocus(true);
Feb 2, 2012
Feb 2, 2012
204
d->updateFocusItemTransform();
Oct 24, 2011
Oct 24, 2011
205
}
Jun 10, 2011
Jun 10, 2011
206
207
Oct 21, 2011
Oct 21, 2011
208
void QQuickCanvasPrivate::polishItems()
Apr 27, 2011
Apr 27, 2011
209
{
Feb 13, 2012
Feb 13, 2012
210
211
212
213
214
QSet<QQuickItem *> itms = itemsToPolish;
itemsToPolish.clear();
for (QSet<QQuickItem *>::iterator it = itms.begin(); it != itms.end(); ++it) {
QQuickItem *item = *it;
Oct 21, 2011
Oct 21, 2011
215
QQuickItemPrivate::get(item)->polishScheduled = false;
Apr 27, 2011
Apr 27, 2011
216
217
item->updatePolish();
}
Sep 8, 2011
Sep 8, 2011
218
updateFocusItemTransform();
Apr 27, 2011
Apr 27, 2011
219
220
}
Feb 2, 2012
Feb 2, 2012
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/**
* This parameter enables that this canvas can be rendered without
* being shown on screen. This feature is very limited in what it supports.
*
* There needs to be another window actually showing that we can make current
* to get a surface to make current AND for this feature to be useful
* one needs to hook into beforeRender() and set the render tareget.
*
*/
void QQuickCanvasPrivate::setRenderWithoutShowing(bool render)
{
if (render == renderWithoutShowing)
return;
Q_Q(QQuickCanvas);
renderWithoutShowing = render;
if (render)
windowManager->show(q);
else
windowManager->hide(q);
}
Dec 19, 2011
Dec 19, 2011
245
246
247
248
249
250
251
252
253
254
void forceUpdate(QQuickItem *item)
{
if (item->flags() & QQuickItem::ItemHasContents)
item->update();
QQuickItemPrivate::get(item)->dirty(QQuickItemPrivate::ChildrenUpdateMask);
QList <QQuickItem *> items = item->childItems();
for (int i=0; i<items.size(); ++i)
forceUpdate(items.at(i));
}
Apr 27, 2011
Apr 27, 2011
255
Oct 21, 2011
Oct 21, 2011
256
void QQuickCanvasPrivate::syncSceneGraph()
Apr 27, 2011
Apr 27, 2011
257
{
Dec 8, 2011
Dec 8, 2011
258
if (!renderer) {
Dec 19, 2011
Dec 19, 2011
259
260
forceUpdate(rootItem);
Dec 8, 2011
Dec 8, 2011
261
262
263
264
265
266
QSGRootNode *rootNode = new QSGRootNode;
rootNode->appendChildNode(QQuickItemPrivate::get(rootItem)->itemNode());
renderer = context->createRenderer();
renderer->setRootNode(rootNode);
}
Apr 27, 2011
Apr 27, 2011
267
updateDirtyNodes();
Nov 18, 2011
Nov 18, 2011
268
269
// Copy the current state of clearing from canvas into renderer.
Dec 8, 2011
Dec 8, 2011
270
renderer->setClearColor(clearColor);
Nov 18, 2011
Nov 18, 2011
271
272
273
QSGRenderer::ClearMode mode = QSGRenderer::ClearStencilBuffer | QSGRenderer::ClearDepthBuffer;
if (clearBeforeRendering)
mode |= QSGRenderer::ClearColorBuffer;
Dec 8, 2011
Dec 8, 2011
274
renderer->setClearMode(mode);
Apr 27, 2011
Apr 27, 2011
275
276
277
}
Oct 21, 2011
Oct 21, 2011
278
void QQuickCanvasPrivate::renderSceneGraph(const QSize &size)
Apr 27, 2011
Apr 27, 2011
279
{
Nov 18, 2011
Nov 18, 2011
280
Q_Q(QQuickCanvas);
Feb 8, 2012
Feb 8, 2012
281
282
emit q->beforeRendering();
int fboId = 0;
Dec 8, 2011
Dec 8, 2011
283
renderer->setDeviceRect(QRect(QPoint(0, 0), size));
Feb 8, 2012
Feb 8, 2012
284
285
286
287
288
289
if (renderTargetId) {
fboId = renderTargetId;
renderer->setViewportRect(QRect(QPoint(0, 0), renderTargetSize));
} else {
renderer->setViewportRect(QRect(QPoint(0, 0), size));
}
Dec 8, 2011
Dec 8, 2011
290
renderer->setProjectionMatrixToDeviceRect();
Apr 27, 2011
Apr 27, 2011
291
Feb 8, 2012
Feb 8, 2012
292
context->renderNextFrame(renderer, fboId);
Nov 18, 2011
Nov 18, 2011
293
emit q->afterRendering();
Apr 27, 2011
Apr 27, 2011
294
295
}
Oct 21, 2011
Oct 21, 2011
296
QQuickCanvasPrivate::QQuickCanvasPrivate()
Apr 27, 2011
Apr 27, 2011
297
298
299
: rootItem(0)
, activeFocusItem(0)
, mouseGrabberItem(0)
Feb 10, 2012
Feb 10, 2012
300
301
, touchMouseId(-1)
, touchMousePressTimestamp(0)
Feb 2, 2012
Feb 2, 2012
302
, renderWithoutShowing(false)
Apr 27, 2011
Apr 27, 2011
303
304
, dirtyItemList(0)
, context(0)
Dec 8, 2011
Dec 8, 2011
305
306
, renderer(0)
, windowManager(0)
Nov 18, 2011
Nov 18, 2011
307
308
, clearColor(Qt::white)
, clearBeforeRendering(true)
Mar 20, 2012
Mar 20, 2012
309
310
, persistentGLContext(false)
, persistentSceneGraph(false)
Jul 1, 2011
Jul 1, 2011
311
, renderTarget(0)
Feb 8, 2012
Feb 8, 2012
312
, renderTargetId(0)
Sep 30, 2011
Sep 30, 2011
313
, incubationController(0)
Apr 27, 2011
Apr 27, 2011
314
315
316
{
}
Oct 21, 2011
Oct 21, 2011
317
QQuickCanvasPrivate::~QQuickCanvasPrivate()
Apr 27, 2011
Apr 27, 2011
318
319
320
{
}
Oct 21, 2011
Oct 21, 2011
321
void QQuickCanvasPrivate::init(QQuickCanvas *c)
Apr 27, 2011
Apr 27, 2011
322
323
324
{
q_ptr = c;
Oct 21, 2011
Oct 21, 2011
325
Q_Q(QQuickCanvas);
Apr 27, 2011
Apr 27, 2011
326
Oct 21, 2011
Oct 21, 2011
327
328
rootItem = new QQuickRootItem;
QQuickItemPrivate *rootItemPrivate = QQuickItemPrivate::get(rootItem);
Apr 27, 2011
Apr 27, 2011
329
rootItemPrivate->canvas = q;
Oct 21, 2011
Oct 21, 2011
330
rootItemPrivate->flags |= QQuickItem::ItemIsFocusScope;
Apr 27, 2011
Apr 27, 2011
331
Nov 1, 2011
Nov 1, 2011
332
333
334
335
336
337
// In the absence of a focus in event on some platforms assume the window will
// be activated immediately and set focus on the rootItem
// ### Remove when QTBUG-22415 is resolved.
//It is important that this call happens after the rootItem has a canvas..
rootItem->setFocus(true);
Dec 8, 2011
Dec 8, 2011
338
339
windowManager = QQuickWindowManager::instance();
context = windowManager->sceneGraphContext();
Sep 15, 2011
Sep 15, 2011
340
q->setSurfaceType(QWindow::OpenGLSurface);
Sep 26, 2011
Sep 26, 2011
341
q->setFormat(context->defaultSurfaceFormat());
Dec 8, 2011
Dec 8, 2011
342
Dec 19, 2011
Dec 19, 2011
343
344
345
QObject::connect(context, SIGNAL(initialized()), q, SIGNAL(sceneGraphInitialized()), Qt::DirectConnection);
QObject::connect(context, SIGNAL(invalidated()), q, SIGNAL(sceneGraphInvalidated()), Qt::DirectConnection);
QObject::connect(context, SIGNAL(invalidated()), q, SLOT(cleanupSceneGraph()), Qt::DirectConnection);
Dec 8, 2011
Dec 8, 2011
346
347
348
349
// ### TODO: remove QSGEngine
engine = new QSGEngine();
engine->setCanvas(q);
Apr 27, 2011
Apr 27, 2011
350
351
}
Feb 24, 2012
Feb 24, 2012
352
QQmlListProperty<QObject> QQuickCanvasPrivate::data()
Nov 29, 2011
Nov 29, 2011
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
{
initRootItem();
return QQuickItemPrivate::get(rootItem)->data();
}
void QQuickCanvasPrivate::initRootItem()
{
Q_Q(QQuickCanvas);
q->connect(q, SIGNAL(widthChanged(int)),
rootItem, SLOT(setWidth(int)));
q->connect(q, SIGNAL(heightChanged(int)),
rootItem, SLOT(setHeight(int)));
rootItem->setWidth(q->width());
rootItem->setHeight(q->height());
}
Feb 10, 2012
Feb 10, 2012
369
370
371
372
373
374
375
376
377
378
static QQuickMouseEventEx touchToMouseEvent(QEvent::Type type, const QTouchEvent::TouchPoint &p)
{
QQuickMouseEventEx me(type, p.pos(), p.scenePos(), p.screenPos(),
Qt::LeftButton, Qt::LeftButton, 0);
me.setVelocity(p.velocity());
return me;
}
void QQuickCanvasPrivate::translateTouchToMouse(QTouchEvent *event)
{
Mar 9, 2012
Mar 9, 2012
379
380
if (event->type() == QEvent::TouchCancel) {
touchMouseId = -1;
Mar 13, 2012
Mar 13, 2012
381
382
if (mouseGrabberItem)
mouseGrabberItem->ungrabMouse();
Mar 9, 2012
Mar 9, 2012
383
384
return;
}
Feb 10, 2012
Feb 10, 2012
385
386
387
388
389
390
391
392
393
394
for (int i = 0; i < event->touchPoints().count(); ++i) {
QTouchEvent::TouchPoint p = event->touchPoints().at(i);
if (touchMouseId == -1 && p.state() & Qt::TouchPointPressed) {
bool doubleClick = event->timestamp() - touchMousePressTimestamp
< static_cast<ulong>(qApp->styleHints()->mouseDoubleClickInterval());
touchMousePressTimestamp = event->timestamp();
if (doubleClick) {
QQuickMouseEventEx me = touchToMouseEvent(QEvent::MouseButtonDblClick, p);
me.setTimestamp(event->timestamp());
me.setAccepted(false);
Mar 2, 2012
Mar 2, 2012
395
me.setCapabilities(event->device()->capabilities());
Mar 1, 2012
Mar 1, 2012
396
397
398
399
400
401
402
403
404
405
406
if (!mouseGrabberItem) {
if (deliverInitialMousePressEvent(rootItem, &me)) {
touchMouseId = p.id();
event->setAccepted(true);
}
} else {
deliverMouseEvent(&me);
if (me.isAccepted()) {
touchMouseId = p.id();
event->setAccepted(true);
}
Feb 10, 2012
Feb 10, 2012
407
408
409
410
411
}
}
QQuickMouseEventEx me = touchToMouseEvent(QEvent::MouseButtonPress, p);
me.setTimestamp(event->timestamp());
me.setAccepted(false);
Mar 2, 2012
Mar 2, 2012
412
me.setCapabilities(event->device()->capabilities());
Feb 10, 2012
Feb 10, 2012
413
414
415
416
417
deliverMouseEvent(&me);
if (me.isAccepted()) {
touchMouseId = p.id();
event->setAccepted(true);
}
Mar 1, 2012
Mar 1, 2012
418
419
if (touchMouseId != -1)
break;
Feb 10, 2012
Feb 10, 2012
420
421
422
423
} else if (p.id() == touchMouseId) {
if (p.state() & Qt::TouchPointMoved) {
QQuickMouseEventEx me = touchToMouseEvent(QEvent::MouseMove, p);
me.setTimestamp(event->timestamp());
Mar 2, 2012
Mar 2, 2012
424
me.setCapabilities(event->device()->capabilities());
Feb 10, 2012
Feb 10, 2012
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
if (!mouseGrabberItem) {
if (lastMousePosition.isNull())
lastMousePosition = me.windowPos();
QPointF last = lastMousePosition;
lastMousePosition = me.windowPos();
bool accepted = me.isAccepted();
bool delivered = deliverHoverEvent(rootItem, me.windowPos(), last, me.modifiers(), accepted);
if (!delivered) {
//take care of any exits
accepted = clearHover();
}
me.setAccepted(accepted);
break;
}
deliverMouseEvent(&me);
} else if (p.state() & Qt::TouchPointReleased) {
touchMouseId = -1;
if (!mouseGrabberItem)
return;
QQuickMouseEventEx me = touchToMouseEvent(QEvent::MouseButtonRelease, p);
me.setTimestamp(event->timestamp());
Mar 2, 2012
Mar 2, 2012
448
me.setCapabilities(event->device()->capabilities());
Feb 10, 2012
Feb 10, 2012
449
deliverMouseEvent(&me);
Mar 13, 2012
Mar 13, 2012
450
451
if (mouseGrabberItem)
mouseGrabberItem->ungrabMouse();
Feb 10, 2012
Feb 10, 2012
452
453
454
455
456
457
}
break;
}
}
}
Oct 21, 2011
Oct 21, 2011
458
void QQuickCanvasPrivate::transformTouchPoints(QList<QTouchEvent::TouchPoint> &touchPoints, const QTransform &transform)
Apr 27, 2011
Apr 27, 2011
459
460
461
462
463
464
465
466
467
468
469
470
471
472
{
for (int i=0; i<touchPoints.count(); i++) {
QTouchEvent::TouchPoint &touchPoint = touchPoints[i];
touchPoint.setRect(transform.mapRect(touchPoint.sceneRect()));
touchPoint.setStartPos(transform.map(touchPoint.startScenePos()));
touchPoint.setLastPos(transform.map(touchPoint.lastScenePos()));
}
}
/*!
Translates the data in \a touchEvent to this canvas. This method leaves the item local positions in
\a touchEvent untouched (these are filled in later).
*/
Oct 21, 2011
Oct 21, 2011
473
void QQuickCanvasPrivate::translateTouchEvent(QTouchEvent *touchEvent)
Apr 27, 2011
Apr 27, 2011
474
{
Oct 21, 2011
Oct 21, 2011
475
// Q_Q(QQuickCanvas);
Apr 27, 2011
Apr 27, 2011
476
Aug 5, 2011
Aug 5, 2011
477
// touchEvent->setWidget(q); // ### refactor...
Apr 27, 2011
Apr 27, 2011
478
479
480
481
482
483
484
485
486
487
488
489
490
QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
for (int i = 0; i < touchPoints.count(); ++i) {
QTouchEvent::TouchPoint &touchPoint = touchPoints[i];
touchPoint.setScreenRect(touchPoint.sceneRect());
touchPoint.setStartScreenPos(touchPoint.startScenePos());
touchPoint.setLastScreenPos(touchPoint.lastScenePos());
touchPoint.setSceneRect(touchPoint.rect());
touchPoint.setStartScenePos(touchPoint.startPos());
touchPoint.setLastScenePos(touchPoint.lastPos());
Jan 13, 2012
Jan 13, 2012
491
if (i == 0)
Apr 27, 2011
Apr 27, 2011
492
493
494
495
496
lastMousePosition = touchPoint.pos().toPoint();
}
touchEvent->setTouchPoints(touchPoints);
}
Oct 21, 2011
Oct 21, 2011
497
void QQuickCanvasPrivate::setFocusInScope(QQuickItem *scope, QQuickItem *item, FocusOptions options)
Apr 27, 2011
Apr 27, 2011
498
{
Oct 21, 2011
Oct 21, 2011
499
Q_Q(QQuickCanvas);
Apr 27, 2011
Apr 27, 2011
500
501
Q_ASSERT(item);
May 19, 2011
May 19, 2011
502
Q_ASSERT(scope || item == rootItem);
Apr 27, 2011
Apr 27, 2011
503
504
#ifdef FOCUS_DEBUG
Oct 21, 2011
Oct 21, 2011
505
qWarning() << "QQuickCanvasPrivate::setFocusInScope():";
Apr 27, 2011
Apr 27, 2011
506
qWarning() << " scope:" << (QObject *)scope;
May 19, 2011
May 19, 2011
507
if (scope)
Oct 21, 2011
Oct 21, 2011
508
qWarning() << " scopeSubFocusItem:" << (QObject *)QQuickItemPrivate::get(scope)->subFocusItem;
Apr 27, 2011
Apr 27, 2011
509
510
511
512
qWarning() << " item:" << (QObject *)item;
qWarning() << " activeFocusItem:" << (QObject *)activeFocusItem;
#endif
Oct 21, 2011
Oct 21, 2011
513
514
QQuickItemPrivate *scopePrivate = scope ? QQuickItemPrivate::get(scope) : 0;
QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item);
Apr 27, 2011
Apr 27, 2011
515
Oct 21, 2011
Oct 21, 2011
516
517
QQuickItem *oldActiveFocusItem = 0;
QQuickItem *newActiveFocusItem = 0;
Apr 27, 2011
Apr 27, 2011
518
Oct 21, 2011
Oct 21, 2011
519
QVarLengthArray<QQuickItem *, 20> changed;
Apr 27, 2011
Apr 27, 2011
520
521
// Does this change the active focus?
Feb 2, 2012
Feb 2, 2012
522
if (item == rootItem || (scopePrivate->activeFocus && item->isEnabled())) {
Apr 27, 2011
Apr 27, 2011
523
524
oldActiveFocusItem = activeFocusItem;
newActiveFocusItem = item;
Feb 1, 2012
Feb 1, 2012
525
526
527
while (newActiveFocusItem->isFocusScope()
&& newActiveFocusItem->scopedFocusItem()
&& newActiveFocusItem->scopedFocusItem()->isEnabled()) {
Apr 27, 2011
Apr 27, 2011
528
newActiveFocusItem = newActiveFocusItem->scopedFocusItem();
Feb 1, 2012
Feb 1, 2012
529
}
Apr 27, 2011
Apr 27, 2011
530
May 19, 2011
May 19, 2011
531
if (oldActiveFocusItem) {
Apr 27, 2011
Apr 27, 2011
532
#ifndef QT_NO_IM
Feb 10, 2012
Feb 10, 2012
533
qApp->inputMethod()->reset();
Apr 27, 2011
Apr 27, 2011
534
535
#endif
May 19, 2011
May 19, 2011
536
537
538
539
activeFocusItem = 0;
QFocusEvent event(QEvent::FocusOut, Qt::OtherFocusReason);
q->sendEvent(oldActiveFocusItem, &event);
Oct 21, 2011
Oct 21, 2011
540
QQuickItem *afi = oldActiveFocusItem;
May 19, 2011
May 19, 2011
541
while (afi != scope) {
Oct 21, 2011
Oct 21, 2011
542
543
if (QQuickItemPrivate::get(afi)->activeFocus) {
QQuickItemPrivate::get(afi)->activeFocus = false;
May 19, 2011
May 19, 2011
544
545
546
changed << afi;
}
afi = afi->parentItem();
Apr 27, 2011
Apr 27, 2011
547
548
549
550
}
}
}
Feb 1, 2012
Feb 1, 2012
551
if (item != rootItem && !(options & DontChangeSubFocusItem)) {
Oct 21, 2011
Oct 21, 2011
552
QQuickItem *oldSubFocusItem = scopePrivate->subFocusItem;
May 19, 2011
May 19, 2011
553
if (oldSubFocusItem) {
Oct 21, 2011
Oct 21, 2011
554
QQuickItemPrivate::get(oldSubFocusItem)->focus = false;
May 19, 2011
May 19, 2011
555
556
changed << oldSubFocusItem;
}
Mar 20, 2012
Mar 20, 2012
557
558
QQuickItemPrivate::get(item)->updateSubFocusItem(scope, true);
Apr 27, 2011
Apr 27, 2011
559
560
561
}
if (!(options & DontChangeFocusProperty)) {
Nov 1, 2011
Nov 1, 2011
562
// if (item != rootItem || QGuiApplication::focusWindow() == q) { // QTBUG-22415
May 19, 2011
May 19, 2011
563
564
itemPrivate->focus = true;
changed << item;
Nov 1, 2011
Nov 1, 2011
565
// }
Apr 27, 2011
Apr 27, 2011
566
567
}
Nov 1, 2011
Nov 1, 2011
568
if (newActiveFocusItem && rootItem->hasFocus()) {
Apr 27, 2011
Apr 27, 2011
569
570
activeFocusItem = newActiveFocusItem;
Oct 21, 2011
Oct 21, 2011
571
QQuickItemPrivate::get(newActiveFocusItem)->activeFocus = true;
Apr 27, 2011
Apr 27, 2011
572
573
changed << newActiveFocusItem;
Oct 21, 2011
Oct 21, 2011
574
QQuickItem *afi = newActiveFocusItem->parentItem();
May 19, 2011
May 19, 2011
575
while (afi && afi != scope) {
Apr 27, 2011
Apr 27, 2011
576
if (afi->isFocusScope()) {
Oct 21, 2011
Oct 21, 2011
577
QQuickItemPrivate::get(afi)->activeFocus = true;
Apr 27, 2011
Apr 27, 2011
578
579
580
581
582
583
changed << afi;
}
afi = afi->parentItem();
}
QFocusEvent event(QEvent::FocusIn, Qt::OtherFocusReason);
Aug 31, 2011
Aug 31, 2011
584
q->sendEvent(newActiveFocusItem, &event);
Apr 27, 2011
Apr 27, 2011
585
586
}
Feb 2, 2012
Feb 2, 2012
587
588
emit q->focusObjectChanged(activeFocusItem);
May 19, 2011
May 19, 2011
589
if (!changed.isEmpty())
Apr 27, 2011
Apr 27, 2011
590
591
592
notifyFocusChangesRecur(changed.data(), changed.count() - 1);
}
Oct 21, 2011
Oct 21, 2011
593
void QQuickCanvasPrivate::clearFocusInScope(QQuickItem *scope, QQuickItem *item, FocusOptions options)
Apr 27, 2011
Apr 27, 2011
594
{
Oct 21, 2011
Oct 21, 2011
595
Q_Q(QQuickCanvas);
Apr 27, 2011
Apr 27, 2011
596
597
Q_ASSERT(item);
May 19, 2011
May 19, 2011
598
Q_ASSERT(scope || item == rootItem);
Apr 27, 2011
Apr 27, 2011
599
600
#ifdef FOCUS_DEBUG
Oct 21, 2011
Oct 21, 2011
601
qWarning() << "QQuickCanvasPrivate::clearFocusInScope():";
Apr 27, 2011
Apr 27, 2011
602
603
604
605
606
qWarning() << " scope:" << (QObject *)scope;
qWarning() << " item:" << (QObject *)item;
qWarning() << " activeFocusItem:" << (QObject *)activeFocusItem;
#endif
Mar 15, 2012
Mar 15, 2012
607
608
609
610
611
612
QQuickItemPrivate *scopePrivate = 0;
if (scope) {
scopePrivate = QQuickItemPrivate::get(scope);
if ( !scopePrivate->subFocusItem )
return;//No focus, nothing to do.
}
Apr 27, 2011
Apr 27, 2011
613
Oct 21, 2011
Oct 21, 2011
614
615
QQuickItem *oldActiveFocusItem = 0;
QQuickItem *newActiveFocusItem = 0;
Apr 27, 2011
Apr 27, 2011
616
Oct 21, 2011
Oct 21, 2011
617
QVarLengthArray<QQuickItem *, 20> changed;
Apr 27, 2011
Apr 27, 2011
618
May 19, 2011
May 19, 2011
619
Q_ASSERT(item == rootItem || item == scopePrivate->subFocusItem);
Apr 27, 2011
Apr 27, 2011
620
621
// Does this change the active focus?
May 19, 2011
May 19, 2011
622
if (item == rootItem || scopePrivate->activeFocus) {
Apr 27, 2011
Apr 27, 2011
623
624
oldActiveFocusItem = activeFocusItem;
newActiveFocusItem = scope;
May 19, 2011
May 19, 2011
625
Apr 27, 2011
Apr 27, 2011
626
627
628
Q_ASSERT(oldActiveFocusItem);
#ifndef QT_NO_IM
Feb 10, 2012
Feb 10, 2012
629
qApp->inputMethod()->reset();
Apr 27, 2011
Apr 27, 2011
630
631
632
633
634
635
#endif
activeFocusItem = 0;
QFocusEvent event(QEvent::FocusOut, Qt::OtherFocusReason);
q->sendEvent(oldActiveFocusItem, &event);
Oct 21, 2011
Oct 21, 2011
636
QQuickItem *afi = oldActiveFocusItem;
Apr 27, 2011
Apr 27, 2011
637
while (afi != scope) {
Oct 21, 2011
Oct 21, 2011
638
639
if (QQuickItemPrivate::get(afi)->activeFocus) {
QQuickItemPrivate::get(afi)->activeFocus = false;
Apr 27, 2011
Apr 27, 2011
640
641
642
643
644
645
changed << afi;
}
afi = afi->parentItem();
}
}
Feb 1, 2012
Feb 1, 2012
646
if (item != rootItem && !(options & DontChangeSubFocusItem)) {
Oct 21, 2011
Oct 21, 2011
647
QQuickItem *oldSubFocusItem = scopePrivate->subFocusItem;
May 19, 2011
May 19, 2011
648
if (oldSubFocusItem && !(options & DontChangeFocusProperty)) {
Oct 21, 2011
Oct 21, 2011
649
QQuickItemPrivate::get(oldSubFocusItem)->focus = false;
May 19, 2011
May 19, 2011
650
651
changed << oldSubFocusItem;
}
Mar 20, 2012
Mar 20, 2012
652
653
654
QQuickItemPrivate::get(item)->updateSubFocusItem(scope, false);
May 19, 2011
May 19, 2011
655
} else if (!(options & DontChangeFocusProperty)) {
Oct 21, 2011
Oct 21, 2011
656
QQuickItemPrivate::get(item)->focus = false;
May 19, 2011
May 19, 2011
657
changed << item;
Apr 27, 2011
Apr 27, 2011
658
659
660
661
662
663
664
}
if (newActiveFocusItem) {
Q_ASSERT(newActiveFocusItem == scope);
activeFocusItem = scope;
QFocusEvent event(QEvent::FocusIn, Qt::OtherFocusReason);
Aug 31, 2011
Aug 31, 2011
665
q->sendEvent(newActiveFocusItem, &event);
Apr 27, 2011
Apr 27, 2011
666
667
}
Feb 2, 2012
Feb 2, 2012
668
669
emit q->focusObjectChanged(activeFocusItem);
Aug 31, 2011
Aug 31, 2011
670
if (!changed.isEmpty())
Apr 27, 2011
Apr 27, 2011
671
672
673
notifyFocusChangesRecur(changed.data(), changed.count() - 1);
}
Oct 21, 2011
Oct 21, 2011
674
void QQuickCanvasPrivate::notifyFocusChangesRecur(QQuickItem **items, int remaining)
Apr 27, 2011
Apr 27, 2011
675
{
Feb 24, 2012
Feb 24, 2012
676
QQmlGuard<QQuickItem> item(*items);
Apr 27, 2011
Apr 27, 2011
677
678
679
680
681
if (remaining)
notifyFocusChangesRecur(items + 1, remaining - 1);
if (item) {
Oct 21, 2011
Oct 21, 2011
682
QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item);
Apr 27, 2011
Apr 27, 2011
683
684
685
686
687
688
689
690
if (itemPrivate->notifiedFocus != itemPrivate->focus) {
itemPrivate->notifiedFocus = itemPrivate->focus;
emit item->focusChanged(itemPrivate->focus);
}
if (item && itemPrivate->notifiedActiveFocus != itemPrivate->activeFocus) {
itemPrivate->notifiedActiveFocus = itemPrivate->activeFocus;
Oct 21, 2011
Oct 21, 2011
691
itemPrivate->itemChange(QQuickItem::ItemActiveFocusHasChanged, itemPrivate->activeFocus);
Apr 27, 2011
Apr 27, 2011
692
693
emit item->activeFocusChanged(itemPrivate->activeFocus);
}
Aug 31, 2011
Aug 31, 2011
694
}
Apr 27, 2011
Apr 27, 2011
695
696
}
Oct 21, 2011
Oct 21, 2011
697
void QQuickCanvasPrivate::dirtyItem(QQuickItem *)
Apr 27, 2011
Apr 27, 2011
698
{
Oct 21, 2011
Oct 21, 2011
699
Q_Q(QQuickCanvas);
Apr 27, 2011
Apr 27, 2011
700
701
702
q->maybeUpdate();
}
Oct 21, 2011
Oct 21, 2011
703
void QQuickCanvasPrivate::cleanup(QSGNode *n)
Apr 27, 2011
Apr 27, 2011
704
{
Oct 21, 2011
Oct 21, 2011
705
Q_Q(QQuickCanvas);
Apr 27, 2011
Apr 27, 2011
706
707
708
709
710
711
712
Q_ASSERT(!cleanupNodeList.contains(n));
cleanupNodeList.append(n);
q->maybeUpdate();
}
Nov 29, 2011
Nov 29, 2011
713
714
715
716
717
718
719
720
/*!
\qmlclass Window QQuickCanvas
\inqmlmodule QtQuick.Window 2
\brief The Window object creates a new top-level window.
The Window object creates a new top-level window for a QtQuick scene. It automatically sets up the
window for use with QtQuick 2.0 graphical elements.
*/
Nov 3, 2011
Nov 3, 2011
721
722
723
724
725
726
727
728
729
730
731
732
/*!
\class QQuickCanvas
\since QtQuick 2.0
\brief The QQuickCanvas class provides the canvas for displaying a graphical QML scene
QQuickCanvas provides the graphical scene management needed to interact with and display
a scene of QQuickItems.
A QQuickCanvas always has a single invisible root item. To add items to this canvas,
reparent the items to the root item or to an existing item in the scene.
For easily displaying a scene from a QML file, see \l{QQuickView}.
Mar 20, 2012
Mar 20, 2012
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
\section1 Scene Graph and Rendering
The QQuickCanvas uses a scene graph on top of OpenGL to render. This scene graph is disconnected
from the QML scene and potentially lives in another thread, depending on the platform
implementation. Since the rendering scene graph lives independently from the QML scene, it can
also be completely released without affecting the state of the QML scene.
The sceneGraphInitialized() signal is emitted on the rendering thread before the QML scene is
rendered to the screen for the first time. If the rendering scene graph has been released
the signal will be emitted again before the next frame is rendered.
Rendering is done by first copying the QML scene's state into the rendering scene graph. This is
done by calling QQuickItem::updatePaintNode() functions on all items that have changed. This phase
is run on the rendering thread with the GUI thread blocked, when a separate rendering thread
is being used. The scene can then be rendered.
Before the scene graph is rendered, the beforeRendering() signal is emitted. The OpenGL context
is bound at this point and the application is free to do its own rendering. Also
make sure to disable the clearing of the color buffer, using setClearBeforeRendering(). The
default clear color is white and can be changed with setClearColor(). After the scene has
been rendered, the afterRendering() signal is emitted. The application can use this to render
OpenGL on top of a QML application. Once the frame is fully done and has been swapped,
the frameSwapped() signal is emitted.
While the scene graph is being rendered on the rendering thread, the GUI will process animations
for the next frame. This means that as long as users are not using scene graph API
directly, the added complexity of a rendering thread can be completely ignored.
When a QQuickCanvas is programatically hidden with hide() or setVisible(false), it will
stop rendering and its scene graph and OpenGL context might be released. The
sceneGraphInvalidated() signal will be emitted when this happens.
\warning It is crucial that OpenGL operations and interaction with the scene graph happens
exclusively on the rendering thread, primarily during the updatePaintNode() phase.
\warning As signals related to rendering might be emitted from the rendering thread,
connections should be made using Qt::DirectConnection
\section1 Resource Management
QML will typically try to cache images, scene graph nodes, etc to improve performance, but in
some low-memory scenarios it might be required to aggressively release these resources. The
releaseResources() can be used to force clean up of certain resources. Calling releaseResources()
may result in the entire scene graph and its OpenGL context being deleted. The
sceneGraphInvalidated() signal will be emitted when this happens.
Nov 3, 2011
Nov 3, 2011
782
*/
Oct 21, 2011
Oct 21, 2011
783
784
QQuickCanvas::QQuickCanvas(QWindow *parent)
: QWindow(*(new QQuickCanvasPrivate), parent)
Apr 27, 2011
Apr 27, 2011
785
{
Oct 21, 2011
Oct 21, 2011
786
Q_D(QQuickCanvas);
Apr 27, 2011
Apr 27, 2011
787
788
789
d->init(this);
}
Oct 21, 2011
Oct 21, 2011
790
QQuickCanvas::QQuickCanvas(QQuickCanvasPrivate &dd, QWindow *parent)
Aug 5, 2011
Aug 5, 2011
791
: QWindow(dd, parent)
Apr 27, 2011
Apr 27, 2011
792
{
Oct 21, 2011
Oct 21, 2011
793
Q_D(QQuickCanvas);
Apr 27, 2011
Apr 27, 2011
794
795
796
d->init(this);
}
Oct 21, 2011
Oct 21, 2011
797
QQuickCanvas::~QQuickCanvas()
Apr 27, 2011
Apr 27, 2011
798
{
Oct 21, 2011
Oct 21, 2011
799
Q_D(QQuickCanvas);
Apr 27, 2011
Apr 27, 2011
800
Dec 8, 2011
Dec 8, 2011
801
d->windowManager->canvasDestroyed(this);
May 11, 2011
May 11, 2011
802
Oct 21, 2011
Oct 21, 2011
803
// ### should we change ~QQuickItem to handle this better?
Apr 27, 2011
Apr 27, 2011
804
// manually cleanup for the root item (item destructor only handles these when an item is parented)
Oct 21, 2011
Oct 21, 2011
805
QQuickItemPrivate *rootItemPrivate = QQuickItemPrivate::get(d->rootItem);
Apr 27, 2011
Apr 27, 2011
806
807
rootItemPrivate->removeFromDirtyList();
Feb 27, 2012
Feb 27, 2012
808
QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
Sep 30, 2011
Sep 30, 2011
809
810
delete d->incubationController; d->incubationController = 0;
Apr 27, 2011
Apr 27, 2011
811
812
813
delete d->rootItem; d->rootItem = 0;
}
Feb 15, 2012
Feb 15, 2012
814
815
816
817
/*!
This function tries to release redundant resources currently held by the QML scene.
Mar 20, 2012
Mar 20, 2012
818
819
820
821
822
823
824
825
826
Calling this function might result in the scene graph and the OpenGL context used
for rendering being released to release graphics memory. If this happens, the
sceneGraphInvalidated() signal will be called, allowing users to clean up their
own graphics resources. The setPersistentOpenGLContext() and setPersistentSceneGraph()
functions can be used to prevent this from happening, if handling the cleanup is
not feasible in the application, at the cost of higher memory usage.
\sa sceneGraphInvalidated(), setPersistentOpenGLContext(), setPersistentSceneGraph().
Feb 15, 2012
Feb 15, 2012
827
828
829
830
831
832
*/
void QQuickCanvas::releaseResources()
{
Q_D(QQuickCanvas);
d->windowManager->releaseResources();
Feb 24, 2012
Feb 24, 2012
833
QQuickPixmap::purgeCache();
Feb 15, 2012
Feb 15, 2012
834
835
836
837
}
Mar 20, 2012
Mar 20, 2012
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
/*!
Controls whether the OpenGL context can be released as a part of a call to
releaseResources().
The OpenGL context might still be released when the user makes an explicit
call to hide().
\sa setPersistentSceneGraph()
*/
void QQuickCanvas::setPersistentOpenGLContext(bool persistent)
{
Q_D(QQuickCanvas);
d->persistentGLContext = persistent;
}
/*!
Returns whether the OpenGL context can be released as a part of a call to
releaseResources().
*/
bool QQuickCanvas::isPersistentOpenGLContext() const
{
Q_D(const QQuickCanvas);
return d->persistentGLContext;
}
/*!
Controls whether the scene graph nodes and resources can be released as a
part of a call to releaseResources().
The scene graph nodes and resources might still be released when the user
makes an explicit call to hide().
\sa setPersistentOpenGLContext()
*/
void QQuickCanvas::setPersistentSceneGraph(bool persistent)
{
Q_D(QQuickCanvas);
d->persistentSceneGraph = persistent;
}
/*!
Returns whether the scene graph nodes and resources can be released as a part
of a call to releaseResources().
*/
bool QQuickCanvas::isPersistentSceneGraph() const
{
Q_D(const QQuickCanvas);
return d->persistentSceneGraph;
}
Nov 3, 2011
Nov 3, 2011
901
902
903
904
905
906
/*!
Returns the invisible root item of the scene.
A QQuickCanvas always has a single invisible root item. To add items to this canvas,
reparent the items to the root item or to an existing item in the scene.
*/
Oct 21, 2011
Oct 21, 2011
907
QQuickItem *QQuickCanvas::rootItem() const
Apr 27, 2011
Apr 27, 2011
908
{
Oct 21, 2011
Oct 21, 2011
909
Q_D(const QQuickCanvas);
Aug 31, 2011
Aug 31, 2011
910
Apr 27, 2011
Apr 27, 2011
911
912
913
return d->rootItem;
}
Nov 3, 2011
Nov 3, 2011
914
915
916
/*!
Returns the item which currently has active focus.
*/
Oct 21, 2011
Oct 21, 2011
917
QQuickItem *QQuickCanvas::activeFocusItem() const
Apr 27, 2011
Apr 27, 2011
918
{
Oct 21, 2011
Oct 21, 2011
919
Q_D(const QQuickCanvas);
Aug 31, 2011
Aug 31, 2011
920
Apr 27, 2011
Apr 27, 2011
921
922
923
return d->activeFocusItem;
}
Jan 25, 2012
Jan 25, 2012
924
925
926
927
928
929
930
931
932
933
QObject *QQuickCanvas::focusObject() const
{
Q_D(const QQuickCanvas);
if (d->activeFocusItem)
return d->activeFocusItem;
return const_cast<QQuickCanvas*>(this);
}
Nov 3, 2011
Nov 3, 2011
934
935
936
/*!
Returns the item which currently has the mouse grab.
*/
Oct 21, 2011
Oct 21, 2011
937
QQuickItem *QQuickCanvas::mouseGrabberItem() const
Apr 27, 2011
Apr 27, 2011
938
{
Oct 21, 2011
Oct 21, 2011
939
Q_D(const QQuickCanvas);
Aug 31, 2011
Aug 31, 2011
940
Apr 27, 2011
Apr 27, 2011
941
942
943
944
return d->mouseGrabberItem;
}
Nov 29, 2011
Nov 29, 2011
945
946
947
948
949
950
951
952
/*!
\qmlproperty color QtQuick2.Window::Window::color
The background color for the window.
Setting this property is more efficient than using a separate Rectangle.
*/
Oct 21, 2011
Oct 21, 2011
953
bool QQuickCanvasPrivate::clearHover()
Apr 27, 2011
Apr 27, 2011
954
{
Aug 2, 2011
Aug 2, 2011
955
956
if (hoverItems.isEmpty())
return false;
Apr 27, 2011
Apr 27, 2011
957
Aug 5, 2011
Aug 5, 2011
958
QPointF pos = QCursor::pos(); // ### refactor: q->mapFromGlobal(QCursor::pos());
Apr 27, 2011
Apr 27, 2011
959
Aug 2, 2011
Aug 2, 2011
960
bool accepted = false;
Oct 21, 2011
Oct 21, 2011
961
foreach (QQuickItem* item, hoverItems)
Sep 1, 2011
Sep 1, 2011
962
accepted = sendHoverEvent(QEvent::HoverLeave, item, pos, pos, QGuiApplication::keyboardModifiers(), true) || accepted;
Aug 2, 2011
Aug 2, 2011
963
964
hoverItems.clear();
return accepted;
Apr 27, 2011
Apr 27, 2011
965
966
}
Mar 6, 2012
Mar 6, 2012
967
/*! \reimp */
Oct 21, 2011
Oct 21, 2011
968
bool QQuickCanvas::event(QEvent *e)
Apr 27, 2011
Apr 27, 2011
969
{
Oct 21, 2011
Oct 21, 2011
970
Q_D(QQuickCanvas);
Apr 27, 2011
Apr 27, 2011
971
972
973
974
975
976
switch (e->type()) {
case QEvent::TouchBegin:
case QEvent::TouchUpdate:
case QEvent::TouchEnd:
Feb 13, 2012
Feb 13, 2012
977
case QEvent::TouchCancel:
Apr 27, 2011
Apr 27, 2011
978
979
980
981
{
QTouchEvent *touch = static_cast<QTouchEvent *>(e);
d->translateTouchEvent(touch);
d->deliverTouchEvent(touch);
Feb 10, 2012
Feb 10, 2012
982
983
if (qmlTranslateTouchToMouse())
d->translateTouchToMouse(touch);
Jan 24, 2012
Jan 24, 2012
984
985
return touch->isAccepted();
Apr 27, 2011
Apr 27, 2011
986
987
988
989
990
}
case QEvent::Leave:
d->clearHover();
d->lastMousePosition = QPoint();
break;
Oct 10, 2011
Oct 10, 2011
991
992
993
994
995
case QEvent::DragEnter:
case QEvent::DragLeave:
case QEvent::DragMove:
case QEvent::Drop:
d->deliverDragEvent(&d->dragGrabber, e);
Jun 9, 2011
Jun 9, 2011
996
break;
Aug 2, 2011
Aug 2, 2011
997
998
999
case QEvent::WindowDeactivate:
rootItem()->windowDeactivateEvent();
break;
Apr 27, 2011
Apr 27, 2011
1000
default: