qquickwindow.cpp 120.55 KiB
/****************************************************************************
**
** 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 <QtQml/qqmlincubator.h>
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
#include <QtQuick/private/qquickpixmapcache_p.h> #include <private/qqmlprofilerservice_p.h> #include <private/qqmlmemoryprofiler_p.h> QT_BEGIN_NAMESPACE extern Q_GUI_EXPORT QImage qt_gl_read_framebuffer(const QSize &size, bool alpha_format, bool include_alpha); bool QQuickWindowPrivate::defaultAlphaBuffer(0); 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); m_animation_driver = m_renderLoop->animationDriver(); if (m_animation_driver) { connect(m_animation_driver, 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() { if (incubatingObjectCount()) { if (m_renderLoop->interleaveIncubation()) { incubateFor(m_incubation_time); } else { incubateFor(m_incubation_time * 2); if (incubatingObjectCount()) incubateAgain(); } } }
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
void animationStopped() { incubate(); } protected: virtual void incubatingObjectCountChanged(int count) { if (count && !m_renderLoop->interleaveIncubation()) incubateAgain(); } private: QSGRenderLoop *m_renderLoop; int m_incubation_time; QAnimationDriver *m_animation_driver; 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. */ // #define FOCUS_DEBUG // #define MOUSE_DEBUG // #define TOUCH_DEBUG // #define DIRTY_DEBUG #ifdef FOCUS_DEBUG void printFocusTree(QQuickItem *item, QQuickItem *scope = 0, int depth = 1); #endif QQuickItem::UpdatePaintNodeData::UpdatePaintNodeData() : transformNode(0) { } QQuickRootItem::QQuickRootItem() { }
211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
/*! \reimp */ 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(); }