From e7bf0edfd49de9a4d8285fbe8d878f8fda910e6d Mon Sep 17 00:00:00 2001 From: Andreas Hartmetz Date: Tue, 19 Jan 2016 14:30:18 +0100 Subject: Add option to disable "session management by closing windows". That feature is a poor man's session management for applications that do not implement any specific session management features. It badly interferes with proper session management support, so applications must be able to disable it. This enables fixing applications with QGuiApplication::quitOnLastWindowClosed() true - the default - dying too early, before they are enumerated for the list of applications to restart on session restore, thus preventing them from being restored. See https://bugs.kde.org/show_bug.cgi?id=354724 [ChangeLog][QtGui] Qt asking to close windows on session exit as a fallback session management mechanism has been made optional. Disabling it fixes session management for applications that implement full session management. See QGuiApplication::isFallbackSessionManagementEnabled(). Task-number: QTBUG-49667 Change-Id: Ib22e58c9c64351dea8b7e2a74db91d26dd7ab7aa Reviewed-by: Oswald Buddenhagen Reviewed-by: David Faure --- src/gui/kernel/qguiapplication.cpp | 60 ++++++++++++++++++++++++++++++++++++-- src/gui/kernel/qguiapplication.h | 3 ++ src/gui/kernel/qguiapplication_p.h | 1 + src/gui/kernel/qsessionmanager.cpp | 19 ++++++------ 4 files changed, 71 insertions(+), 12 deletions(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 65d679cdad..8f1c62fbca 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -138,6 +138,8 @@ QPlatformTheme *QGuiApplicationPrivate::platform_theme = 0; QList QGuiApplicationPrivate::generic_plugin_list; +bool QGuiApplicationPrivate::is_fallback_session_management_enabled = true; + enum ApplicationResourceFlags { ApplicationPaletteExplicitlySet = 0x1, @@ -3082,6 +3084,55 @@ void QGuiApplicationPrivate::setApplicationState(Qt::ApplicationState state, boo emit qApp->applicationStateChanged(applicationState); } +// ### Qt6: consider removing the feature or making it less intrusive +/*! + \since 5.6 + + Returns whether QGuiApplication will use fallback session management. + + The default is \c true. + + If this is \c true and the session manager allows user interaction, + QGuiApplication will try to close toplevel windows after + commitDataRequest() has been emitted. If a window cannot be closed, session + shutdown will be canceled and the application will keep running. + + Fallback session management only benefits applications that have an + "are you sure you want to close this window?" feature or other logic that + prevents closing a toplevel window depending on certain conditions, and + that do nothing to explicitly implement session management. In applications + that \e do implement session management using the proper session management + API, fallback session management interferes and may break session + management logic. + + \warning If all windows \e are closed due to fallback session management + and quitOnLastWindowClosed() is \c true, the application will quit before + it is explicitly instructed to quit through the platform's session + management protocol. That violation of protocol may prevent the platform + session manager from saving application state. + + \sa setFallbackSessionManagementEnabled(), + QSessionManager::allowsInteraction(), saveStateRequest(), + commitDataRequest(), {Session Management} +*/ +bool QGuiApplication::isFallbackSessionManagementEnabled() +{ + return QGuiApplicationPrivate::is_fallback_session_management_enabled; +} + +/*! + \since 5.6 + + Sets whether QGuiApplication will use fallback session management to + \a enabled. + + \sa isFallbackSessionManagementEnabled() +*/ +void QGuiApplication::setFallbackSessionManagementEnabled(bool enabled) +{ + QGuiApplicationPrivate::is_fallback_session_management_enabled = enabled; +} + /*! \since 4.2 \fn void QGuiApplication::commitDataRequest(QSessionManager &manager) @@ -3106,7 +3157,8 @@ void QGuiApplicationPrivate::setApplicationState(Qt::ApplicationState state, boo \note You should use Qt::DirectConnection when connecting to this signal. - \sa isSessionRestored(), sessionId(), saveStateRequest(), {Session Management} + \sa setFallbackSessionManagementEnabled(), isSessionRestored(), + sessionId(), saveStateRequest(), {Session Management} */ /*! @@ -3236,9 +3288,13 @@ void QGuiApplicationPrivate::commitData() { Q_Q(QGuiApplication); is_saving_session = true; + emit q->commitDataRequest(*session_manager); - if (session_manager->allowsInteraction() && !tryCloseAllWindows()) + if (is_fallback_session_management_enabled && session_manager->allowsInteraction() + && !tryCloseAllWindows()) { session_manager->cancel(); + } + is_saving_session = false; } diff --git a/src/gui/kernel/qguiapplication.h b/src/gui/kernel/qguiapplication.h index d995387d66..3f233d4eda 100644 --- a/src/gui/kernel/qguiapplication.h +++ b/src/gui/kernel/qguiapplication.h @@ -152,6 +152,9 @@ public: QString sessionId() const; QString sessionKey() const; bool isSavingSession() const; + + static bool isFallbackSessionManagementEnabled(); + static void setFallbackSessionManagementEnabled(bool); #endif static void sync(); diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index 7c7da9790b..4f0f6fdc44 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -234,6 +234,7 @@ public: #endif #ifndef QT_NO_SESSIONMANAGER + static bool is_fallback_session_management_enabled; QSessionManager *session_manager; bool is_session_restored; bool is_saving_session; diff --git a/src/gui/kernel/qsessionmanager.cpp b/src/gui/kernel/qsessionmanager.cpp index f4b56fd01b..c6d23f163c 100644 --- a/src/gui/kernel/qsessionmanager.cpp +++ b/src/gui/kernel/qsessionmanager.cpp @@ -64,22 +64,21 @@ QT_BEGIN_NAMESPACE settings. QSessionManager provides an interface between the application and the - session manager so that the program can work well with the session manager. - In Qt, session management requests for action are handled by the two - signals QGuiApplication::commitDataRequest() and - QGuiApplication::saveStateRequest(). Both provide a reference to a session - manager object as argument, to allow the application to communicate with - the session manager. The session manager can only be accessed through these - functions. + platform's session manager. In Qt, session management requests for action + are handled by the two signals QGuiApplication::commitDataRequest() and + QGuiApplication::saveStateRequest(). Both provide a reference to a + QSessionManager object as argument. The session manager can only be + accessed in slots invoked by these signals. + + \warning If you use QSessionManager, you should disable fallback session + management: QGuiApplication::setFallbackSessionManagementEnabled(). No user interaction is possible \e unless the application gets explicit permission from the session manager. You ask for permission by calling allowsInteraction() or, if it is really urgent, allowsErrorInteraction(). Qt does not enforce this, but the session manager may. - You can try to abort the shutdown process by calling cancel(). The default - commitData() function does this if some top-level window rejected its - closeEvent(). + You can try to abort the shutdown process by calling cancel(). For sophisticated session managers provided on Unix/X11, QSessionManager offers further possibilities to fine-tune an application's session -- cgit v1.2.3 From 719623a11d57da6a56d069a5ca8161531a37776b Mon Sep 17 00:00:00 2001 From: Andreas Hartmetz Date: Wed, 17 Feb 2016 21:33:25 +0100 Subject: Fix builds without session management. My previous change broke it. Change-Id: I3c3a9a65775032a95eebf3526c1bbf2c50773230 Reviewed-by: Samuli Piippo --- src/gui/kernel/qguiapplication.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 8f1c62fbca..95e47e18a9 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -138,7 +138,9 @@ QPlatformTheme *QGuiApplicationPrivate::platform_theme = 0; QList QGuiApplicationPrivate::generic_plugin_list; +#ifndef QT_NO_SESSIONMANAGER bool QGuiApplicationPrivate::is_fallback_session_management_enabled = true; +#endif enum ApplicationResourceFlags { @@ -3084,6 +3086,7 @@ void QGuiApplicationPrivate::setApplicationState(Qt::ApplicationState state, boo emit qApp->applicationStateChanged(applicationState); } +#ifndef QT_NO_SESSIONMANAGER // ### Qt6: consider removing the feature or making it less intrusive /*! \since 5.6 @@ -3132,6 +3135,7 @@ void QGuiApplication::setFallbackSessionManagementEnabled(bool enabled) { QGuiApplicationPrivate::is_fallback_session_management_enabled = enabled; } +#endif // QT_NO_SESSIONMANAGER /*! \since 4.2 -- cgit v1.2.3 From 837d75eed500bd0138d78c60edc54d0dd75967cf Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 26 Feb 2016 13:24:05 +0100 Subject: qt_handleTouchEvent(): Scale coordinates when converting touch points. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove outdated static functions to convert touch points and use QWindowSystemInterfacePrivate::fromNativeTouchPoints(). Fix tst_QWidget::underMouse() to pass when High DPI scaling is in effect. .\tst_qwidget.cpp(9000) : failure location FAIL! : tst_QWidget::underMouse() 'childWidget1.underMouse()' returned FALSE. () .\tst_qwidget.cpp(10161) : failure location Task-number: QTBUG-46615 Change-Id: Ie73dba610da357e7be396f2ea0229987f7503462 Reviewed-by: Morten Johan Sørvig --- src/gui/kernel/qwindowsysteminterface.cpp | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp index e10ddf22a7..b0772e7a96 100644 --- a/src/gui/kernel/qwindowsysteminterface.cpp +++ b/src/gui/kernel/qwindowsysteminterface.cpp @@ -906,36 +906,14 @@ Q_GUI_EXPORT bool qt_sendShortcutOverrideEvent(QObject *o, ulong timestamp, int #endif } -static QWindowSystemInterface::TouchPoint touchPoint(const QTouchEvent::TouchPoint& pt) -{ - QWindowSystemInterface::TouchPoint p; - p.id = pt.id(); - p.flags = pt.flags(); - p.normalPosition = pt.normalizedPos(); - p.area = pt.screenRect(); - p.pressure = pt.pressure(); - p.state = pt.state(); - p.velocity = pt.velocity(); - p.rawPositions = pt.rawScreenPositions(); - return p; -} -static QList touchPointList(const QList& pointList) -{ - QList newList; - - Q_FOREACH (QTouchEvent::TouchPoint p, pointList) - newList.append(touchPoint(p)); - - return newList; -} - Q_GUI_EXPORT void qt_handleTouchEvent(QWindow *w, QTouchDevice *device, const QList &points, Qt::KeyboardModifiers mods = Qt::NoModifier) { bool wasSynchronous = QWindowSystemInterfacePrivate::synchronousWindowSystemEvents; QWindowSystemInterface::setSynchronousWindowSystemEvents(true); - QWindowSystemInterface::handleTouchEvent(w, device, touchPointList(points), mods); + QWindowSystemInterface::handleTouchEvent(w, device, + QWindowSystemInterfacePrivate::toNativeTouchPoints(points, w), mods); QWindowSystemInterface::setSynchronousWindowSystemEvents(wasSynchronous); } -- cgit v1.2.3 From defd302f64f213a8764875a88788dbcea76d66f0 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 26 Feb 2016 13:22:36 +0100 Subject: qt_handleMouseEvent(): Scale coordinates. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix tst_qwindow::testInputEvents() to pass when High DPI scaling is in effect. FAIL! : tst_QWindow::testInputEvents() Compared values are not the same Actual (window.mousePressLocalPos): QPointF(6,17) Expected (local) : QPointF(12,34) .\tst_qwindow.cpp(771) : failure location Task-number: QTBUG-46615 Change-Id: I1ccacc807f3390b6ab26a369d13fd7896e64cbca Reviewed-by: Morten Johan Sørvig --- src/gui/kernel/qwindowsysteminterface.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp index b0772e7a96..841e4f8f41 100644 --- a/src/gui/kernel/qwindowsysteminterface.cpp +++ b/src/gui/kernel/qwindowsysteminterface.cpp @@ -857,7 +857,9 @@ Q_GUI_EXPORT void qt_handleMouseEvent(QWindow *w, const QPointF &local, const QP { bool wasSynchronous = QWindowSystemInterfacePrivate::synchronousWindowSystemEvents; QWindowSystemInterface::setSynchronousWindowSystemEvents(true); - QWindowSystemInterface::handleMouseEvent(w, timestamp, local, global, b, mods); + const qreal factor = QHighDpiScaling::factor(w); + QWindowSystemInterface::handleMouseEvent(w, timestamp, local * factor, + global * factor, b, mods); QWindowSystemInterface::setSynchronousWindowSystemEvents(wasSynchronous); } -- cgit v1.2.3 From 29d8159c4478a5275d2ea102daf270a91ed7e92e Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 29 Jan 2016 10:43:35 +0100 Subject: Avoid repeated QByteArray creation when resolving opengl functions Add an getProcAddress(const char *) overload to QOpenGLContext, and refactor the QPA interface to take a const char *. Like this we can avoid lots of mallocs when resoving GL methods. Change-Id: Ic45b985fbaa0da8d32ba3e3b485351173352ca6f Reviewed-by: Laszlo Agocs Reviewed-by: Sean Harmer --- src/gui/kernel/qopenglcontext.cpp | 11 ++++++++++- src/gui/kernel/qopenglcontext.h | 1 + src/gui/kernel/qplatformopenglcontext.cpp | 5 ++--- src/gui/kernel/qplatformopenglcontext.h | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp index b45396ab3c..f301b21ec1 100644 --- a/src/gui/kernel/qopenglcontext.cpp +++ b/src/gui/kernel/qopenglcontext.cpp @@ -1069,10 +1069,19 @@ void QOpenGLContext::swapBuffers(QSurface *surface) Returns 0 if no such function can be found. */ QFunctionPointer QOpenGLContext::getProcAddress(const QByteArray &procName) const +{ + return getProcAddress(procName.constData()); +} + +/*! + \overload + \since 5.8 + */ +QFunctionPointer QOpenGLContext::getProcAddress(const char *procName) const { Q_D(const QOpenGLContext); if (!d->platformGLContext) - return 0; + return nullptr; return d->platformGLContext->getProcAddress(procName); } diff --git a/src/gui/kernel/qopenglcontext.h b/src/gui/kernel/qopenglcontext.h index 56eb6f0e12..130d55464f 100644 --- a/src/gui/kernel/qopenglcontext.h +++ b/src/gui/kernel/qopenglcontext.h @@ -174,6 +174,7 @@ public: void swapBuffers(QSurface *surface); QFunctionPointer getProcAddress(const QByteArray &procName) const; + QFunctionPointer getProcAddress(const char *procName) const; QSurface *surface() const; diff --git a/src/gui/kernel/qplatformopenglcontext.cpp b/src/gui/kernel/qplatformopenglcontext.cpp index 2457a5237d..5b375f7883 100644 --- a/src/gui/kernel/qplatformopenglcontext.cpp +++ b/src/gui/kernel/qplatformopenglcontext.cpp @@ -71,10 +71,9 @@ QT_BEGIN_NAMESPACE The implementation must support being called in a thread different than the gui-thread. */ -/*! \fn QFunctionPointer QPlatformOpenGLContext::getProcAddress(const QByteArray &procName) - Reimplement in subclass to native getProcAddr calls. +/*! \fn QFunctionPointer QPlatformOpenGLContext::getProcAddress(const char *procName) - Note: its convenient to use qPrintable(const QString &str) to get the const char * pointer + Reimplement in subclass to native getProcAddr calls. */ class QPlatformOpenGLContextPrivate diff --git a/src/gui/kernel/qplatformopenglcontext.h b/src/gui/kernel/qplatformopenglcontext.h index f2ec1c1a7e..1a38a5fed3 100644 --- a/src/gui/kernel/qplatformopenglcontext.h +++ b/src/gui/kernel/qplatformopenglcontext.h @@ -83,7 +83,7 @@ public: virtual bool isSharing() const { return false; } virtual bool isValid() const { return true; } - virtual QFunctionPointer getProcAddress(const QByteArray &procName) = 0; + virtual QFunctionPointer getProcAddress(const char *procName) = 0; QOpenGLContext *context() const; -- cgit v1.2.3 From 5e9a5246fb688a33ff27bed010226595f579f23d Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 2 Feb 2016 12:50:33 +0100 Subject: Ensure we can query all GL functions in all platform plugins This is required to simplify our code in the opengl classes and makes it possible to remove OS dependent code paths in Qt Gui. Change-Id: Ice09440840c86b2d6ac8d3955d273846695338d4 Reviewed-by: Laszlo Agocs --- src/gui/kernel/qplatformintegration.cpp | 6 ++++-- src/gui/kernel/qplatformopenglcontext.cpp | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qplatformintegration.cpp b/src/gui/kernel/qplatformintegration.cpp index 06e41f7364..a0e65654a6 100644 --- a/src/gui/kernel/qplatformintegration.cpp +++ b/src/gui/kernel/qplatformintegration.cpp @@ -224,7 +224,8 @@ QPlatformServices *QPlatformIntegration::services() const platforms where no window management is available, meaning for example that windows are never repositioned by the window manager. The default implementation returns \c true. - \value AllGLFunctionsQueryable The QOpenGLContext backend provided by the platform is + \value AllGLFunctionsQueryable Deprecated. Used to indicate whether the QOpenGLContext + backend provided by the platform is able to return function pointers from getProcAddress() even for standard OpenGL functions, for example OpenGL 1 functions like glClear() or glDrawArrays(). This is important because the OpenGL specifications do not require this ability from the @@ -232,7 +233,8 @@ QPlatformServices *QPlatformIntegration::services() const platform plugins may however choose to enhance the behavior in the backend implementation for QOpenGLContext::getProcAddress() and support returning a function pointer also for the standard, non-extension functions. This capability is a - prerequisite for dynamic OpenGL loading. + prerequisite for dynamic OpenGL loading. Starting with Qt 5.7, the platform plugin + is required to have this capability. \value ApplicationIcon The platform supports setting the application icon. (since 5.5) */ diff --git a/src/gui/kernel/qplatformopenglcontext.cpp b/src/gui/kernel/qplatformopenglcontext.cpp index 5b375f7883..07b5a0dda6 100644 --- a/src/gui/kernel/qplatformopenglcontext.cpp +++ b/src/gui/kernel/qplatformopenglcontext.cpp @@ -73,7 +73,9 @@ QT_BEGIN_NAMESPACE /*! \fn QFunctionPointer QPlatformOpenGLContext::getProcAddress(const char *procName) - Reimplement in subclass to native getProcAddr calls. + Reimplement in subclass to allow dynamic querying of OpenGL symbols. As opposed to e.g. the wglGetProcAddress + function on Windows, Qt expects this methods to be able to return valid function pointers even for standard + OpenGL symbols. */ class QPlatformOpenGLContextPrivate -- cgit v1.2.3 From d56203436a2e59c35e0243ad86338d131de62f20 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 3 Feb 2016 10:11:13 +0100 Subject: Use an enum for versioning the opengl function backends Saves some code, is easier to maintain and will allow for some more nice refactoring. Change-Id: Ica7ae8e9d36acbe6586e488bc6aff114336c65bb Reviewed-by: Laszlo Agocs --- src/gui/kernel/qopenglcontext.cpp | 7 +++---- src/gui/kernel/qopenglcontext.h | 7 +++---- src/gui/kernel/qopenglcontext_p.h | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp index f301b21ec1..a45217ca29 100644 --- a/src/gui/kernel/qopenglcontext.cpp +++ b/src/gui/kernel/qopenglcontext.cpp @@ -1302,7 +1302,7 @@ QOpenGLContext *QOpenGLContext::globalShareContext() /*! \internal */ -QOpenGLVersionFunctionsBackend *QOpenGLContext::functionsBackend(const QOpenGLVersionStatus &v) const +QOpenGLVersionFunctionsBackend *QOpenGLContext::functionsBackend(const QOpenGLVersionFunctionsBackend::Version v) const { Q_D(const QOpenGLContext); return d->versionFunctionsBackend.value(v, 0); @@ -1311,8 +1311,7 @@ QOpenGLVersionFunctionsBackend *QOpenGLContext::functionsBackend(const QOpenGLVe /*! \internal */ -void QOpenGLContext::insertFunctionsBackend(const QOpenGLVersionStatus &v, - QOpenGLVersionFunctionsBackend *backend) +void QOpenGLContext::insertFunctionsBackend(const QOpenGLVersionFunctionsBackend::Version v, QOpenGLVersionFunctionsBackend *backend) { Q_D(QOpenGLContext); d->versionFunctionsBackend.insert(v, backend); @@ -1321,7 +1320,7 @@ void QOpenGLContext::insertFunctionsBackend(const QOpenGLVersionStatus &v, /*! \internal */ -void QOpenGLContext::removeFunctionsBackend(const QOpenGLVersionStatus &v) +void QOpenGLContext::removeFunctionsBackend(const QOpenGLVersionFunctionsBackend::Version v) { Q_D(QOpenGLContext); d->versionFunctionsBackend.remove(v); diff --git a/src/gui/kernel/qopenglcontext.h b/src/gui/kernel/qopenglcontext.h index 130d55464f..9bb48ab4fc 100644 --- a/src/gui/kernel/qopenglcontext.h +++ b/src/gui/kernel/qopenglcontext.h @@ -237,10 +237,9 @@ private: void setQGLContextHandle(void *handle,void (*qGLContextDeleteFunction)(void *)); void deleteQGLContext(); - QOpenGLVersionFunctionsBackend* functionsBackend(const QOpenGLVersionStatus &v) const; - void insertFunctionsBackend(const QOpenGLVersionStatus &v, - QOpenGLVersionFunctionsBackend *backend); - void removeFunctionsBackend(const QOpenGLVersionStatus &v); + QOpenGLVersionFunctionsBackend* functionsBackend(QOpenGLVersionFunctionsBackend::Version v) const; + void insertFunctionsBackend(const QOpenGLVersionFunctionsBackend::Version v, QOpenGLVersionFunctionsBackend *backend); + void removeFunctionsBackend(const QOpenGLVersionFunctionsBackend::Version v); void insertExternalFunctions(QAbstractOpenGLFunctions *f); void removeExternalFunctions(QAbstractOpenGLFunctions *f); diff --git a/src/gui/kernel/qopenglcontext_p.h b/src/gui/kernel/qopenglcontext_p.h index 7fc922f388..57053a6d61 100644 --- a/src/gui/kernel/qopenglcontext_p.h +++ b/src/gui/kernel/qopenglcontext_p.h @@ -222,7 +222,7 @@ public: } mutable QHash versionFunctions; - mutable QHash versionFunctionsBackend; + mutable QHash versionFunctionsBackend; mutable QSet externalVersionFunctions; void *qGLContextHandle; -- cgit v1.2.3 From 6b0a577bf85845780e9a7b101260cdf72fa1d33c Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 3 Feb 2016 12:42:52 +0100 Subject: Refactor initialization/caching code for versioned opengl functions Saves around 80k in Qt Gui. Change-Id: I3f7068ae699136d0edf46a49694ade7e1df3c91d Reviewed-by: Laszlo Agocs --- src/gui/kernel/qopenglcontext.cpp | 24 ++---------------------- src/gui/kernel/qopenglcontext.h | 4 +--- src/gui/kernel/qopenglcontext_p.h | 2 +- 3 files changed, 4 insertions(+), 26 deletions(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp index a45217ca29..61324d73f3 100644 --- a/src/gui/kernel/qopenglcontext.cpp +++ b/src/gui/kernel/qopenglcontext.cpp @@ -661,8 +661,6 @@ void QOpenGLContext::destroy() d->externalVersionFunctions.clear(); qDeleteAll(d->versionFunctions); d->versionFunctions.clear(); - qDeleteAll(d->versionFunctionsBackend); - d->versionFunctionsBackend.clear(); delete d->textureFunctions; d->textureFunctions = 0; @@ -1302,28 +1300,10 @@ QOpenGLContext *QOpenGLContext::globalShareContext() /*! \internal */ -QOpenGLVersionFunctionsBackend *QOpenGLContext::functionsBackend(const QOpenGLVersionFunctionsBackend::Version v) const +QOpenGLVersionFunctionsStorage *QOpenGLContext::functionsBackendStorage() const { Q_D(const QOpenGLContext); - return d->versionFunctionsBackend.value(v, 0); -} - -/*! - \internal -*/ -void QOpenGLContext::insertFunctionsBackend(const QOpenGLVersionFunctionsBackend::Version v, QOpenGLVersionFunctionsBackend *backend) -{ - Q_D(QOpenGLContext); - d->versionFunctionsBackend.insert(v, backend); -} - -/*! - \internal -*/ -void QOpenGLContext::removeFunctionsBackend(const QOpenGLVersionFunctionsBackend::Version v) -{ - Q_D(QOpenGLContext); - d->versionFunctionsBackend.remove(v); + return &d->versionFunctionsStorage; } /*! diff --git a/src/gui/kernel/qopenglcontext.h b/src/gui/kernel/qopenglcontext.h index 9bb48ab4fc..33e3f1c3f6 100644 --- a/src/gui/kernel/qopenglcontext.h +++ b/src/gui/kernel/qopenglcontext.h @@ -237,9 +237,7 @@ private: void setQGLContextHandle(void *handle,void (*qGLContextDeleteFunction)(void *)); void deleteQGLContext(); - QOpenGLVersionFunctionsBackend* functionsBackend(QOpenGLVersionFunctionsBackend::Version v) const; - void insertFunctionsBackend(const QOpenGLVersionFunctionsBackend::Version v, QOpenGLVersionFunctionsBackend *backend); - void removeFunctionsBackend(const QOpenGLVersionFunctionsBackend::Version v); + QOpenGLVersionFunctionsStorage* functionsBackendStorage() const; void insertExternalFunctions(QAbstractOpenGLFunctions *f); void removeExternalFunctions(QAbstractOpenGLFunctions *f); diff --git a/src/gui/kernel/qopenglcontext_p.h b/src/gui/kernel/qopenglcontext_p.h index 57053a6d61..4a5fbab364 100644 --- a/src/gui/kernel/qopenglcontext_p.h +++ b/src/gui/kernel/qopenglcontext_p.h @@ -222,7 +222,7 @@ public: } mutable QHash versionFunctions; - mutable QHash versionFunctionsBackend; + mutable QOpenGLVersionFunctionsStorage versionFunctionsStorage; mutable QSet externalVersionFunctions; void *qGLContextHandle; -- cgit v1.2.3 From 1bd24e5b0c7c329e8e6b00e85d2d360abf5630c6 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 24 Jun 2015 09:48:50 +0200 Subject: QtGui: Mark some more types as shared for Qt 6. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Marking them shared (which implies movable) now would make QLists of these BiC. Change-Id: If5638e8d9f43e0ad549aedf08934de31e1e189f1 Reviewed-by: Lars Knoll Reviewed-by: Jędrzej Nowacki --- src/gui/kernel/qcursor.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qcursor.h b/src/gui/kernel/qcursor.h index 1b11bad69f..814e8ab7bd 100644 --- a/src/gui/kernel/qcursor.h +++ b/src/gui/kernel/qcursor.h @@ -87,9 +87,12 @@ public: QCursor &operator=(const QCursor &cursor); #ifdef Q_COMPILER_RVALUE_REFS QCursor(QCursor &&other) Q_DECL_NOTHROW : d(other.d) { other.d = Q_NULLPTR; } - inline QCursor &operator=(QCursor &&other) - { qSwap(d, other.d); return *this; } + inline QCursor &operator=(QCursor &&other) Q_DECL_NOTHROW + { swap(other); return *this; } #endif + + void swap(QCursor &other) Q_DECL_NOTHROW { qSwap(d, other.d); } + operator QVariant() const; Qt::CursorShape shape() const; @@ -110,6 +113,7 @@ public: private: QCursorData *d; }; +Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QCursor) /***************************************************************************** QCursor stream functions -- cgit v1.2.3 From 53abb8267bfa4c261a1aa543f1ad50ed0851bcbf Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 5 Jul 2015 22:37:40 +0200 Subject: QtGui: mark some more types as movable/primitive MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These are already held in QVectors. Public API types need to wait until Qt 6, for BC reasons. Even though Q_RELOCATABLE_TYPE deals with most of them, we lack a way to mark a type as primitive, but still isStatic - for QList. Change-Id: I91392b01ae6f94cc847007636e12d4e64c43b2bc Reviewed-by: Jędrzej Nowacki --- src/gui/kernel/qevent.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index 029b76b2bd..5752869cab 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -575,8 +575,10 @@ private: Qt::InputMethodQuery query; QVariant value; }; + friend QTypeInfo; QVector m_values; }; +Q_DECLARE_TYPEINFO(QInputMethodQueryEvent::QueryPair, Q_MOVABLE_TYPE); #endif // QT_NO_INPUTMETHOD -- cgit v1.2.3 From 600529e07a46d8e20f4302dc988125f3fee36ec4 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 17 Oct 2015 17:48:34 +0200 Subject: QtGui: use printf-style qWarning/qDebug where possible (I) The printf-style version of QDebug expands to a lot less code than the std::ostream-style version. Of course, you pay in type safety (but compilers warn about it these days), you cannot stream complex Qt types and streaming QStrings is awkward, but in many cases you actually improve on readability. But the main reason is that something that's not supposed to be executed under normal operation has no business bloating executable code size. This is not an attempt at converting all qWarnings() to printf-style, only the low-hanging fruit. In this first part, replace qWarning() << "..."; with qWarning("..."); In QTransform shared warning strings. Saves 3KiB in text size on optimized GCC 5.3 AMD64 builds. Change-Id: I142a8020eaab043d78465178192f2c8c6d1cc4f9 Reviewed-by: Friedemann Kleint Reviewed-by: Kai Koehne --- src/gui/kernel/qguiapplication.cpp | 4 ++-- src/gui/kernel/qopenglcontext.cpp | 8 ++++---- src/gui/kernel/qstylehints.cpp | 2 +- src/gui/kernel/qwindow.cpp | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index e4d7ad8fcd..057450374d 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -1437,7 +1437,7 @@ void QGuiApplicationPrivate::init() typedef void (*TasInitialize)(void); TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init"); if (Q_UNLIKELY(!initFunction)) { - qCritical() << "Library qttestability resolve failed!"; + qCritical("Library qttestability resolve failed!"); } else { initFunction(); } @@ -1595,7 +1595,7 @@ QFunctionPointer QGuiApplication::platformFunction(const QByteArray &function) { QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration(); if (!pi) { - qWarning() << "QGuiApplication::platformFunction(): Must construct a QGuiApplication before accessing a platform function"; + qWarning("QGuiApplication::platformFunction(): Must construct a QGuiApplication before accessing a platform function"); return Q_NULLPTR; } diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp index 61324d73f3..81c0971ea0 100644 --- a/src/gui/kernel/qopenglcontext.cpp +++ b/src/gui/kernel/qopenglcontext.cpp @@ -1033,19 +1033,19 @@ void QOpenGLContext::swapBuffers(QSurface *surface) return; if (!surface) { - qWarning() << "QOpenGLContext::swapBuffers() called with null argument"; + qWarning("QOpenGLContext::swapBuffers() called with null argument"); return; } if (!surface->supportsOpenGL()) { - qWarning() << "QOpenGLContext::swapBuffers() called with non-opengl surface"; + qWarning("QOpenGLContext::swapBuffers() called with non-opengl surface"); return; } if (surface->surfaceClass() == QSurface::Window && !qt_window_private(static_cast(surface))->receivedExpose) { - qWarning() << "QOpenGLContext::swapBuffers() called with non-exposed window, behavior is undefined"; + qWarning("QOpenGLContext::swapBuffers() called with non-exposed window, behavior is undefined"); } QPlatformSurface *surfaceHandle = surface->surfaceHandle(); @@ -1054,7 +1054,7 @@ void QOpenGLContext::swapBuffers(QSurface *surface) #if !defined(QT_NO_DEBUG) if (!QOpenGLContextPrivate::toggleMakeCurrentTracker(this, false)) - qWarning() << "QOpenGLContext::swapBuffers() called without corresponding makeCurrent()"; + qWarning("QOpenGLContext::swapBuffers() called without corresponding makeCurrent()"); #endif if (surface->format().swapBehavior() == QSurfaceFormat::SingleBuffer) functions()->glFlush(); diff --git a/src/gui/kernel/qstylehints.cpp b/src/gui/kernel/qstylehints.cpp index e184fed275..ecc2886a04 100644 --- a/src/gui/kernel/qstylehints.cpp +++ b/src/gui/kernel/qstylehints.cpp @@ -54,7 +54,7 @@ static inline QVariant themeableHint(QPlatformTheme::ThemeHint th, QPlatformIntegration::StyleHint ih) { if (!QCoreApplication::instance()) { - qWarning() << "Must construct a QGuiApplication before accessing a platform theme hint."; + qWarning("Must construct a QGuiApplication before accessing a platform theme hint."); return QVariant(); } if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) { diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index f43ef43c6c..3f430be579 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -1145,7 +1145,7 @@ qreal QWindow::devicePixelRatio() const void QWindow::setWindowState(Qt::WindowState state) { if (state == Qt::WindowActive) { - qWarning() << "QWindow::setWindowState does not accept Qt::WindowActive"; + qWarning("QWindow::setWindowState does not accept Qt::WindowActive"); return; } @@ -2436,7 +2436,7 @@ QWindow *QWindowPrivate::topLevelWindow() const QWindow *QWindow::fromWinId(WId id) { if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ForeignWindows)) { - qWarning() << "QWindow::fromWinId(): platform plugin does not support foreign windows."; + qWarning("QWindow::fromWinId(): platform plugin does not support foreign windows."); return 0; } -- cgit v1.2.3 From d5fde514106f5479f9c929c8a165aced4a1b2c84 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Tue, 1 Mar 2016 13:17:13 +0100 Subject: QWheelEvent: make NoScrollPhase opt-in The fix for QTBUG-50199 involves adding an undocumented enum value which can be returned from QWheelEvent::phase(). This will be quite unexpected for applications that use it, which work fine with 5.6.0 and then start receiving this new phase value in 5.6.1. So it should not happen by default. Set the env variable QT_ENABLE_MOUSE_WHEEL_TRACKING to enable this functionality. In 5.7 it will be default behavior. But in 5.6 the default behavior is as it was before: if you use a conventional mouse wheel, the phase stays at ScrollUpdate continuously. [ChangeLog][QtCore] QWheelEvent::phase() returns 0 rather than Qt::ScrollUpdate when the wheel event comes from an actual non-emulated mouse wheel and the environment variable QT_ENABLE_MOUSE_WHEEL_TRACKING is set. In Qt 5.6, this is required to enable the fix for QTBUG-50199. Change-Id: Ieb2152ff767df24c42730d201235d1225aaec832 Reviewed-by: Gabriel de Dietrich Reviewed-by: Shawn Rutledge Reviewed-by: Alex Blasche --- src/gui/kernel/qevent.cpp | 9 ++++++++- src/gui/kernel/qguiapplication.cpp | 5 +++++ src/gui/kernel/qguiapplication_p.h | 3 +++ src/gui/kernel/qwindowsysteminterface.cpp | 11 +++++++++++ src/gui/kernel/qwindowsysteminterface_p.h | 3 +-- 5 files changed, 28 insertions(+), 3 deletions(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 8abec2b05e..9281744692 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -729,6 +729,8 @@ QWheelEvent::QWheelEvent(const QPointF &pos, int delta, : QInputEvent(Wheel, modifiers), p(pos), qt4D(delta), qt4O(orient), mouseState(buttons), ph(Qt::NoScrollPhase), src(Qt::MouseEventNotSynthesized) { + if (!QGuiApplicationPrivate::scrollNoPhaseAllowed) + ph = Qt::ScrollUpdate; g = QCursor::pos(); if (orient == Qt::Vertical) angleD = QPoint(0, delta); @@ -764,6 +766,8 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos, int delta : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), qt4D(delta), qt4O(orient), mouseState(buttons), ph(Qt::NoScrollPhase), src(Qt::MouseEventNotSynthesized) { + if (!QGuiApplicationPrivate::scrollNoPhaseAllowed) + ph = Qt::ScrollUpdate; if (orient == Qt::Vertical) angleD = QPoint(0, delta); else @@ -800,7 +804,10 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos, : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), pixelD(pixelDelta), angleD(angleDelta), qt4D(qt4Delta), qt4O(qt4Orientation), mouseState(buttons), ph(Qt::NoScrollPhase), src(Qt::MouseEventNotSynthesized) -{} +{ + if (!QGuiApplicationPrivate::scrollNoPhaseAllowed) + ph = Qt::ScrollUpdate; +} /*! Constructs a wheel event object. diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 3fe6698955..3808bec8a4 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -186,6 +186,9 @@ bool QGuiApplicationPrivate::obey_desktop_settings = true; QInputDeviceManager *QGuiApplicationPrivate::m_inputDeviceManager = 0; +// enable the fix for QTBUG-50199; TODO remove this check in 5.7 +bool QGuiApplicationPrivate::scrollNoPhaseAllowed = false; + static qreal fontSmoothingGamma = 1.7; extern void qRegisterGuiVariant(); @@ -1412,6 +1415,8 @@ void QGuiApplicationPrivate::init() if (layout_direction == Qt::LayoutDirectionAuto || force_reverse) QGuiApplication::setLayoutDirection(qt_detectRTLLanguage() ? Qt::RightToLeft : Qt::LeftToRight); + + scrollNoPhaseAllowed = qEnvironmentVariableIsSet("QT_ENABLE_MOUSE_WHEEL_TRACKING"); } extern void qt_cleanupFontDatabase(); diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index 7c7da9790b..9c8b655c71 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -285,6 +285,9 @@ public: static void setApplicationState(Qt::ApplicationState state, bool forcePropagate = false); + // enable the fix for QTBUG-50199; TODO remove this check in 5.7 + static bool scrollNoPhaseAllowed; + protected: virtual void notifyThemeChanged(); bool tryCloseRemainingWindows(QWindowList processedWindows); diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp index 841e4f8f41..cae976098c 100644 --- a/src/gui/kernel/qwindowsysteminterface.cpp +++ b/src/gui/kernel/qwindowsysteminterface.cpp @@ -311,6 +311,9 @@ void QWindowSystemInterface::handleWheelEvent(QWindow *w, const QPointF & local, void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, const QPointF & local, const QPointF & global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase, Qt::MouseEventSource source) { + if (!QGuiApplicationPrivate::scrollNoPhaseAllowed && phase == Qt::NoScrollPhase) + phase = Qt::ScrollUpdate; + // Qt 4 sends two separate wheel events for horizontal and vertical // deltas. For Qt 5 we want to send the deltas in one event, but at the // same time preserve source and behavior compatibility with Qt 4. @@ -930,5 +933,13 @@ bool QWindowSystemEventHandler::sendEvent(QWindowSystemInterfacePrivate::WindowS return true; } +QWindowSystemInterfacePrivate::WheelEvent::WheelEvent(QWindow *w, ulong time, const QPointF &local, const QPointF &global, QPoint pixelD, + QPoint angleD, int qt4D, Qt::Orientation qt4O, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase, Qt::MouseEventSource src) + : InputEvent(w, time, Wheel, mods), pixelDelta(pixelD), angleDelta(angleD), qt4Delta(qt4D), + qt4Orientation(qt4O), localPos(local), globalPos(global), + phase(!QGuiApplicationPrivate::scrollNoPhaseAllowed && phase == Qt::NoScrollPhase ? Qt::ScrollUpdate : phase), + source(src) +{ +} QT_END_NAMESPACE diff --git a/src/gui/kernel/qwindowsysteminterface_p.h b/src/gui/kernel/qwindowsysteminterface_p.h index c2569f29cd..b3c6d0d96d 100644 --- a/src/gui/kernel/qwindowsysteminterface_p.h +++ b/src/gui/kernel/qwindowsysteminterface_p.h @@ -236,8 +236,7 @@ public: class WheelEvent : public InputEvent { public: WheelEvent(QWindow *w, ulong time, const QPointF & local, const QPointF & global, QPoint pixelD, QPoint angleD, int qt4D, Qt::Orientation qt4O, - Qt::KeyboardModifiers mods, Qt::ScrollPhase phase = Qt::NoScrollPhase, Qt::MouseEventSource src = Qt::MouseEventNotSynthesized) - : InputEvent(w, time, Wheel, mods), pixelDelta(pixelD), angleDelta(angleD), qt4Delta(qt4D), qt4Orientation(qt4O), localPos(local), globalPos(global), phase(phase), source(src) { } + Qt::KeyboardModifiers mods, Qt::ScrollPhase phase = Qt::NoScrollPhase, Qt::MouseEventSource src = Qt::MouseEventNotSynthesized); QPoint pixelDelta; QPoint angleDelta; int qt4Delta; -- cgit v1.2.3 From bcd88d8e9984bff664740aae3cff708a069dbbdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Tue, 7 Jan 2014 12:54:03 +0100 Subject: Add QWheelEvent::inverted() Some consumers of wheel events need to know if the scrolling direction is inverted in order to provide consistent behavior. For example, the scrolling direction of a horizontal slider should not change when the user toggles the "natural scrolling" setting on OS X. In this case the inverted bit will change state and the slider can compensate. This change adds a bit to QWheelEvent and sets it on OS X. Task-number: QTBUG-35972 Change-Id: I221435dea45d436d570b113bd0e24ee6f6832211 Reviewed-by: Shawn Rutledge --- src/gui/kernel/qevent.cpp | 82 ++++++++++++++++++++++++++++--- src/gui/kernel/qevent.h | 7 ++- src/gui/kernel/qguiapplication.cpp | 3 +- src/gui/kernel/qwindowsysteminterface.cpp | 12 +++-- src/gui/kernel/qwindowsysteminterface.h | 3 +- src/gui/kernel/qwindowsysteminterface_p.h | 5 +- 6 files changed, 94 insertions(+), 18 deletions(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 98499c11ac..78a4dc4f35 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -701,6 +701,31 @@ QHoverEvent::~QHoverEvent() \sa Qt::MouseEventSource */ +/*! + \fn bool QWheelEvent::inverted() const + \since 5.7 + + Returns whether the delta values delivered with the event are inverted. + + Normally, a vertical wheel will produce a QWheelEvent with positive delta + values if the top of the wheel is rotating away from the hand operating it. + Similarly, a horizontal wheel movement will produce a QWheelEvent with + positive delta values if the top of the wheel is moved to the left. + + However, on some platforms this is configurable, so that the same + operations described above will produce negative delta values (but with the + same magnitude). With the inverted property a wheel event consumer can + choose to always follow the direction of the wheel, regardless of the + system settings, but only for specific widgets. (One such use case could be + that the user is rotating the wheel in the same direction as a visual + Tumbler rotates. Another usecase is to make a slider handle follow the + direction of movement of fingers on a touchpad regardless of system + configuration.) + + \note Many platforms provide no such information. On such platforms + \l inverted always returns false. +*/ + /*! \fn Qt::Orientation QWheelEvent::orientation() const \obsolete @@ -734,7 +759,7 @@ QWheelEvent::QWheelEvent(const QPointF &pos, int delta, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::Orientation orient) : QInputEvent(Wheel, modifiers), p(pos), qt4D(delta), qt4O(orient), mouseState(buttons), - ph(Qt::NoScrollPhase), src(Qt::MouseEventNotSynthesized) + ph(Qt::NoScrollPhase), src(Qt::MouseEventNotSynthesized), invertedScrolling(false) { g = QCursor::pos(); if (orient == Qt::Vertical) @@ -769,7 +794,7 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos, int delta Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::Orientation orient) : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), qt4D(delta), qt4O(orient), mouseState(buttons), - ph(Qt::NoScrollPhase), src(Qt::MouseEventNotSynthesized) + ph(Qt::NoScrollPhase), src(Qt::MouseEventNotSynthesized), invertedScrolling(false) { if (orient == Qt::Vertical) angleD = QPoint(0, delta); @@ -806,7 +831,7 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers) : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), pixelD(pixelDelta), angleD(angleDelta), qt4D(qt4Delta), qt4O(qt4Orientation), mouseState(buttons), ph(Qt::NoScrollPhase), - src(Qt::MouseEventNotSynthesized) + src(Qt::MouseEventNotSynthesized), invertedScrolling(false) {} /*! @@ -837,15 +862,14 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase) : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), pixelD(pixelDelta), angleD(angleDelta), qt4D(qt4Delta), qt4O(qt4Orientation), mouseState(buttons), ph(phase), - src(Qt::MouseEventNotSynthesized) + src(Qt::MouseEventNotSynthesized), invertedScrolling(false) {} /*! Constructs a wheel event object. - The \a pos provides the location of the mouse cursor - within the window. The position in global coordinates is specified - by \a globalPos. + The \a pos provides the location of the mouse cursor within the window. The + position in global coordinates is specified by \a globalPos. \a pixelDelta contains the scrolling distance in pixels on screen, while \a angleDelta contains the wheel rotation distance. \a pixelDelta is @@ -873,7 +897,49 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos, QPoint pixelDelta, QPoint angleDelta, int qt4Delta, Qt::Orientation qt4Orientation, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase, Qt::MouseEventSource source) : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), pixelD(pixelDelta), - angleD(angleDelta), qt4D(qt4Delta), qt4O(qt4Orientation), mouseState(buttons), ph(phase), src(source) + angleD(angleDelta), qt4D(qt4Delta), qt4O(qt4Orientation), mouseState(buttons), ph(phase), src(source), + invertedScrolling(false) +{} + +/*! + Constructs a wheel event object. + + The \a pos provides the location of the mouse cursor + within the window. The position in global coordinates is specified + by \a globalPos. + + \a pixelDelta contains the scrolling distance in pixels on screen, while + \a angleDelta contains the wheel rotation distance. \a pixelDelta is + optional and can be null. + + The mouse and keyboard states at the time of the event are specified by + \a buttons and \a modifiers. + + For backwards compatibility, the event can also hold monodirectional wheel + event data: \a qt4Delta specifies the rotation, and \a qt4Orientation the + direction. + + The scrolling phase of the event is specified by \a phase. + + If the wheel event comes from a physical mouse wheel, \a source is set to + Qt::MouseEventNotSynthesized. If it comes from a gesture detected by the + operating system, or from a non-mouse hardware device, such that \a + pixelDelta is directly related to finger movement, \a source is set to + Qt::MouseEventSynthesizedBySystem. If it comes from Qt, source would be set + to Qt::MouseEventSynthesizedByQt. + + If the system is configured to invert the delta values delivered with the + event (such as natural scrolling of the touchpad on OS X), \a inverted + should be \c true. Otherwise, \a inverted is \c false + + \sa posF(), globalPosF(), angleDelta(), pixelDelta(), phase() +*/ +QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos, + QPoint pixelDelta, QPoint angleDelta, int qt4Delta, Qt::Orientation qt4Orientation, + Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase, Qt::MouseEventSource source, bool inverted) + : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), pixelD(pixelDelta), + angleD(angleDelta), qt4D(qt4Delta), qt4O(qt4Orientation), mouseState(buttons), ph(phase), src(source), + invertedScrolling(inverted) {} #endif // QT_NO_WHEELEVENT diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index 5752869cab..0a207667ad 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -187,6 +187,9 @@ public: QWheelEvent(const QPointF &pos, const QPointF &globalPos, QPoint pixelDelta, QPoint angleDelta, int qt4Delta, Qt::Orientation qt4Orientation, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase, Qt::MouseEventSource source); + QWheelEvent(const QPointF &pos, const QPointF &globalPos, QPoint pixelDelta, QPoint angleDelta, + int qt4Delta, Qt::Orientation qt4Orientation, Qt::MouseButtons buttons, + Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase, Qt::MouseEventSource source, bool inverted); ~QWheelEvent(); @@ -210,6 +213,7 @@ public: inline Qt::MouseButtons buttons() const { return mouseState; } inline Qt::ScrollPhase phase() const { return Qt::ScrollPhase(ph); } + inline bool inverted() const { return invertedScrolling; } Qt::MouseEventSource source() const { return Qt::MouseEventSource(src); } @@ -223,7 +227,8 @@ protected: Qt::MouseButtons mouseState; uint ph : 2; uint src: 2; - int reserved : 28; + bool invertedScrolling : 1; + int reserved : 27; friend class QApplication; }; diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 057450374d..3f3ed87944 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -1974,7 +1974,8 @@ void QGuiApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::Wh return; } - QWheelEvent ev(localPoint, globalPoint, e->pixelDelta, e->angleDelta, e->qt4Delta, e->qt4Orientation, buttons, e->modifiers, e->phase, e->source); + QWheelEvent ev(localPoint, globalPoint, e->pixelDelta, e->angleDelta, e->qt4Delta, e->qt4Orientation, + buttons, e->modifiers, e->phase, e->source, e->inverted); ev.setTimestamp(e->timestamp); QGuiApplication::sendSpontaneousEvent(window, &ev); #endif /* ifndef QT_NO_WHEELEVENT */ diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp index 39bc161a7c..7547e58346 100644 --- a/src/gui/kernel/qwindowsysteminterface.cpp +++ b/src/gui/kernel/qwindowsysteminterface.cpp @@ -315,7 +315,8 @@ void QWindowSystemInterface::handleWheelEvent(QWindow *w, const QPointF & local, handleWheelEvent(w, time, local, global, pixelDelta, angleDelta, mods, phase, source); } -void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, const QPointF & local, const QPointF & global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase, Qt::MouseEventSource source) +void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, const QPointF & local, const QPointF & global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase, + Qt::MouseEventSource source, bool invertedScrolling) { // Qt 4 sends two separate wheel events for horizontal and vertical // deltas. For Qt 5 we want to send the deltas in one event, but at the @@ -333,14 +334,15 @@ void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, con // Simple case: vertical deltas only: if (angleDelta.y() != 0 && angleDelta.x() == 0) { - e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, QHighDpi::fromNativeLocalPosition(local, tlw), QHighDpi::fromNativePixels(global, tlw), pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, mods, phase, source); + e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, QHighDpi::fromNativeLocalPosition(local, tlw), QHighDpi::fromNativePixels(global, tlw), pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, + mods, phase, source, invertedScrolling); QWindowSystemInterfacePrivate::handleWindowSystemEvent(e); return; } // Simple case: horizontal deltas only: if (angleDelta.y() == 0 && angleDelta.x() != 0) { - e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, QHighDpi::fromNativeLocalPosition(local, tlw), QHighDpi::fromNativePixels(global, tlw), pixelDelta, angleDelta, angleDelta.x(), Qt::Horizontal, mods, phase, source); + e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, QHighDpi::fromNativeLocalPosition(local, tlw), QHighDpi::fromNativePixels(global, tlw), pixelDelta, angleDelta, angleDelta.x(), Qt::Horizontal, mods, phase, source, invertedScrolling); QWindowSystemInterfacePrivate::handleWindowSystemEvent(e); return; } @@ -348,12 +350,12 @@ void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, con // Both horizontal and vertical deltas: Send two wheel events. // The first event contains the Qt 5 pixel and angle delta as points, // and in addition the Qt 4 compatibility vertical angle delta. - e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, QHighDpi::fromNativeLocalPosition(local, tlw), QHighDpi::fromNativePixels(global, tlw), pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, mods, phase, source); + e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, QHighDpi::fromNativeLocalPosition(local, tlw), QHighDpi::fromNativePixels(global, tlw), pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, mods, phase, source, invertedScrolling); QWindowSystemInterfacePrivate::handleWindowSystemEvent(e); // The second event contains null pixel and angle points and the // Qt 4 compatibility horizontal angle delta. - e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, QHighDpi::fromNativeLocalPosition(local, tlw), QHighDpi::fromNativePixels(global, tlw), QPoint(), QPoint(), angleDelta.x(), Qt::Horizontal, mods, phase, source); + e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, QHighDpi::fromNativeLocalPosition(local, tlw), QHighDpi::fromNativePixels(global, tlw), QPoint(), QPoint(), angleDelta.x(), Qt::Horizontal, mods, phase, source, invertedScrolling); QWindowSystemInterfacePrivate::handleWindowSystemEvent(e); } diff --git a/src/gui/kernel/qwindowsysteminterface.h b/src/gui/kernel/qwindowsysteminterface.h index 66a4afb085..eff3986788 100644 --- a/src/gui/kernel/qwindowsysteminterface.h +++ b/src/gui/kernel/qwindowsysteminterface.h @@ -109,7 +109,8 @@ public: QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods = Qt::NoModifier, Qt::ScrollPhase phase = Qt::NoScrollPhase, - Qt::MouseEventSource source = Qt::MouseEventNotSynthesized); + Qt::MouseEventSource source = Qt::MouseEventNotSynthesized, + bool inverted = false); // Wheel event compatibility functions. Will be removed: do not use. static void handleWheelEvent(QWindow *w, const QPointF & local, const QPointF & global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods = Qt::NoModifier); diff --git a/src/gui/kernel/qwindowsysteminterface_p.h b/src/gui/kernel/qwindowsysteminterface_p.h index 523aa984a9..4bb0e83a97 100644 --- a/src/gui/kernel/qwindowsysteminterface_p.h +++ b/src/gui/kernel/qwindowsysteminterface_p.h @@ -242,8 +242,8 @@ public: class WheelEvent : public InputEvent { public: WheelEvent(QWindow *w, ulong time, const QPointF & local, const QPointF & global, QPoint pixelD, QPoint angleD, int qt4D, Qt::Orientation qt4O, - Qt::KeyboardModifiers mods, Qt::ScrollPhase phase = Qt::NoScrollPhase, Qt::MouseEventSource src = Qt::MouseEventNotSynthesized) - : InputEvent(w, time, Wheel, mods), pixelDelta(pixelD), angleDelta(angleD), qt4Delta(qt4D), qt4Orientation(qt4O), localPos(local), globalPos(global), phase(phase), source(src) { } + Qt::KeyboardModifiers mods, Qt::ScrollPhase phase = Qt::NoScrollPhase, Qt::MouseEventSource src = Qt::MouseEventNotSynthesized, bool inverted = false) + : InputEvent(w, time, Wheel, mods), pixelDelta(pixelD), angleDelta(angleD), qt4Delta(qt4D), qt4Orientation(qt4O), localPos(local), globalPos(global), phase(phase), source(src), inverted(inverted) { } QPoint pixelDelta; QPoint angleDelta; int qt4Delta; @@ -252,6 +252,7 @@ public: QPointF globalPos; Qt::ScrollPhase phase; Qt::MouseEventSource source; + bool inverted; }; class KeyEvent : public InputEvent { -- cgit v1.2.3 From 1b441c3941efc56f9b0ead35a4501056a74a77e1 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 7 Mar 2016 20:26:14 +0100 Subject: Q*Application: fix UB caused by accessing QGuiApplication from QCoreApplication ctor As reported by ubsan: src/gui/kernel/qplatformintegration.cpp:463:10: runtime error: downcast of address 0x7ffdc2942490 which does not point to an object of type 'QGuiApplication' 0x7ffdc2942490: note: object is of type 'QCoreApplication' src/gui/kernel/qplatformintegration.cpp:466:14: runtime error: downcast of address 0x7ffdc2942490 which does not point to an object of type 'QGuiApplication' 0x7ffdc2942490: note: object is of type 'QCoreApplication' src/gui/kernel/qplatformintegration.cpp:466:43: runtime error: member call on address 0x7ffdc2942490 which does not point to an object of type 'QGuiApplication' 0x7ffdc2942490: note: object is of type 'QCoreApplication' to name just a few which are reported when running gui and widget auto-tests; there're definitely more where these came from. This is caused by QCoreApplication::init() being called from the QCoreApplication ctor, calling virtual functions on Q*AppPrivate, which happen to attempt, in this case, to emit QGuiApp signals. At that point in time, the QGuiApplication ctor has not entered the constructor body, ergo the object is still a QCoreApplication, and calling the signal, as a member function on the derived class, invokes UB. Fix by cleaning up the wild mix of initialization functions used in this hierarchy. The cleanup restores the 1. Q*ApplicationPrivate::Q*ApplicationPrivate() 2. Q*ApplicationPrivate::init(), calling each base class' init() as the first thing two-stage construction pattern commonly used elsewhere in Qt to make sure that the public class' object is fully constructed by the time each level's Private::init() is called. Change-Id: I290402b3232315d7ed687c97e740bfbdbd3ecd1a Reviewed-by: Lars Knoll --- src/gui/kernel/qguiapplication.cpp | 4 +++- src/gui/kernel/qguiapplication_p.h | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 3808bec8a4..385264d70a 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -577,7 +577,7 @@ QGuiApplication::QGuiApplication(int &argc, char **argv, int flags) QGuiApplication::QGuiApplication(QGuiApplicationPrivate &p) : QCoreApplication(p) { - d_func()->init(); } +} /*! Destructs the application. @@ -1260,6 +1260,8 @@ void QGuiApplicationPrivate::eventDispatcherReady() void QGuiApplicationPrivate::init() { + QCoreApplicationPrivate::init(); + QCoreApplicationPrivate::is_app_running = false; // Starting up. bool loadTestability = false; diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index 9c8b655c71..9e157aad51 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -75,6 +75,8 @@ public: QGuiApplicationPrivate(int &argc, char **argv, int flags); ~QGuiApplicationPrivate(); + void init(); + void createPlatformIntegration(); void createEventDispatcher() Q_DECL_OVERRIDE; void eventDispatcherReady() Q_DECL_OVERRIDE; @@ -298,8 +300,6 @@ protected: private: friend class QDragManager; - void init(); - static QGuiApplicationPrivate *self; static QTouchDevice *m_fakeTouchDevice; static int m_fakeMouseSourcePointId; -- cgit v1.2.3 From a3def2869da8ad9c17d44005c0d1fd70a903f855 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Thu, 25 Feb 2016 12:41:35 +0300 Subject: QtGui: de-duplicate calls and cache results Change-Id: Iaf232c31d6780b49dc6a3d0faafb9717f3c36e65 Reviewed-by: Marc Mutz Reviewed-by: Lars Knoll Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/gui/kernel/qhighdpiscaling_p.h | 6 ++++-- src/gui/kernel/qopenglwindow.cpp | 5 +++-- src/gui/kernel/qplatformwindow.cpp | 5 +++-- src/gui/kernel/qrasterwindow.cpp | 5 +++-- src/gui/kernel/qwindow.cpp | 4 ++-- 5 files changed, 15 insertions(+), 10 deletions(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qhighdpiscaling_p.h b/src/gui/kernel/qhighdpiscaling_p.h index 364dfaeaee..eb3a9d5545 100644 --- a/src/gui/kernel/qhighdpiscaling_p.h +++ b/src/gui/kernel/qhighdpiscaling_p.h @@ -474,8 +474,9 @@ QVector fromNativePixels(const QVector &pixelValues, const QWindow *window QVector pointValues; pointValues.reserve(pixelValues.size()); + const auto factor = QHighDpiScaling::factor(window); for (const T &pixelValue : pixelValues) - pointValues.append(pixelValue / QHighDpiScaling::factor(window)); + pointValues.append(pixelValue / factor); return pointValues; } @@ -488,8 +489,9 @@ QVector toNativePixels(const QVector &pointValues, const QWindow *window) QVector pixelValues; pixelValues.reserve(pointValues.size()); + const auto factor = QHighDpiScaling::factor(window); for (const T &pointValue : pointValues) - pixelValues.append(pointValue * QHighDpiScaling::factor(window)); + pixelValues.append(pointValue * factor); return pixelValues; } diff --git a/src/gui/kernel/qopenglwindow.cpp b/src/gui/kernel/qopenglwindow.cpp index 37db608430..8ab5c08442 100644 --- a/src/gui/kernel/qopenglwindow.cpp +++ b/src/gui/kernel/qopenglwindow.cpp @@ -252,9 +252,10 @@ void QOpenGLWindowPrivate::beginPaint(const QRegion ®ion) if (!fbo || fbo->size() != deviceSize) { QOpenGLFramebufferObjectFormat fboFormat; fboFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); - if (q->requestedFormat().samples() > 0) { + const int samples = q->requestedFormat().samples(); + if (samples > 0) { if (updateBehavior != QOpenGLWindow::PartialUpdateBlend) - fboFormat.setSamples(q->requestedFormat().samples()); + fboFormat.setSamples(samples); else qWarning("QOpenGLWindow: PartialUpdateBlend does not support multisampling"); } diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp index 347d02d616..e45a1d61ba 100644 --- a/src/gui/kernel/qplatformwindow.cpp +++ b/src/gui/kernel/qplatformwindow.cpp @@ -499,9 +499,10 @@ QPlatformScreen *QPlatformWindow::screenForGeometry(const QRect &newGeometry) co if (!parent() && currentScreen && !currentScreen->geometry().contains(center)) { const auto screens = currentScreen->virtualSiblings(); for (QPlatformScreen *screen : screens) { - if (screen->geometry().contains(center)) + const QRect screenGeometry = screen->geometry(); + if (screenGeometry.contains(center)) return screen; - if (screen->geometry().intersects(newGeometry)) + if (screenGeometry.intersects(newGeometry)) fallback = screen; } } diff --git a/src/gui/kernel/qrasterwindow.cpp b/src/gui/kernel/qrasterwindow.cpp index 947f2bb6a8..d8d448249e 100644 --- a/src/gui/kernel/qrasterwindow.cpp +++ b/src/gui/kernel/qrasterwindow.cpp @@ -73,8 +73,9 @@ public: void beginPaint(const QRegion ®ion) Q_DECL_OVERRIDE { Q_Q(QRasterWindow); - if (backingstore->size() != q->size()) { - backingstore->resize(q->size()); + const QSize size = q->size(); + if (backingstore->size() != size) { + backingstore->resize(size); markWindowAsDirty(); } backingstore->beginPaint(region); diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 3f430be579..107ea73a56 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -1469,9 +1469,9 @@ void QWindow::setGeometry(const QRect &rect) { Q_D(QWindow); d->positionAutomatic = false; - if (rect == geometry()) + const QRect oldRect = geometry(); + if (rect == oldRect) return; - QRect oldRect = geometry(); d->positionPolicy = QWindowPrivate::WindowFrameExclusive; if (d->platformWindow) { -- cgit v1.2.3 From abe3217bac18fe8a99cbb2f494a5e4cf6c6d70ce Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 29 Jan 2016 14:03:41 +0100 Subject: Reimplement QShapedPixmapWindow using QRasterWindow. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current implementation makes the window too big when a QPixmap with a DPR != 1 is set. Circumvent the problem by using a QRasterWindow. Task-number: QTBUG-46068 Task-number: QTBUG-50938 Change-Id: I0fca91f571937250c740f1400bd60286330fb595 Reviewed-by: Błażej Szczygieł Reviewed-by: Alexander Volkov Reviewed-by: Shawn Rutledge --- src/gui/kernel/qshapedpixmapdndwindow.cpp | 72 +++++++++++++------------------ src/gui/kernel/qshapedpixmapdndwindow_p.h | 10 ++--- 2 files changed, 33 insertions(+), 49 deletions(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qshapedpixmapdndwindow.cpp b/src/gui/kernel/qshapedpixmapdndwindow.cpp index d77b6dc262..850987ac1d 100644 --- a/src/gui/kernel/qshapedpixmapdndwindow.cpp +++ b/src/gui/kernel/qshapedpixmapdndwindow.cpp @@ -42,52 +42,31 @@ QT_BEGIN_NAMESPACE QShapedPixmapWindow::QShapedPixmapWindow(QScreen *screen) - : QWindow(screen), - m_backingStore(0), - m_useCompositing(true) + : m_useCompositing(true) { + setScreen(screen); QSurfaceFormat format; format.setAlphaBufferSize(8); setFormat(format); - setSurfaceType(RasterSurface); - setFlags(Qt::ToolTip | Qt::FramelessWindowHint | - Qt::X11BypassWindowManagerHint | Qt::WindowTransparentForInput | Qt::WindowDoesNotAcceptFocus); - create(); - m_backingStore = new QBackingStore(this); + setFlags(Qt::ToolTip | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint + | Qt::WindowTransparentForInput | Qt::WindowDoesNotAcceptFocus); } QShapedPixmapWindow::~QShapedPixmapWindow() { - delete m_backingStore; - m_backingStore = 0; -} - -void QShapedPixmapWindow::render() -{ - QRect rect(QPoint(), geometry().size()); - - m_backingStore->beginPaint(rect); - - QPaintDevice *device = m_backingStore->paintDevice(); - - { - QPainter p(device); - if (m_useCompositing) - p.setCompositionMode(QPainter::CompositionMode_Source); - else - p.fillRect(rect, QGuiApplication::palette().base()); - p.drawPixmap(0, 0, m_pixmap); - } - - m_backingStore->endPaint(); - m_backingStore->flush(rect); } void QShapedPixmapWindow::setPixmap(const QPixmap &pixmap) { m_pixmap = pixmap; - if (!m_useCompositing) - setMask(m_pixmap.mask()); + if (!m_useCompositing) { + const QBitmap mask = m_pixmap.mask(); + if (!mask.isNull()) { + if (!handle()) + create(); + setMask(mask); + } + } } void QShapedPixmapWindow::setHotspot(const QPoint &hotspot) @@ -95,19 +74,28 @@ void QShapedPixmapWindow::setHotspot(const QPoint &hotspot) m_hotSpot = hotspot; } -void QShapedPixmapWindow::updateGeometry(const QPoint &pos) +void QShapedPixmapWindow::paintEvent(QPaintEvent *) { - if (m_pixmap.isNull()) - m_backingStore->resize(QSize(1,1)); - else if (m_backingStore->size() != m_pixmap.size()) - m_backingStore->resize(m_pixmap.size()); - - setGeometry(QRect(pos - m_hotSpot, m_backingStore->size())); + if (!m_pixmap.isNull()) { + const QRect rect(QPoint(0, 0), size()); + QPainter painter(this); + if (m_useCompositing) + painter.setCompositionMode(QPainter::CompositionMode_Source); + else + painter.fillRect(rect, QGuiApplication::palette().base()); + painter.drawPixmap(rect, m_pixmap); + } } -void QShapedPixmapWindow::exposeEvent(QExposeEvent *) +void QShapedPixmapWindow::updateGeometry(const QPoint &pos) { - render(); + QSize size(1, 1); + if (!m_pixmap.isNull()) { + size = qFuzzyCompare(m_pixmap.devicePixelRatio(), 1.0) + ? m_pixmap.size() + : (QSizeF(m_pixmap.size()) / m_pixmap.devicePixelRatio()).toSize(); + } + setGeometry(QRect(pos - m_hotSpot, size)); } QT_END_NAMESPACE diff --git a/src/gui/kernel/qshapedpixmapdndwindow_p.h b/src/gui/kernel/qshapedpixmapdndwindow_p.h index 3d7974fa82..f2d678c1b4 100644 --- a/src/gui/kernel/qshapedpixmapdndwindow_p.h +++ b/src/gui/kernel/qshapedpixmapdndwindow_p.h @@ -45,21 +45,18 @@ // We mean it. // -#include +#include #include -#include QT_BEGIN_NAMESPACE -class QShapedPixmapWindow : public QWindow +class QShapedPixmapWindow : public QRasterWindow { Q_OBJECT public: explicit QShapedPixmapWindow(QScreen *screen = 0); ~QShapedPixmapWindow(); - void render(); - void setUseCompositing(bool on) { m_useCompositing = on; } void setPixmap(const QPixmap &pixmap); void setHotspot(const QPoint &hotspot); @@ -67,10 +64,9 @@ public: void updateGeometry(const QPoint &pos); protected: - void exposeEvent(QExposeEvent *) Q_DECL_OVERRIDE; + void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; private: - QBackingStore *m_backingStore; QPixmap m_pixmap; QPoint m_hotSpot; bool m_useCompositing; -- cgit v1.2.3 From d1f803af60ce4aec9669aaee775647ff1101cc40 Mon Sep 17 00:00:00 2001 From: Nikita Krupenko Date: Sat, 5 Mar 2016 22:53:47 +0200 Subject: QPlatformTheme: added EditorFont Which is needed by Qt Labs Controls. Task-number: QTBUG-51203 Change-Id: If5f39d59c5c88de37c9b034b784c38b976759439 Reviewed-by: J-P Nurmi --- src/gui/kernel/qplatformtheme.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qplatformtheme.h b/src/gui/kernel/qplatformtheme.h index 77e063f889..c4c7482995 100644 --- a/src/gui/kernel/qplatformtheme.h +++ b/src/gui/kernel/qplatformtheme.h @@ -172,6 +172,7 @@ public: FixedFont, GroupBoxTitleFont, TabButtonFont, + EditorFont, NFonts }; -- cgit v1.2.3 From 96740193e1e0f0608f67660811a44b696924ad4c Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Tue, 8 Mar 2016 14:37:55 -0800 Subject: QWheelEvent: Make NoScrollPhase public This reverts d5fde514106f5479f9c929c8a165aced4a1b2c84 and makes that enum value the default for QWheelEvent::phase() with non phase-aware mice. [ChangeLog][QtGui] QWheelEvent::phase() returns NoScrollPhase with non phase-aware mice. This is most mice and input devices except, for now, Apple's trackpads and Magic Mouse. Change-Id: I929fb39889cf116e89dcd134c1b1ec6587b8f05e Reviewed-by: Shawn Rutledge --- src/gui/kernel/qevent.cpp | 9 +-------- src/gui/kernel/qguiapplication.cpp | 5 ----- src/gui/kernel/qguiapplication_p.h | 3 --- src/gui/kernel/qwindowsysteminterface.cpp | 7 +------ 4 files changed, 2 insertions(+), 22 deletions(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index d8b1367833..78a4dc4f35 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -761,8 +761,6 @@ QWheelEvent::QWheelEvent(const QPointF &pos, int delta, : QInputEvent(Wheel, modifiers), p(pos), qt4D(delta), qt4O(orient), mouseState(buttons), ph(Qt::NoScrollPhase), src(Qt::MouseEventNotSynthesized), invertedScrolling(false) { - if (!QGuiApplicationPrivate::scrollNoPhaseAllowed) - ph = Qt::ScrollUpdate; g = QCursor::pos(); if (orient == Qt::Vertical) angleD = QPoint(0, delta); @@ -798,8 +796,6 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos, int delta : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), qt4D(delta), qt4O(orient), mouseState(buttons), ph(Qt::NoScrollPhase), src(Qt::MouseEventNotSynthesized), invertedScrolling(false) { - if (!QGuiApplicationPrivate::scrollNoPhaseAllowed) - ph = Qt::ScrollUpdate; if (orient == Qt::Vertical) angleD = QPoint(0, delta); else @@ -836,10 +832,7 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos, : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), pixelD(pixelDelta), angleD(angleDelta), qt4D(qt4Delta), qt4O(qt4Orientation), mouseState(buttons), ph(Qt::NoScrollPhase), src(Qt::MouseEventNotSynthesized), invertedScrolling(false) -{ - if (!QGuiApplicationPrivate::scrollNoPhaseAllowed) - ph = Qt::ScrollUpdate; -} +{} /*! Constructs a wheel event object. diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index a79a602088..31b30c6e5a 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -199,9 +199,6 @@ bool QGuiApplicationPrivate::obey_desktop_settings = true; QInputDeviceManager *QGuiApplicationPrivate::m_inputDeviceManager = 0; -// enable the fix for QTBUG-50199; TODO remove this check in 5.7 -bool QGuiApplicationPrivate::scrollNoPhaseAllowed = false; - static qreal fontSmoothingGamma = 1.7; extern void qRegisterGuiVariant(); @@ -1458,8 +1455,6 @@ void QGuiApplicationPrivate::init() if (layout_direction == Qt::LayoutDirectionAuto || force_reverse) QGuiApplication::setLayoutDirection(qt_detectRTLLanguage() ? Qt::RightToLeft : Qt::LeftToRight); - - scrollNoPhaseAllowed = qEnvironmentVariableIsSet("QT_ENABLE_MOUSE_WHEEL_TRACKING"); } extern void qt_cleanupFontDatabase(); diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index 830d716ed8..a028441a2f 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -302,9 +302,6 @@ public: static void setApplicationState(Qt::ApplicationState state, bool forcePropagate = false); - // enable the fix for QTBUG-50199; TODO remove this check in 5.7 - static bool scrollNoPhaseAllowed; - protected: virtual void notifyThemeChanged(); bool tryCloseRemainingWindows(QWindowList processedWindows); diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp index 01e27d72d4..5b91f1bc7e 100644 --- a/src/gui/kernel/qwindowsysteminterface.cpp +++ b/src/gui/kernel/qwindowsysteminterface.cpp @@ -318,9 +318,6 @@ void QWindowSystemInterface::handleWheelEvent(QWindow *w, const QPointF & local, void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, const QPointF & local, const QPointF & global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase, Qt::MouseEventSource source, bool invertedScrolling) { - if (!QGuiApplicationPrivate::scrollNoPhaseAllowed && phase == Qt::NoScrollPhase) - phase = Qt::ScrollUpdate; - // Qt 4 sends two separate wheel events for horizontal and vertical // deltas. For Qt 5 we want to send the deltas in one event, but at the // same time preserve source and behavior compatibility with Qt 4. @@ -944,9 +941,7 @@ bool QWindowSystemEventHandler::sendEvent(QWindowSystemInterfacePrivate::WindowS QWindowSystemInterfacePrivate::WheelEvent::WheelEvent(QWindow *w, ulong time, const QPointF &local, const QPointF &global, QPoint pixelD, QPoint angleD, int qt4D, Qt::Orientation qt4O, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase, Qt::MouseEventSource src, bool inverted) : InputEvent(w, time, Wheel, mods), pixelDelta(pixelD), angleDelta(angleD), qt4Delta(qt4D), - qt4Orientation(qt4O), localPos(local), globalPos(global), - phase(!QGuiApplicationPrivate::scrollNoPhaseAllowed && phase == Qt::NoScrollPhase ? Qt::ScrollUpdate : phase), - source(src), inverted(inverted) + qt4Orientation(qt4O), localPos(local), globalPos(global), phase(phase), source(src), inverted(inverted) { } -- cgit v1.2.3 From e4d79e1fdeb6b26ba0b12b578daacf7cd672b960 Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Sat, 27 Feb 2016 20:55:41 +0300 Subject: Add createMenu() method to QPlatformMenuBar The D-Bus platform menus are only useful inside menu bars and system tray icons, and should not be created for other cases (like the context menus). This adds a new virtual createMenu() method to QPlatformMenuBar class, analogous to the already existing QPlatformSystemTrayIcon::createMenu() method, and adds support for it to QMenuBar. The D-Bus platform menus are now created from QDBusMenuBar class. As an additional benefit, we no longer have to check whether the AppMenu Registrar service is present for every created menu, and check it only once (this should speed things a bit up). Change-Id: Ic7d94e58a501ab9d2954aeb342ebd46ef8e62d49 Reviewed-by: J-P Nurmi Reviewed-by: Friedemann Kleint Reviewed-by: Shawn Rutledge --- src/gui/kernel/qplatformmenu.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qplatformmenu.h b/src/gui/kernel/qplatformmenu.h index 22848fcff6..bd4f4d9beb 100644 --- a/src/gui/kernel/qplatformmenu.h +++ b/src/gui/kernel/qplatformmenu.h @@ -148,6 +148,7 @@ public: virtual void handleReparent(QWindow *newParentWindow) = 0; virtual QPlatformMenu *menuForTag(quintptr tag) const = 0; + virtual QPlatformMenu *createMenu() const { return nullptr; } }; QT_END_NAMESPACE -- cgit v1.2.3