diff options
Diffstat (limited to 'src/quick/items/qquickwindow.cpp')
-rw-r--r-- | src/quick/items/qquickwindow.cpp | 270 |
1 files changed, 226 insertions, 44 deletions
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index 469ea4225c..176f46e3b7 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -50,7 +50,7 @@ #include <QtQuick/private/qsgtexture_p.h> #include <QtQuick/private/qsgflashnode_p.h> -#include <private/qquickwindowmanager_p.h> +#include <private/qsgrenderloop_p.h> #include <private/qguiapplication_p.h> #include <QtGui/QInputMethod> @@ -77,8 +77,11 @@ void QQuickWindowPrivate::updateFocusItemTransform() Q_Q(QQuickWindow); #ifndef QT_NO_IM QQuickItem *focus = q->activeFocusItem(); - if (focus && qApp->focusObject() == focus) - qApp->inputMethod()->setInputItemTransform(QQuickItemPrivate::get(focus)->itemToWindowTransform()); + 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 } @@ -221,17 +224,17 @@ void QQuickWindow::hideEvent(QHideEvent *) } /*! \reimp */ -void QQuickWindow::focusOutEvent(QFocusEvent *) +void QQuickWindow::focusOutEvent(QFocusEvent *ev) { Q_D(QQuickWindow); - d->contentItem->setFocus(false); + d->contentItem->setFocus(false, ev->reason()); } /*! \reimp */ -void QQuickWindow::focusInEvent(QFocusEvent *) +void QQuickWindow::focusInEvent(QFocusEvent *ev) { Q_D(QQuickWindow); - d->contentItem->setFocus(true); + d->contentItem->setFocus(true, ev->reason()); d->updateFocusItemTransform(); } @@ -345,6 +348,7 @@ void QQuickWindowPrivate::renderSceneGraph(const QSize &size) 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(); @@ -366,8 +370,8 @@ QQuickWindowPrivate::QQuickWindowPrivate() , windowManager(0) , clearColor(Qt::white) , clearBeforeRendering(true) - , persistentGLContext(false) - , persistentSceneGraph(false) + , persistentGLContext(true) + , persistentSceneGraph(true) , lastWheelEventAccepted(false) , renderTarget(0) , renderTargetId(0) @@ -392,13 +396,7 @@ void QQuickWindowPrivate::init(QQuickWindow *c) contentItemPrivate->windowRefCount = 1; contentItemPrivate->flags |= QQuickItem::ItemIsFocusScope; - // In the absence of a focus in event on some platforms assume the window will - // be activated immediately and set focus on the contentItem - // ### Remove when QTBUG-22415 is resolved. - //It is important that this call happens after the contentItem has a window.. - contentItem->setFocus(true); - - windowManager = QQuickWindowManager::instance(); + windowManager = QSGRenderLoop::instance(); context = windowManager->sceneGraphContext(); q->setSurfaceType(QWindow::OpenGLSurface); q->setFormat(context->defaultSurfaceFormat()); @@ -406,6 +404,8 @@ void QQuickWindowPrivate::init(QQuickWindow *c) 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())); } /*! @@ -611,7 +611,12 @@ void QQuickWindowPrivate::translateTouchEvent(QTouchEvent *touchEvent) touchEvent->setTouchPoints(touchPoints); } -void QQuickWindowPrivate::setFocusInScope(QQuickItem *scope, QQuickItem *item, FocusOptions options) +/*! +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); @@ -630,13 +635,13 @@ void QQuickWindowPrivate::setFocusInScope(QQuickItem *scope, QQuickItem *item, F QQuickItemPrivate *scopePrivate = scope ? QQuickItemPrivate::get(scope) : 0; QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); - QQuickItem *oldActiveFocusItem = 0; QQuickItem *newActiveFocusItem = 0; QVarLengthArray<QQuickItem *, 20> changed; // Does this change the active focus? if (item == contentItem || (scopePrivate->activeFocus && item->isEnabled())) { + QQuickItem *oldActiveFocusItem = 0; oldActiveFocusItem = activeFocusItem; newActiveFocusItem = item; while (newActiveFocusItem->isFocusScope() @@ -651,7 +656,7 @@ void QQuickWindowPrivate::setFocusInScope(QQuickItem *scope, QQuickItem *item, F #endif activeFocusItem = 0; - QFocusEvent event(QEvent::FocusOut, Qt::OtherFocusReason); + QFocusEvent event(QEvent::FocusOut, reason); q->sendEvent(oldActiveFocusItem, &event); QQuickItem *afi = oldActiveFocusItem; @@ -676,10 +681,10 @@ void QQuickWindowPrivate::setFocusInScope(QQuickItem *scope, QQuickItem *item, F } if (!(options & DontChangeFocusProperty)) { -// if (item != contentItem || QGuiApplication::focusWindow() == q) { // QTBUG-22415 + if (item != contentItem || QGuiApplication::focusWindow() == q) { itemPrivate->focus = true; changed << item; -// } + } } if (newActiveFocusItem && contentItem->hasFocus()) { @@ -696,8 +701,9 @@ void QQuickWindowPrivate::setFocusInScope(QQuickItem *scope, QQuickItem *item, F } afi = afi->parentItem(); } + updateFocusItemTransform(); - QFocusEvent event(QEvent::FocusIn, Qt::OtherFocusReason); + QFocusEvent event(QEvent::FocusIn, reason); q->sendEvent(newActiveFocusItem, &event); } @@ -707,7 +713,7 @@ void QQuickWindowPrivate::setFocusInScope(QQuickItem *scope, QQuickItem *item, F notifyFocusChangesRecur(changed.data(), changed.count() - 1); } -void QQuickWindowPrivate::clearFocusInScope(QQuickItem *scope, QQuickItem *item, FocusOptions options) +void QQuickWindowPrivate::clearFocusInScope(QQuickItem *scope, QQuickItem *item, Qt::FocusReason reason, FocusOptions options) { Q_Q(QQuickWindow); @@ -747,7 +753,7 @@ void QQuickWindowPrivate::clearFocusInScope(QQuickItem *scope, QQuickItem *item, #endif activeFocusItem = 0; - QFocusEvent event(QEvent::FocusOut, Qt::OtherFocusReason); + QFocusEvent event(QEvent::FocusOut, reason); q->sendEvent(oldActiveFocusItem, &event); QQuickItem *afi = oldActiveFocusItem; @@ -777,8 +783,9 @@ void QQuickWindowPrivate::clearFocusInScope(QQuickItem *scope, QQuickItem *item, if (newActiveFocusItem) { Q_ASSERT(newActiveFocusItem == scope); activeFocusItem = scope; + updateFocusItemTransform(); - QFocusEvent event(QEvent::FocusIn, Qt::OtherFocusReason); + QFocusEvent event(QEvent::FocusIn, reason); q->sendEvent(newActiveFocusItem, &event); } @@ -834,11 +841,11 @@ void QQuickWindowPrivate::cleanup(QSGNode *n) \brief 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 types. + window for use with QtQuick 2.x graphical types. To use this type, you will need to import the module with the following line: \code - import QtQuick.Window 2.0 + import QtQuick.Window 2.1 \endcode Restricting this import will allow you to have a QML environment without access to window system features. @@ -915,7 +922,7 @@ void QQuickWindowPrivate::cleanup(QSGNode *n) scene graph and its OpenGL context being deleted. The sceneGraphInvalidated() signal will be emitted when this happens. - \sa {OpenGL Under QML} + \sa {Scene Graph - OpenGL Under QML} */ @@ -929,6 +936,8 @@ QQuickWindow::QQuickWindow(QWindow *parent) d->init(this); } + + /*! \internal */ @@ -972,20 +981,32 @@ QQuickWindow::~QQuickWindow() void QQuickWindow::releaseResources() { Q_D(QQuickWindow); - d->windowManager->releaseResources(); + d->windowManager->releaseResources(this); QQuickPixmap::purgeCache(); } /*! - Sets whether the OpenGL context can be released as a part of a call to - releaseResources() to \a persistent. + Sets whether the OpenGL context can be released to \a + persistent. The default value is true. + + The OpenGL context can be released to free up graphics resources + when the window is obscured, hidden or not rendering. When this + happens is implementation specific. - The OpenGL context might still be released when the user makes an explicit - call to hide(). + The QOpenGLContext::aboutToBeDestroyed() signal is emitted from + the QQuickWindow::openglContext() when the OpenGL context is about + to be released. The QQuickWindow::sceneGraphInitialized() signal + is emitted when a new OpenGL context is created for this + window. Make a Qt::DirectConnection to these signals to be + notified. - \sa setPersistentSceneGraph() + The OpenGL context is still released when the last QQuickWindow is + deleted. + + \sa setPersistentSceneGraph(), + QOpenGLContext::aboutToBeDestroyed(), sceneGraphInitialized() */ void QQuickWindow::setPersistentOpenGLContext(bool persistent) @@ -995,9 +1016,13 @@ void QQuickWindow::setPersistentOpenGLContext(bool persistent) } + /*! - Returns whether the OpenGL context can be released as a part of a call to - releaseResources(). + Returns whether the OpenGL context can be released during the + lifetime of the QQuickWindow. + + \note This is a hint. When and how this happens is implementation + specific. */ bool QQuickWindow::isPersistentOpenGLContext() const @@ -1009,13 +1034,24 @@ bool QQuickWindow::isPersistentOpenGLContext() const /*! - Sets whether the scene graph nodes and resources can be released as a - part of a call to releaseResources() to \a persistent. + Sets whether the scene graph nodes and resources can be released + to \a persistent. The default value is true. + + The scene graph nodes and resources can be released to free up + graphics resources when the window is obscured, hidden or not + rendering. When this happens is implementation specific. + + The QQuickWindow::sceneGraphInvalidated() signal is emitted when + cleanup occurs. The QQuickWindow::sceneGraphInitialized() signal + is emitted when a new scene graph is recreated for this + window. Make a Qt::DirectConnection to these signals to be + notified. - The scene graph nodes and resources might still be released when the user - makes an explicit call to hide(). + The scene graph nodes and resources are still released when the + last QQuickWindow is deleted. - \sa setPersistentOpenGLContext() + \sa setPersistentOpenGLContext(), + sceneGraphInvalidated(), sceneGraphInitialized() */ void QQuickWindow::setPersistentSceneGraph(bool persistent) @@ -1027,8 +1063,11 @@ void QQuickWindow::setPersistentSceneGraph(bool persistent) /*! - Returns whether the scene graph nodes and resources can be released as a part - of a call to releaseResources(). + Returns whether the scene graph nodes and resources can be + released during the lifetime of this QQuickWindow. + + \note This is a hint. When and how this happens is implementation + specific. */ bool QQuickWindow::isPersistentSceneGraph() const @@ -1161,6 +1200,12 @@ void QQuickWindow::keyPressEvent(QKeyEvent *e) { Q_D(QQuickWindow); +#ifndef QT_NO_SHORTCUT + // Try looking for a Shortcut before sending key events + if (QGuiApplicationPrivate::instance()->shortcutMap.tryShortcutEvent(focusObject(), e)) + return; +#endif + if (d->activeFocusItem) sendEvent(d->activeFocusItem, e); } @@ -2783,6 +2828,14 @@ void QQuickWindow::setColor(const QColor &color) if (color == d->clearColor) return; + if (color.alpha() != d->clearColor.alpha()) { + QSurfaceFormat fmt = format(); + if (color.alpha() < 255) + fmt.setAlphaBufferSize(8); + else + fmt.setAlphaBufferSize(-1); + setFormat(fmt); + } d->clearColor = color; emit colorChanged(color); d->dirtyItem(contentItem()); @@ -2805,7 +2858,7 @@ QColor QQuickWindow::color() const */ /*! - \qmlproperty string QtQuick.Window2::Window::modality + \qmlproperty Qt::WindowModality QtQuick.Window2::Window::modality The modality of the window. @@ -2814,6 +2867,135 @@ QColor QQuickWindow::color() const and Qt.ApplicationModal. */ +/*! + \qmlproperty Qt::WindowFlags QtQuick.Window2::Window::flags + + The window flags of the window. + + The window flags control the window's appearance in the windowing system, + whether it's a dialog, popup, or a regular window, and whether it should + have a title bar, etc. + + The flags which you read from this property might differ from the ones + that you set if the requested flags could not be fulfilled. + */ + +/*! + \qmlproperty int QtQuick.Window2::Window::x + \qmlproperty int QtQuick.Window2::Window::y + \qmlproperty int QtQuick.Window2::Window::width + \qmlproperty int QtQuick.Window2::Window::height + + Defines the window's position and size. + + The (x,y) position is relative to the \l Screen if there is only one, + or to the virtual desktop (arrangement of multiple screens). + + \qml + Window { x: 100; y: 100; width: 100; height: 100 } + \endqml + + \image screen-and-window-dimensions.jpg + */ + +/*! + \qmlproperty int QtQuick.Window2::Window::minimumWidth + \qmlproperty int QtQuick.Window2::Window::minimumHeight + \since Qt 5.1 + + Defines the window's minimum size. + + This is a hint to the window manager to prevent resizing below the specified + width and height. + */ + +/*! + \qmlproperty int QtQuick.Window2::Window::maximumWidth + \qmlproperty int QtQuick.Window2::Window::maximumHeight + \since Qt 5.1 + + Defines the window's maximum size. + + This is a hint to the window manager to prevent resizing above the specified + width and height. + */ + +/*! + \qmlproperty bool QtQuick.Window2::Window::visible + + Whether the window is visible on the screen. + + Setting visible to false is the same as setting \l visibility to Hidden. + + \sa visibility + */ + +/*! + \qmlproperty QWindow::Visibility QtQuick.Window2::Window::visibility + + The screen-occupation state of the window. + + Visibility is whether the window should appear in the windowing system as + normal, minimized, maximized, fullscreen or hidden. + + To set the visibility to AutomaticVisibility means to give the window a + default visible state, which might be fullscreen or windowed depending on + the platform. However when reading the visibility property you will always + get the actual state, never AutomaticVisibility. + + When a window is not visible its visibility is Hidden, and setting + visibility to Hidden is the same as setting \l visible to false. + + \sa visible + \since Qt 5.1 + */ + +/*! + \qmlproperty Qt::ScreenOrientation QtQuick.Window2::Window::contentOrientation + + This is a hint to the window manager in case it needs to display + additional content like popups, dialogs, status bars, or similar + in relation to the window. + + The recommended orientation is \l Screen.orientation, but + an application doesn't have to support all possible orientations, + and thus can opt to ignore the current screen orientation. + + The difference between the window and the content orientation + determines how much to rotate the content by. + + The default value is Qt::PrimaryOrientation. + + \sa Screen + + \since Qt 5.1 + */ + +/*! + \qmlproperty real QtQuick.Window2::Window::opacity + + The opacity of the window. + + If the windowing system supports window opacity, this can be used to fade the + window in and out, or to make it semitransparent. + + A value of 1.0 or above is treated as fully opaque, whereas a value of 0.0 or below + is treated as fully transparent. Values inbetween represent varying levels of + translucency between the two extremes. + + The default value is 1.0. + + \since Qt 5.1 + */ + +/*! + \qmlproperty Item QtQuick.Window2::Window::activeFocusItem + \since Qt 5.1 + + The item which currently has active focus or \c null if there is + no item with active focus. + */ + #include "moc_qquickwindow.cpp" QT_END_NAMESPACE |