From f66c22ff5b7b9ec81d8c1621850649be8a1ac4d4 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 5 Jul 2019 09:55:46 +0200 Subject: QWidget::restoreGeometry(): Remove code related to restoredFrameGeometry restoredFrameGeometry is only used for a sanity check in format version 0, add a comment and remove code. Task-number: QTBUG-76900 Change-Id: I797b07d069f8568cb39541bcbe9009935a4a79f7 Reviewed-by: Gatis Paeglis --- src/widgets/kernel/qwidget.cpp | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 50745175b4..2f96b95522 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -7505,7 +7505,7 @@ bool QWidget::restoreGeometry(const QByteArray &geometry) quint8 fullScreen; qint32 restoredScreenWidth = 0; - stream >> restoredFrameGeometry + stream >> restoredFrameGeometry // Only used for sanity checks in version 0 >> restoredNormalGeometry >> restoredScreenNumber >> maximized @@ -7535,8 +7535,6 @@ bool QWidget::restoreGeometry(const QByteArray &geometry) } const int frameHeight = 20; - if (!restoredFrameGeometry.isValid()) - restoredFrameGeometry = QRect(QPoint(0,0), sizeHint()); if (!restoredNormalGeometry.isValid()) restoredNormalGeometry = QRect(QPoint(0, frameHeight), sizeHint()); @@ -7556,17 +7554,9 @@ bool QWidget::restoreGeometry(const QByteArray &geometry) // - (Mac only) The window is higher than the available geometry. It must // be possible to bring the size grip on screen by moving the window. #if 0 // Used to be included in Qt4 for Q_WS_MAC - restoredFrameGeometry.setHeight(qMin(restoredFrameGeometry.height(), availableGeometry.height())); restoredNormalGeometry.setHeight(qMin(restoredNormalGeometry.height(), availableGeometry.height() - frameHeight)); #endif - if (!restoredFrameGeometry.intersects(availableGeometry)) { - restoredFrameGeometry.moveBottom(qMin(restoredFrameGeometry.bottom(), availableGeometry.bottom())); - restoredFrameGeometry.moveLeft(qMax(restoredFrameGeometry.left(), availableGeometry.left())); - restoredFrameGeometry.moveRight(qMin(restoredFrameGeometry.right(), availableGeometry.right())); - } - restoredFrameGeometry.moveTop(qMax(restoredFrameGeometry.top(), availableGeometry.top())); - if (!restoredNormalGeometry.intersects(availableGeometry)) { restoredNormalGeometry.moveBottom(qMin(restoredNormalGeometry.bottom(), availableGeometry.bottom())); restoredNormalGeometry.moveLeft(qMax(restoredNormalGeometry.left(), availableGeometry.left())); -- cgit v1.2.3 From 85dc392135feb72eed449e6eaf47cdd023879394 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 5 Jul 2019 09:58:45 +0200 Subject: QWidget::restoreGeometry(): Fix Windows being restored out of screen area Factor out the screen area check to a separate helper and apply to restoredGeometry, too, fixing an oversight of 2f2bfc4e59cecfdd210663fbf81c000ecddfb822. Change-Id: I795d8d5e3cddb5e986c96c08a342d69063d04970 Fixes: QTBUG-76900 Reviewed-by: Gatis Paeglis --- src/widgets/kernel/qwidget.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 2f96b95522..fdb3872903 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -7451,6 +7451,17 @@ QByteArray QWidget::saveGeometry() const return array; } +static void checkRestoredGeometry(const QRect &availableGeometry, QRect *restoredGeometry, + int frameHeight) +{ + if (!restoredGeometry->intersects(availableGeometry)) { + restoredGeometry->moveBottom(qMin(restoredGeometry->bottom(), availableGeometry.bottom())); + restoredGeometry->moveLeft(qMax(restoredGeometry->left(), availableGeometry.left())); + restoredGeometry->moveRight(qMin(restoredGeometry->right(), availableGeometry.right())); + } + restoredGeometry->moveTop(qMax(restoredGeometry->top(), availableGeometry.top() + frameHeight)); +} + /*! \since 4.2 @@ -7557,12 +7568,8 @@ bool QWidget::restoreGeometry(const QByteArray &geometry) restoredNormalGeometry.setHeight(qMin(restoredNormalGeometry.height(), availableGeometry.height() - frameHeight)); #endif - if (!restoredNormalGeometry.intersects(availableGeometry)) { - restoredNormalGeometry.moveBottom(qMin(restoredNormalGeometry.bottom(), availableGeometry.bottom())); - restoredNormalGeometry.moveLeft(qMax(restoredNormalGeometry.left(), availableGeometry.left())); - restoredNormalGeometry.moveRight(qMin(restoredNormalGeometry.right(), availableGeometry.right())); - } - restoredNormalGeometry.moveTop(qMax(restoredNormalGeometry.top(), availableGeometry.top() + frameHeight)); + checkRestoredGeometry(availableGeometry, &restoredGeometry, frameHeight); + checkRestoredGeometry(availableGeometry, &restoredNormalGeometry, frameHeight); if (maximized || fullScreen) { // set geometry before setting the window state to make -- cgit v1.2.3 From deac052a40c93633041da058d5c73c9e91aa76c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 12 Jul 2019 12:28:29 +0200 Subject: Revert "Reset QWidget's winId when backing window surface is destroyed" This reverts commit a9246c7132a2c8864d3ae6cebd260bb9ee711fcb. The QWidget machinery is way to fragile to reset the winId under the feet of QWidget like that. We would potentially need to include all the logic in QWidget::destroy. This also ties into the flow between QtGui and QtWidgets during window closing, which is still unresolved. Change-Id: I168048a63c89796398eb5331a80ce3e5c8d9a208 Fixes: QTBUG-76588 Task-number: QTBUG-69289 Reviewed-by: Friedemann Kleint Reviewed-by: Volker Hilsheimer --- src/widgets/kernel/qwidget.cpp | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index fdb3872903..6f0f39a344 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -9382,12 +9382,6 @@ bool QWidget::event(QEvent *event) d->renderToTextureReallyDirty = 1; #endif break; - case QEvent::PlatformSurface: { - auto surfaceEvent = static_cast(event); - if (surfaceEvent->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed) - d->setWinId(0); - break; - } #ifndef QT_NO_PROPERTIES case QEvent::DynamicPropertyChange: { const QByteArray &propName = static_cast(event)->propertyName(); -- cgit v1.2.3 From 7d3a55cbd219bee4e071df5588c87723d9c8f7c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 12 Jul 2019 11:45:07 +0200 Subject: Remove unused arguments from QWidgetPrivate::create_sys The public QWidget::create still has them, but we don't need to propagate them on - that just makes debugging the window creation flow harder. The window argument to QWidget::create is technically used to guard an early exit in the function, but to keep behavior the same we leave it for now. Change-Id: Ic0287575aa25f1272e216adc1b75e34d6f55f6d9 Reviewed-by: Simon Hausmann --- src/widgets/kernel/qwidget.cpp | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 6f0f39a344..bf339ca5c5 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1190,7 +1190,7 @@ void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f) q->setAttribute(Qt::WA_ContentsMarginsRespectsSafeArea); q->setAttribute(Qt::WA_WState_Hidden); - //give potential windows a bigger "pre-initial" size; create_sys() will give them a new size later + //give potential windows a bigger "pre-initial" size; create() will give them a new size later data.crect = parentWidget ? QRect(0,0,100,30) : QRect(0,0,640,480); focus_next = focus_prev = q; @@ -1255,27 +1255,19 @@ void QWidgetPrivate::createRecursively() /*! Creates a new widget window. - The parameter \a window is ignored in Qt 5. Please use - QWindow::fromWinId() to create a QWindow wrapping a foreign - window and pass it to QWidget::createWindowContainer() instead. - - Initializes the window (sets the geometry etc.) if \a - initializeWindow is true. If \a initializeWindow is false, no - initialization is performed. This parameter only makes sense if \a - window is a valid window. - - Destroys the old window if \a destroyOldWindow is true. If \a - destroyOldWindow is false, you are responsible for destroying the - window yourself (using platform native code). - - The QWidget constructor calls create(0,true,true) to create a - window for this widget. + The parameters \a window, \a initializeWindow, and \a destroyOldWindow + are ignored in Qt 5. Please use QWindow::fromWinId() to create a + QWindow wrapping a foreign window and pass it to + QWidget::createWindowContainer() instead. \sa createWindowContainer(), QWindow::fromWinId() */ void QWidget::create(WId window, bool initializeWindow, bool destroyOldWindow) { + Q_UNUSED(initializeWindow); + Q_UNUSED(destroyOldWindow); + Q_D(QWidget); if (Q_UNLIKELY(window)) qWarning("QWidget::create(): Parameter 'window' does not have any effect."); @@ -1335,7 +1327,7 @@ void QWidget::create(WId window, bool initializeWindow, bool destroyOldWindow) d->updateIsOpaque(); setAttribute(Qt::WA_WState_Created); // set created flag - d->create_sys(window, initializeWindow, destroyOldWindow); + d->create(); // a real toplevel window needs a backing store if (isWindow() && windowType() != Qt::Desktop) { @@ -1404,14 +1396,10 @@ void q_createNativeChildrenAndSetParent(const QWidget *parentWidget) } -void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyOldWindow) +void QWidgetPrivate::create() { Q_Q(QWidget); - Q_UNUSED(window); - Q_UNUSED(initializeWindow); - Q_UNUSED(destroyOldWindow); - if (!q->testAttribute(Qt::WA_NativeWindow) && !q->isWindow()) return; // we only care about real toplevels @@ -11340,7 +11328,7 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on) // windowModality property and then reshown. } if (testAttribute(Qt::WA_WState_Created)) { - // don't call setModal_sys() before create_sys() + // don't call setModal_sys() before create() d->setModal_sys(); } break; -- cgit v1.2.3 From 9c2f18d35764fe4c5452d3aa500bd2824ebe7564 Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Mon, 22 Jul 2019 11:12:38 +0200 Subject: Remove usages of deprecated QApplication::keypadNavigationEnabled Added QApplicationPrivate::keypadNavigationEnabled() as a replacement of deprecated QApplication::keypadNavigationEnabled(), for the internal usage. Task-number: QTBUG-76491 Change-Id: I75f4c628b72d86b5e428e7e285a786d23abbf3f2 Reviewed-by: Volker Hilsheimer --- src/widgets/kernel/qwidget.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 3dad7dad1e..f0230f4f32 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -393,7 +393,7 @@ QPointer QWidgetPrivate::editingWidget; This feature is only available in Qt for Embedded Linux. - \sa setEditFocus(), QApplication::keypadNavigationEnabled() + \sa setEditFocus(), QApplication::navigationMode() */ bool QWidget::hasEditFocus() const { @@ -413,7 +413,7 @@ bool QWidget::hasEditFocus() const This feature is only available in Qt for Embedded Linux. - \sa hasEditFocus(), QApplication::keypadNavigationEnabled() + \sa hasEditFocus(), QApplication::navigationMode() */ void QWidget::setEditFocus(bool on) { -- cgit v1.2.3 From 3e7463411e549100eee7abe2a8fae16fd965f8f6 Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 29 Jul 2019 14:27:16 +0200 Subject: Fix crash when the focus widget gets a focus proxy after the fact QApplicationPrivate::focus_widget became a dangling pointer in the following scenario: A widget first gets focus and later on gets a focus proxy. QApplicationPrivate::focus_widget was still pointing to the initial widget. Upon destruction, QWidget::hasFocus() [which follows to the focus proxy and then compares with focus_widget] was therefore false for both widgets. So QWidget::clearFocus() didn't call QApplicationPrivate::setFocusWidget(0) for either of them. As a result, focus_widget remained set, and became dangling. In real life, this happened with a QWebEngineView, which the application gave focus to upon creation. At that time it doesn't have a focus proxy yet. That happens later, in QWebEngineViewPrivate::widgetChanged. https://bugs.kde.org/show_bug.cgi?id=381793 Change-Id: Ifee610bb76a2d4d2797b98ece9bffe5fffe3c6a6 Reviewed-by: Volker Hilsheimer --- src/widgets/kernel/qwidget.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 353a80d1c5..04290a4ce1 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -6436,8 +6436,18 @@ void QWidget::setFocusProxy(QWidget * w) } } + QWidget *oldDeepestFocusProxy = d_func()->deepestFocusProxy(); + if (!oldDeepestFocusProxy) + oldDeepestFocusProxy = this; + const bool changingAppFocusWidget = (QApplicationPrivate::focus_widget == oldDeepestFocusProxy); + d->createExtra(); d->extra->focus_proxy = w; + + if (changingAppFocusWidget) { + QWidget *newDeepestFocusProxy = d_func()->deepestFocusProxy(); + QApplicationPrivate::focus_widget = newDeepestFocusProxy ? newDeepestFocusProxy : this; + } } -- cgit v1.2.3 From 130fd22d399624c863bbaad2f72d2213a48e9e13 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 24 May 2019 19:51:38 +0200 Subject: QWidget/QLineEdit: deprecate get{Contents,Text}Margins() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We have contentsMargins() and textMargins() methods since 4.6 which are much more efficient and easier to use. [ChangeLog][QtWidgets][QLineEdit] The getTextMargins() member function has been deprecated in favor of textMargins(). [ChangeLog][QtWidgets][QWidget] The getContentsMargins() member function has been deprecated in favor of contentsMargins(). Change-Id: Ifdb890af6198fc682b94701786c67a5b945a4b4c Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Lars Knoll --- src/widgets/kernel/qwidget.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index f0230f4f32..209a4407a0 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -7634,7 +7634,7 @@ bool QWidget::restoreGeometry(const QByteArray &geometry) Changing the margins will trigger a resizeEvent(). - \sa contentsRect(), getContentsMargins() + \sa contentsRect(), contentsMargins() */ void QWidget::setContentsMargins(int left, int top, int right, int bottom) { @@ -7664,7 +7664,7 @@ void QWidget::setContentsMargins(int left, int top, int right, int bottom) Changing the margins will trigger a resizeEvent(). - \sa contentsRect(), getContentsMargins() + \sa contentsRect(), contentsMargins() */ void QWidget::setContentsMargins(const QMargins &margins) { @@ -7693,7 +7693,11 @@ void QWidgetPrivate::updateContentsRect() QCoreApplication::sendEvent(q, &e); } +#if QT_DEPRECATED_SINCE(5, 14) /*! + \obsolete + Use contentsMargins(). + Returns the widget's contents margins for \a left, \a top, \a right, and \a bottom. @@ -7711,6 +7715,7 @@ void QWidget::getContentsMargins(int *left, int *top, int *right, int *bottom) c if (bottom) *bottom = m.bottom(); } +#endif // FIXME: Move to qmargins.h for next minor Qt release QMargins operator|(const QMargins &m1, const QMargins &m2) @@ -7724,7 +7729,7 @@ QMargins operator|(const QMargins &m1, const QMargins &m2) \brief The contentsMargins function returns the widget's contents margins. - \sa getContentsMargins(), setContentsMargins(), contentsRect() + \sa setContentsMargins(), contentsRect() */ QMargins QWidget::contentsMargins() const { @@ -7737,7 +7742,7 @@ QMargins QWidget::contentsMargins() const /*! Returns the area inside the widget's margins. - \sa setContentsMargins(), getContentsMargins() + \sa setContentsMargins(), contentsMargins() */ QRect QWidget::contentsRect() const { -- cgit v1.2.3