An error occurred while loading the file. Please try again.
-
Allan Sandfeld Jensen authored
The tools/qmake directory is a left over from webkit where qmake was but one of many buildsystems. This is not necessary for qtwebengine, so we can instead use the standard locations. Change-Id: I3d126d6627295b113b091f3eabeee25f1c1f6183 Reviewed-by:
Kai Koehne <kai.koehne@qt.io> Reviewed-by:
Oswald Buddenhagen <oswald.buddenhagen@qt.io>
8fb1dbef
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtQuick module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** 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.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qquickwindow.h"
#include "qquickwindow_p.h"
#include "qquickitem.h"
#include "qquickitem_p.h"
#include "qquickevents_p_p.h"
#include <private/qquickdrag_p.h>
#include <QtQuick/private/qsgrenderer_p.h>
#include <QtQuick/private/qsgtexture_p.h>
#include <private/qsgrenderloop_p.h>
#include <private/qquickrendercontrol_p.h>
#include <private/qquickanimatorcontroller_p.h>
#include <private/qguiapplication_p.h>
#include <QtGui/QInputMethod>
#include <private/qabstractanimation_p.h>
#include <QtGui/qpainter.h>
#include <QtGui/qevent.h>
#include <QtGui/qmatrix4x4.h>
#include <QtGui/qstylehints.h>
#include <QtCore/qvarlengtharray.h>
#include <QtCore/qabstractanimation.h>
#include <QtCore/QLibraryInfo>
#include <QtCore/QRunnable>
#include <QtQml/qqmlincubator.h>
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
#include <QtQuick/private/qquickpixmapcache_p.h>
#include <private/qqmlprofilerservice_p.h>
#include <private/qqmlmemoryprofiler_p.h>
#include <private/qopenglvertexarrayobject_p.h>
QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(DBG_TOUCH, "qt.quick.touch");
Q_LOGGING_CATEGORY(DBG_MOUSE, "qt.quick.mouse");
Q_LOGGING_CATEGORY(DBG_FOCUS, "qt.quick.focus");
Q_LOGGING_CATEGORY(DBG_DIRTY, "qt.quick.dirty");
extern Q_GUI_EXPORT QImage qt_gl_read_framebuffer(const QSize &size, bool alpha_format, bool include_alpha);
bool QQuickWindowPrivate::defaultAlphaBuffer = false;
bool QQuickWindowPrivate::defaultFormatInitialized = false;
QSurfaceFormat QQuickWindowPrivate::defaultFormat;
void QQuickWindowPrivate::updateFocusItemTransform()
{
Q_Q(QQuickWindow);
#ifndef QT_NO_IM
QQuickItem *focus = q->activeFocusItem();
if (focus && qApp->focusObject() == focus) {
QQuickItemPrivate *focusPrivate = QQuickItemPrivate::get(focus);
qApp->inputMethod()->setInputItemTransform(focusPrivate->itemToWindowTransform());
qApp->inputMethod()->setInputItemRectangle(QRectF(0, 0, focusPrivate->width, focusPrivate->height));
}
#endif
}
class QQuickWindowIncubationController : public QObject, public QQmlIncubationController
{
Q_OBJECT
public:
QQuickWindowIncubationController(QSGRenderLoop *loop)
: m_renderLoop(loop), m_timer(0)
{
// Allow incubation for 1/3 of a frame.
m_incubation_time = qMax(1, int(1000 / QGuiApplication::primaryScreen()->refreshRate()) / 3);
QAnimationDriver *animationDriver = m_renderLoop->animationDriver();
if (animationDriver) {
connect(animationDriver, SIGNAL(stopped()), this, SLOT(animationStopped()));
connect(m_renderLoop, SIGNAL(timeToIncubate()), this, SLOT(incubate()));
}
}
protected:
void timerEvent(QTimerEvent *)
{
killTimer(m_timer);
m_timer = 0;
incubate();
}
void incubateAgain() {
if (m_timer == 0) {
// Wait for a while before processing the next batch. Using a
// timer to avoid starvation of system events.
m_timer = startTimer(m_incubation_time);
}
}
public slots:
void incubate() {
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
if (incubatingObjectCount()) {
if (m_renderLoop->interleaveIncubation()) {
incubateFor(m_incubation_time);
} else {
incubateFor(m_incubation_time * 2);
if (incubatingObjectCount())
incubateAgain();
}
}
}
void animationStopped() { incubate(); }
protected:
virtual void incubatingObjectCountChanged(int count)
{
if (count && !m_renderLoop->interleaveIncubation())
incubateAgain();
}
private:
QSGRenderLoop *m_renderLoop;
int m_incubation_time;
int m_timer;
};
#include "qquickwindow.moc"
#ifndef QT_NO_ACCESSIBILITY
/*!
Returns an accessibility interface for this window, or 0 if such an
interface cannot be created.
*/
QAccessibleInterface *QQuickWindow::accessibleRoot() const
{
return QAccessible::queryAccessibleInterface(const_cast<QQuickWindow*>(this));
}
#endif
/*
Focus behavior
==============
Prior to being added to a valid window items can set and clear focus with no
effect. Only once items are added to a window (by way of having a parent set that
already belongs to a window) do the focus rules apply. Focus goes back to
having no effect if an item is removed from a window.
When an item is moved into a new focus scope (either being added to a window
for the first time, or having its parent changed), if the focus scope already has
a scope focused item that takes precedence over the item being added. Otherwise,
the focus of the added tree is used. In the case of of a tree of items being
added to a window for the first time, which may have a conflicted focus state (two
or more items in one scope having focus set), the same rule is applied item by item -
thus the first item that has focus will get it (assuming the scope doesn't already
have a scope focused item), and the other items will have their focus cleared.
*/
QQuickItem::UpdatePaintNodeData::UpdatePaintNodeData()
: transformNode(0)
{
}
QQuickRootItem::QQuickRootItem()
{
}
/*! \reimp */
211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
void QQuickWindow::exposeEvent(QExposeEvent *)
{
Q_D(QQuickWindow);
if (d->windowManager)
d->windowManager->exposureChanged(this);
}
/*! \reimp */
void QQuickWindow::resizeEvent(QResizeEvent *ev)
{
Q_D(QQuickWindow);
if (d->contentItem)
d->contentItem->setSize(ev->size());
if (d->windowManager)
d->windowManager->resize(this);
}
/*! \reimp */
void QQuickWindow::showEvent(QShowEvent *)
{
Q_D(QQuickWindow);
if (d->windowManager)
d->windowManager->show(this);
}
/*! \reimp */
void QQuickWindow::hideEvent(QHideEvent *)
{
Q_D(QQuickWindow);
if (d->windowManager)
d->windowManager->hide(this);
}
/*! \reimp */
void QQuickWindow::focusOutEvent(QFocusEvent *ev)
{
Q_D(QQuickWindow);
d->contentItem->setFocus(false, ev->reason());
}
/*! \reimp */
void QQuickWindow::focusInEvent(QFocusEvent *ev)
{
Q_D(QQuickWindow);
d->contentItem->setFocus(true, ev->reason());
d->updateFocusItemTransform();
}
void QQuickWindowPrivate::polishItems()
{
int maxPolishCycles = 100000;
while (!itemsToPolish.isEmpty() && --maxPolishCycles > 0) {
QSet<QQuickItem *> itms = itemsToPolish;
itemsToPolish.clear();
for (QSet<QQuickItem *>::iterator it = itms.begin(); it != itms.end(); ++it) {
QQuickItem *item = *it;
QQuickItemPrivate::get(item)->polishScheduled = false;
item->updatePolish();
}
}
if (maxPolishCycles == 0)
qWarning("QQuickWindow: possible QQuickItem::polish() loop");
updateFocusItemTransform();
}
/*!
281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
* Schedules the window to render another frame.
*
* Calling QQuickWindow::update() differs from QQuickItem::update() in that
* it always triggers a repaint, regardless of changes in the underlying
* scene graph or not.
*/
void QQuickWindow::update()
{
Q_D(QQuickWindow);
if (d->windowManager)
d->windowManager->update(this);
else if (d->renderControl)
QQuickRenderControlPrivate::get(d->renderControl)->update();
}
void forcePolishHelper(QQuickItem *item)
{
if (item->flags() & QQuickItem::ItemHasContents) {
item->polish();
}
QList <QQuickItem *> items = item->childItems();
for (int i=0; i<items.size(); ++i)
forcePolishHelper(items.at(i));
}
/*!
Schedules polish events on all items in the scene.
*/
void QQuickWindow::forcePolish()
{
Q_D(QQuickWindow);
if (!screen())
return;
forcePolishHelper(d->contentItem);
}
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));
}
void QQuickWindowPrivate::syncSceneGraph()
{
QML_MEMORY_SCOPE_STRING("SceneGraph");
Q_Q(QQuickWindow);
animationController->beforeNodeSync();
emit q->beforeSynchronizing();
runAndClearJobs(&beforeSynchronizingJobs);
if (!renderer) {
forceUpdate(contentItem);
QSGRootNode *rootNode = new QSGRootNode;
rootNode->appendChildNode(QQuickItemPrivate::get(contentItem)->itemNode());
renderer = context->createRenderer();
renderer->setRootNode(rootNode);
}
updateDirtyNodes();
animationController->afterNodeSync();
351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
// Copy the current state of clearing from window into renderer.
renderer->setClearColor(clearColor);
QSGRenderer::ClearMode mode = QSGRenderer::ClearStencilBuffer | QSGRenderer::ClearDepthBuffer;
if (clearBeforeRendering)
mode |= QSGRenderer::ClearColorBuffer;
renderer->setClearMode(mode);
renderer->setCustomRenderMode(customRenderMode);
emit q->afterSynchronizing();
runAndClearJobs(&afterSynchronizingJobs);
context->endSync();
}
void QQuickWindowPrivate::renderSceneGraph(const QSize &size)
{
QML_MEMORY_SCOPE_STRING("SceneGraph");
Q_Q(QQuickWindow);
if (!renderer)
return;
animationController->advance();
emit q->beforeRendering();
runAndClearJobs(&beforeRenderingJobs);
int fboId = 0;
const qreal devicePixelRatio = q->devicePixelRatio();
renderer->setDeviceRect(QRect(QPoint(0, 0), size * devicePixelRatio));
if (renderTargetId) {
fboId = renderTargetId;
renderer->setViewportRect(QRect(QPoint(0, 0), renderTargetSize));
} else {
renderer->setViewportRect(QRect(QPoint(0, 0), size * devicePixelRatio));
}
renderer->setProjectionMatrixToRect(QRect(QPoint(0, 0), size));
renderer->setDevicePixelRatio(q->devicePixelRatio());
context->renderNextFrame(renderer, fboId);
emit q->afterRendering();
runAndClearJobs(&afterRenderingJobs);
}
QQuickWindowPrivate::QQuickWindowPrivate()
: contentItem(0)
, activeFocusItem(0)
, mouseGrabberItem(0)
#ifndef QT_NO_CURSOR
, cursorItem(0)
#endif
#ifndef QT_NO_DRAGANDDROP
, dragGrabber(0)
#endif
, touchMouseId(-1)
, touchMousePressTimestamp(0)
, dirtyItemList(0)
, context(0)
, renderer(0)
, windowManager(0)
, renderControl(0)
, touchRecursionGuard(0)
, clearColor(Qt::white)
, clearBeforeRendering(true)
, persistentGLContext(true)
, persistentSceneGraph(true)
, lastWheelEventAccepted(false)
, componentCompleted(true)
, lastFocusReason(Qt::OtherFocusReason)
, renderTarget(0)
, renderTargetId(0)
, vaoHelper(0)
421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
, incubationController(0)
{
#ifndef QT_NO_DRAGANDDROP
dragGrabber = new QQuickDragGrabber;
#endif
}
QQuickWindowPrivate::~QQuickWindowPrivate()
{
}
void QQuickWindowPrivate::init(QQuickWindow *c, QQuickRenderControl *control)
{
q_ptr = c;
Q_Q(QQuickWindow);
contentItem = new QQuickRootItem;
QQmlEngine::setObjectOwnership(contentItem, QQmlEngine::CppOwnership);
QQuickItemPrivate *contentItemPrivate = QQuickItemPrivate::get(contentItem);
contentItemPrivate->window = q;
contentItemPrivate->windowRefCount = 1;
contentItemPrivate->flags |= QQuickItem::ItemIsFocusScope;
contentItem->setSize(q->size());
customRenderMode = qgetenv("QSG_VISUALIZE");
renderControl = control;
if (renderControl)
QQuickRenderControlPrivate::get(renderControl)->window = q;
if (!renderControl)
windowManager = QSGRenderLoop::instance();
Q_ASSERT(windowManager || renderControl);
QSGContext *sg;
if (renderControl) {
QQuickRenderControlPrivate *renderControlPriv = QQuickRenderControlPrivate::get(renderControl);
sg = renderControlPriv->sg;
context = renderControlPriv->rc;
} else {
windowManager->addWindow(q);
sg = windowManager->sceneGraphContext();
context = windowManager->createRenderContext(sg);
}
q->setSurfaceType(QWindow::OpenGLSurface);
q->setFormat(q->defaultFormat());
animationController = new QQuickAnimatorController();
animationController->m_window = q;
delayedTouch = 0;
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);
QObject::connect(q, SIGNAL(focusObjectChanged(QObject*)), q, SIGNAL(activeFocusItemChanged()));
QObject::connect(q, SIGNAL(screenChanged(QScreen*)), q, SLOT(forcePolish()));
QObject::connect(q, SIGNAL(frameSwapped()), q, SLOT(runJobsAfterSwap()), Qt::DirectConnection);
}
/*!
\property QQuickWindow::data
\internal
*/
QQmlListProperty<QObject> QQuickWindowPrivate::data()
491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
{
return QQmlListProperty<QObject>(q_func(), 0, QQuickWindowPrivate::data_append,
QQuickWindowPrivate::data_count,
QQuickWindowPrivate::data_at,
QQuickWindowPrivate::data_clear);
}
static QMouseEvent *touchToMouseEvent(QEvent::Type type, const QTouchEvent::TouchPoint &p, QTouchEvent *event, QQuickItem *item, bool transformNeeded = true)
{
// The touch point local position and velocity are not yet transformed.
QMouseEvent *me = new QMouseEvent(type, transformNeeded ? item->mapFromScene(p.scenePos()) : p.pos(), p.scenePos(), p.screenPos(),
Qt::LeftButton, (type == QEvent::MouseButtonRelease ? Qt::NoButton : Qt::LeftButton), event->modifiers());
me->setAccepted(true);
me->setTimestamp(event->timestamp());
QVector2D transformedVelocity = p.velocity();
if (transformNeeded) {
QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item);
QMatrix4x4 transformMatrix(itemPrivate->windowToItemTransform());
transformedVelocity = transformMatrix.mapVector(p.velocity()).toVector2D();
}
QGuiApplicationPrivate::setMouseEventCapsAndVelocity(me, event->device()->capabilities(), transformedVelocity);
QGuiApplicationPrivate::setMouseEventSource(me, Qt::MouseEventSynthesizedByQt);
return me;
}
bool QQuickWindowPrivate::checkIfDoubleClicked(ulong newPressEventTimestamp)
{
bool doubleClicked;
if (touchMousePressTimestamp == 0) {
// just initialize the variable
touchMousePressTimestamp = newPressEventTimestamp;
doubleClicked = false;
} else {
ulong timeBetweenPresses = newPressEventTimestamp - touchMousePressTimestamp;
ulong doubleClickInterval = static_cast<ulong>(qApp->styleHints()->
mouseDoubleClickInterval());
doubleClicked = timeBetweenPresses < doubleClickInterval;
if (doubleClicked) {
touchMousePressTimestamp = 0;
} else {
touchMousePressTimestamp = newPressEventTimestamp;
}
}
return doubleClicked;
}
bool QQuickWindowPrivate::translateTouchToMouse(QQuickItem *item, QTouchEvent *event)
{
// For each point, check if it is accepted, if not, try the next point.
// Any of the fingers can become the mouse one.
// This can happen because a mouse area might not accept an event at some point but another.
for (int i = 0; i < event->touchPoints().count(); ++i) {
const QTouchEvent::TouchPoint &p = event->touchPoints().at(i);
// A new touch point
if (touchMouseId == -1 && p.state() & Qt::TouchPointPressed) {
QPointF pos = item->mapFromScene(p.scenePos());
// probably redundant, we check bounds in the calling function (matchingNewPoints)
if (!item->contains(pos))
break;
// Store the id already here and restore it to -1 if the event does not get
// accepted. Cannot defer setting the new value because otherwise if the event
// handler spins the event loop all subsequent moves and releases get lost.
touchMouseId = p.id();
itemForTouchPointId[touchMouseId] = item;
QScopedPointer<QMouseEvent> mousePress(touchToMouseEvent(QEvent::MouseButtonPress, p, event, item, false));
561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
// Send a single press and see if that's accepted
if (!mouseGrabberItem)
item->grabMouse();
item->grabTouchPoints(QVector<int>() << touchMouseId);
QCoreApplication::sendEvent(item, mousePress.data());
event->setAccepted(mousePress->isAccepted());
if (!mousePress->isAccepted()) {
touchMouseId = -1;
if (itemForTouchPointId.value(p.id()) == item)
itemForTouchPointId.remove(p.id());
if (mouseGrabberItem == item)
item->ungrabMouse();
}
if (mousePress->isAccepted() && checkIfDoubleClicked(event->timestamp())) {
QScopedPointer<QMouseEvent> mouseDoubleClick(touchToMouseEvent(QEvent::MouseButtonDblClick, p, event, item, false));
QCoreApplication::sendEvent(item, mouseDoubleClick.data());
event->setAccepted(mouseDoubleClick->isAccepted());
if (mouseDoubleClick->isAccepted()) {
touchMouseIdCandidates.clear();
return true;
} else {
touchMouseId = -1;
}
}
// The event was accepted, we are done.
if (mousePress->isAccepted()) {
touchMouseIdCandidates.clear();
return true;
}
// The event was not accepted but touchMouseId was set.
if (touchMouseId != -1)
return false;
// try the next point
// Touch point was there before and moved
} else if (p.id() == touchMouseId) {
if (p.state() & Qt::TouchPointMoved) {
if (mouseGrabberItem) {
QScopedPointer<QMouseEvent> me(touchToMouseEvent(QEvent::MouseMove, p, event, mouseGrabberItem, false));
QCoreApplication::sendEvent(item, me.data());
event->setAccepted(me->isAccepted());
if (me->isAccepted()) {
itemForTouchPointId[p.id()] = mouseGrabberItem; // N.B. the mouseGrabberItem may be different after returning from sendEvent()
return true;
}
} else {
// no grabber, check if we care about mouse hover
// FIXME: this should only happen once, not recursively... I'll ignore it just ignore hover now.
// hover for touch???
QScopedPointer<QMouseEvent> me(touchToMouseEvent(QEvent::MouseMove, p, event, item, false));
if (lastMousePosition.isNull())
lastMousePosition = me->windowPos();
QPointF last = lastMousePosition;
lastMousePosition = me->windowPos();
bool accepted = me->isAccepted();
bool delivered = deliverHoverEvent(contentItem, me->windowPos(), last, me->modifiers(), accepted);
if (!delivered) {
//take care of any exits
accepted = clearHover();
}
me->setAccepted(accepted);
break;
}
} else if (p.state() & Qt::TouchPointReleased) {
// currently handled point was released
touchMouseId = -1;
631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
if (mouseGrabberItem) {
QScopedPointer<QMouseEvent> me(touchToMouseEvent(QEvent::MouseButtonRelease, p, event, mouseGrabberItem, false));
QCoreApplication::sendEvent(item, me.data());
if (mouseGrabberItem) // might have ungrabbed due to event
mouseGrabberItem->ungrabMouse();
return me->isAccepted();
}
}
break;
}
}
return false;
}
void QQuickWindowPrivate::setMouseGrabber(QQuickItem *grabber)
{
Q_Q(QQuickWindow);
if (mouseGrabberItem == grabber)
return;
QQuickItem *oldGrabber = mouseGrabberItem;
mouseGrabberItem = grabber;
if (touchMouseId != -1) {
// update the touch item for mouse touch id to the new grabber
itemForTouchPointId.remove(touchMouseId);
if (grabber)
itemForTouchPointId[touchMouseId] = grabber;
}
if (oldGrabber) {
QEvent ev(QEvent::UngrabMouse);
q->sendEvent(oldGrabber, &ev);
}
}
void QQuickWindowPrivate::transformTouchPoints(QList<QTouchEvent::TouchPoint> &touchPoints, const QTransform &transform)
{
QMatrix4x4 transformMatrix(transform);
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()));
touchPoint.setVelocity(transformMatrix.mapVector(touchPoint.velocity()).toVector2D());
}
}
/*!
Translates the data in \a touchEvent to this window. This method leaves the item local positions in
\a touchEvent untouched (these are filled in later).
*/
void QQuickWindowPrivate::translateTouchEvent(QTouchEvent *touchEvent)
{
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());
if (i == 0)
lastMousePosition = touchPoint.pos().toPoint();
}
701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
touchEvent->setTouchPoints(touchPoints);
}
static inline bool windowHasFocus(QQuickWindow *win)
{
const QWindow *focusWindow = QGuiApplication::focusWindow();
return win == focusWindow || QQuickRenderControl::renderWindowFor(win) == focusWindow;
}
/*!
Set the focus inside \a scope to be \a item.
If the scope contains the active focus item, it will be changed to \a item.
Calls notifyFocusChangesRecur for all changed items.
*/
void QQuickWindowPrivate::setFocusInScope(QQuickItem *scope, QQuickItem *item, Qt::FocusReason reason, FocusOptions options)
{
Q_Q(QQuickWindow);
Q_ASSERT(item);
Q_ASSERT(scope || item == contentItem);
qCDebug(DBG_FOCUS) << "QQuickWindowPrivate::setFocusInScope():";
qCDebug(DBG_FOCUS) << " scope:" << (QObject *)scope;
if (scope)
qCDebug(DBG_FOCUS) << " scopeSubFocusItem:" << (QObject *)QQuickItemPrivate::get(scope)->subFocusItem;
qCDebug(DBG_FOCUS) << " item:" << (QObject *)item;
qCDebug(DBG_FOCUS) << " activeFocusItem:" << (QObject *)activeFocusItem;
QQuickItemPrivate *scopePrivate = scope ? QQuickItemPrivate::get(scope) : 0;
QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item);
QQuickItem *currentActiveFocusItem = activeFocusItem;
QQuickItem *newActiveFocusItem = 0;
lastFocusReason = reason;
QVarLengthArray<QQuickItem *, 20> changed;
// Does this change the active focus?
if (item == contentItem || scopePrivate->activeFocus) {
QQuickItem *oldActiveFocusItem = 0;
oldActiveFocusItem = activeFocusItem;
if (item->isEnabled()) {
newActiveFocusItem = item;
while (newActiveFocusItem->isFocusScope()
&& newActiveFocusItem->scopedFocusItem()
&& newActiveFocusItem->scopedFocusItem()->isEnabled()) {
newActiveFocusItem = newActiveFocusItem->scopedFocusItem();
}
} else {
newActiveFocusItem = scope;
}
if (oldActiveFocusItem) {
#ifndef QT_NO_IM
qApp->inputMethod()->commit();
#endif
activeFocusItem = 0;
QFocusEvent event(QEvent::FocusOut, reason);
q->sendEvent(oldActiveFocusItem, &event);
QQuickItem *afi = oldActiveFocusItem;
while (afi && afi != scope) {
if (QQuickItemPrivate::get(afi)->activeFocus) {
QQuickItemPrivate::get(afi)->activeFocus = false;
changed << afi;
}
afi = afi->parentItem();
771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
}
}
}
if (item != contentItem && !(options & DontChangeSubFocusItem)) {
QQuickItem *oldSubFocusItem = scopePrivate->subFocusItem;
if (oldSubFocusItem) {
QQuickItemPrivate::get(oldSubFocusItem)->focus = false;
changed << oldSubFocusItem;
}
QQuickItemPrivate::get(item)->updateSubFocusItem(scope, true);
}
if (!(options & DontChangeFocusProperty)) {
if (item != contentItem || windowHasFocus(q)) {
itemPrivate->focus = true;
changed << item;
}
}
if (newActiveFocusItem && contentItem->hasFocus()) {
activeFocusItem = newActiveFocusItem;
QQuickItemPrivate::get(newActiveFocusItem)->activeFocus = true;
changed << newActiveFocusItem;
QQuickItem *afi = newActiveFocusItem->parentItem();
while (afi && afi != scope) {
if (afi->isFocusScope()) {
QQuickItemPrivate::get(afi)->activeFocus = true;
changed << afi;
}
afi = afi->parentItem();
}
updateFocusItemTransform();
QFocusEvent event(QEvent::FocusIn, reason);
q->sendEvent(newActiveFocusItem, &event);
}
if (activeFocusItem != currentActiveFocusItem)
emit q->focusObjectChanged(activeFocusItem);
if (!changed.isEmpty())
notifyFocusChangesRecur(changed.data(), changed.count() - 1);
}
void QQuickWindowPrivate::clearFocusInScope(QQuickItem *scope, QQuickItem *item, Qt::FocusReason reason, FocusOptions options)
{
Q_Q(QQuickWindow);
Q_ASSERT(item);
Q_ASSERT(scope || item == contentItem);
qCDebug(DBG_FOCUS) << "QQuickWindowPrivate::clearFocusInScope():";
qCDebug(DBG_FOCUS) << " scope:" << (QObject *)scope;
qCDebug(DBG_FOCUS) << " item:" << (QObject *)item;
qCDebug(DBG_FOCUS) << " activeFocusItem:" << (QObject *)activeFocusItem;
QQuickItemPrivate *scopePrivate = 0;
if (scope) {
scopePrivate = QQuickItemPrivate::get(scope);
if ( !scopePrivate->subFocusItem )
return;//No focus, nothing to do.
}
QQuickItem *currentActiveFocusItem = activeFocusItem;
QQuickItem *oldActiveFocusItem = 0;
QQuickItem *newActiveFocusItem = 0;