summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/kernel')
-rw-r--r--src/widgets/kernel/qapplication.cpp13
-rw-r--r--src/widgets/kernel/qformlayout.cpp2
-rw-r--r--src/widgets/kernel/qlayout.cpp28
-rw-r--r--src/widgets/kernel/qlayout.h4
-rw-r--r--src/widgets/kernel/qwidget.cpp22
-rw-r--r--src/widgets/kernel/qwidget.h2
-rw-r--r--src/widgets/kernel/qwidget_qpa.cpp6
-rw-r--r--src/widgets/kernel/qwidgetbackingstore_p.h8
-rw-r--r--src/widgets/kernel/qwidgetwindow.cpp11
-rw-r--r--src/widgets/kernel/qwindowcontainer.cpp24
-rw-r--r--src/widgets/kernel/qwindowcontainer_p.h1
-rw-r--r--src/widgets/kernel/win.pri2
12 files changed, 93 insertions, 30 deletions
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index 210cb29120..57a2063b78 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -111,13 +111,10 @@ extern bool qt_wince_is_pocket_pc(); //qguifunctions_wince.cpp
static void initResources()
{
#if defined(Q_OS_WINCE)
- Q_INIT_RESOURCE_EXTERN(qstyle_wince)
Q_INIT_RESOURCE(qstyle_wince);
#else
- Q_INIT_RESOURCE_EXTERN(qstyle)
Q_INIT_RESOURCE(qstyle);
#endif
- Q_INIT_RESOURCE_EXTERN(qmessagebox)
Q_INIT_RESOURCE(qmessagebox);
}
@@ -3762,6 +3759,16 @@ void QApplicationPrivate::giveFocusAccordingToFocusPolicy(QWidget *widget, QEven
}
if (focusWidget->isWindow())
break;
+
+ // find out whether this widget (or its proxy) already has focus
+ QWidget *f = focusWidget;
+ if (focusWidget->d_func()->extra && focusWidget->d_func()->extra->focus_proxy)
+ f = focusWidget->d_func()->extra->focus_proxy;
+ // if it has, stop here.
+ // otherwise a click on the focused widget would remove its focus if ClickFocus isn't set
+ if (f->hasFocus())
+ break;
+
localPos += focusWidget->pos();
focusWidget = focusWidget->parentWidget();
}
diff --git a/src/widgets/kernel/qformlayout.cpp b/src/widgets/kernel/qformlayout.cpp
index e1376c754f..c1d3e95e7a 100644
--- a/src/widgets/kernel/qformlayout.cpp
+++ b/src/widgets/kernel/qformlayout.cpp
@@ -641,7 +641,7 @@ static inline int spacingHelper(QWidget* parent, QStyle *style, int userVSpacing
spacing = qMax(spacing, prevItem2->geometry().top() - wid->geometry().top() );
}
}
- return spacing;
+ return qMax(spacing, 0);
}
static inline void initLayoutStruct(QLayoutStruct& sl, QFormLayoutItem* item)
diff --git a/src/widgets/kernel/qlayout.cpp b/src/widgets/kernel/qlayout.cpp
index cd2891d829..eb21a580b1 100644
--- a/src/widgets/kernel/qlayout.cpp
+++ b/src/widgets/kernel/qlayout.cpp
@@ -1112,18 +1112,26 @@ bool QLayout::activate()
\since 5.2
Searches for widget \a from and replaces it with widget \a to if found.
- Returns the layout item that contains the widget \a from on success. Otherwise \c 0 is returned.
- If \a recursive is \c true, sub-layouts are searched for doing the replacement. Notice that the returned item therefore might not belong to this layout, but to a sub-layout.
+ Returns the layout item that contains the widget \a from on success.
+ Otherwise \c 0 is returned. If \a options contains \c Qt::FindChildrenRecursively
+ (the default), sub-layouts are searched for doing the replacement.
+ Any other flag in \a options is ignored.
- The returned layout item is no longer owned by the layout and should be either deleted or inserted to another layout. The widget \a from is no longer managed by the layout and may need to be deleted or hidden. The parent of widget \a from is left unchanged.
+ Notice that the returned item therefore might not belong to this layout,
+ but to a sub-layout.
- This function works for the built-in Qt layouts, but might not work for custom layouts.
+ The returned layout item is no longer owned by the layout and should be
+ either deleted or inserted to another layout. The widget \a from is no
+ longer managed by the layout and may need to be deleted or hidden. The
+ parent of widget \a from is left unchanged.
+
+ This function works for the built-in Qt layouts, but might not work for
+ custom layouts.
\sa indexOf()
*/
-//### Qt 6 make this function virtual
-QLayoutItem* QLayout::replaceWidget(QWidget *from, QWidget *to, bool recursive)
+QLayoutItem *QLayout::replaceWidget(QWidget *from, QWidget *to, Qt::FindChildOptions options)
{
Q_D(QLayout);
if (!from || !to)
@@ -1133,12 +1141,16 @@ QLayoutItem* QLayout::replaceWidget(QWidget *from, QWidget *to, bool recursive)
QLayoutItem *item = 0;
for (int u = 0; u < count(); ++u) {
item = itemAt(u);
+ if (!item)
+ continue;
+
if (item->widget() == from) {
index = u;
break;
}
- if (item && item->layout() && recursive) {
- QLayoutItem *r = item->layout()->replaceWidget(from, to, true);
+
+ if (item->layout() && (options & Qt::FindChildrenRecursively)) {
+ QLayoutItem *r = item->layout()->replaceWidget(from, to, options);
if (r)
return r;
}
diff --git a/src/widgets/kernel/qlayout.h b/src/widgets/kernel/qlayout.h
index ca5f6d42ea..27d9d34b9c 100644
--- a/src/widgets/kernel/qlayout.h
+++ b/src/widgets/kernel/qlayout.h
@@ -130,7 +130,9 @@ public:
virtual int count() const = 0;
bool isEmpty() const;
QSizePolicy::ControlTypes controlTypes() const;
- QLayoutItem* replaceWidget(QWidget *from, QWidget *to, bool recursive = true);
+
+ // ### Qt 6 make this function virtual
+ QLayoutItem *replaceWidget(QWidget *from, QWidget *to, Qt::FindChildOptions options = Qt::FindChildrenRecursively);
int totalHeightForWidth(int w) const;
QSize totalMinimumSize() const;
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index 55459ac1ac..0d8e20ca0c 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -289,7 +289,7 @@ QWidgetPrivate::QWidgetPrivate(int version)
#endif
{
if (!qApp) {
- qFatal("QWidget: Must construct a QApplication before a QPaintDevice");
+ qFatal("QWidget: Must construct a QApplication before a QWidget");
return;
}
@@ -6999,21 +6999,23 @@ void QWidget::setUpdatesEnabled(bool enable)
}
/*!
- Shows the widget and its child widgets. This function is
- equivalent to setVisible(true) in the normal case, and equivalent
- to showFullScreen() if the QStyleHints::showIsFullScreen() hint
- is true and the window is not a popup.
+ Shows the widget and its child widgets.
- \sa raise(), showEvent(), hide(), setVisible(), showMinimized(), showMaximized(),
- showNormal(), isVisible(), windowFlags()
+ This is equivalent to calling showFullScreen(), showMaximized(), or setVisible(true),
+ depending on the platform's default behavior for the window flags.
+
+ \sa raise(), showEvent(), hide(), setVisible(), showMinimized(), showMaximized(),
+ showNormal(), isVisible(), windowFlags(), flags()
*/
void QWidget::show()
{
- bool isPopup = data->window_flags & Qt::Popup & ~Qt::Window;
- if (isWindow() && !isPopup && qApp->styleHints()->showIsFullScreen())
+ Qt::WindowState defaultState = QGuiApplicationPrivate::platformIntegration()->defaultWindowState(data->window_flags);
+ if (defaultState == Qt::WindowFullScreen)
showFullScreen();
+ else if (defaultState == Qt::WindowMaximized)
+ showMaximized();
else
- setVisible(true);
+ setVisible(true); // FIXME: Why not showNormal(), like QWindow::show()?
}
/*! \internal
diff --git a/src/widgets/kernel/qwidget.h b/src/widgets/kernel/qwidget.h
index a9eeaa5470..159011b824 100644
--- a/src/widgets/kernel/qwidget.h
+++ b/src/widgets/kernel/qwidget.h
@@ -733,6 +733,7 @@ private:
Q_DECLARE_OPERATORS_FOR_FLAGS(QWidget::RenderFlags)
+#ifndef Q_QDOC
template <> inline QWidget *qobject_cast<QWidget*>(QObject *o)
{
if (!o || !o->isWidgetType()) return 0;
@@ -743,6 +744,7 @@ template <> inline const QWidget *qobject_cast<const QWidget*>(const QObject *o)
if (!o || !o->isWidgetType()) return 0;
return static_cast<const QWidget*>(o);
}
+#endif // !Q_QDOC
inline QWidget *QWidget::childAt(int ax, int ay) const
{ return childAt(QPoint(ax, ay)); }
diff --git a/src/widgets/kernel/qwidget_qpa.cpp b/src/widgets/kernel/qwidget_qpa.cpp
index ae8a0b25b9..93234f3958 100644
--- a/src/widgets/kernel/qwidget_qpa.cpp
+++ b/src/widgets/kernel/qwidget_qpa.cpp
@@ -53,6 +53,7 @@
#include <qpa/qplatformintegration.h>
#include "QtGui/private/qwindow_p.h"
#include "QtGui/private/qguiapplication_p.h"
+#include <private/qwindowcontainer_p.h>
#include <qpa/qplatformcursor.h>
#include <QtGui/QGuiApplication>
@@ -267,8 +268,11 @@ void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f)
bool explicitlyHidden = q->testAttribute(Qt::WA_WState_Hidden) && q->testAttribute(Qt::WA_WState_ExplicitShowHide);
// Reparenting toplevel to child
- if (wasCreated && !(f & Qt::Window) && (oldFlags & Qt::Window) && !q->testAttribute(Qt::WA_NativeWindow))
+ if (wasCreated && !(f & Qt::Window) && (oldFlags & Qt::Window) && !q->testAttribute(Qt::WA_NativeWindow)) {
+ if (extra && extra->hasWindowContainer)
+ QWindowContainer::toplevelAboutToBeDestroyed(q);
q->destroy();
+ }
adjustFlags(f, q);
data.window_flags = f;
diff --git a/src/widgets/kernel/qwidgetbackingstore_p.h b/src/widgets/kernel/qwidgetbackingstore_p.h
index 39583c8caa..b6c3e13cb0 100644
--- a/src/widgets/kernel/qwidgetbackingstore_p.h
+++ b/src/widgets/kernel/qwidgetbackingstore_p.h
@@ -240,7 +240,13 @@ private:
}
inline bool hasStaticContents() const
- { return !staticWidgets.isEmpty() && false; }
+ {
+#if defined(Q_OS_WIN)
+ return !staticWidgets.isEmpty();
+#else
+ return !staticWidgets.isEmpty() && false;
+#endif
+ }
friend QRegion qt_dirtyRegion(QWidget *);
friend class QWidgetPrivate;
diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp
index 51a0eb7d72..2e96247873 100644
--- a/src/widgets/kernel/qwidgetwindow.cpp
+++ b/src/widgets/kernel/qwidgetwindow.cpp
@@ -76,6 +76,13 @@ public:
}
return w;
}
+
+ void clearFocusObject()
+ {
+ if (QApplicationPrivate::focus_widget)
+ QApplicationPrivate::focus_widget->clearFocus();
+ }
+
};
QWidgetWindow::QWidgetWindow(QWidget *widget)
@@ -244,7 +251,9 @@ bool QWidgetWindow::event(QEvent *event)
case QEvent::Show:
case QEvent::Hide:
return QWindow::event(event);
-
+ case QEvent::WindowBlocked:
+ qt_button_down = 0;
+ break;
default:
break;
}
diff --git a/src/widgets/kernel/qwindowcontainer.cpp b/src/widgets/kernel/qwindowcontainer.cpp
index 6914f64f8e..399f089e0f 100644
--- a/src/widgets/kernel/qwindowcontainer.cpp
+++ b/src/widgets/kernel/qwindowcontainer.cpp
@@ -222,6 +222,11 @@ void QWindowContainer::focusWindowChanged(QWindow *focusWindow)
{
Q_D(QWindowContainer);
d->oldFocusWindow = focusWindow;
+ if (focusWindow == d->window) {
+ QWidget *widget = QApplication::focusWidget();
+ if (widget)
+ widget->clearFocus();
+ }
}
/*!
@@ -300,15 +305,28 @@ static void qwindowcontainer_traverse(QWidget *parent, qwindowcontainer_traverse
}
}
+void QWindowContainer::toplevelAboutToBeDestroyed(QWidget *parent)
+{
+ if (QWindowContainerPrivate *d = QWindowContainerPrivate::get(parent)) {
+ d->window->setParent(&d->fakeParent);
+ }
+ qwindowcontainer_traverse(parent, toplevelAboutToBeDestroyed);
+}
+
void QWindowContainer::parentWasChanged(QWidget *parent)
{
if (QWindowContainerPrivate *d = QWindowContainerPrivate::get(parent)) {
if (d->window->parent()) {
d->updateUsesNativeWidgets();
d->markParentChain();
- d->window->setParent(d->usesNativeWidgets
- ? parent->windowHandle()
- : parent->window()->windowHandle());
+ QWidget *toplevel = d->usesNativeWidgets ? parent : parent->window();
+ if (!toplevel->windowHandle()) {
+ QWidgetPrivate *tld = static_cast<QWidgetPrivate *>(QWidgetPrivate::get(toplevel));
+ tld->createTLExtra();
+ tld->createTLSysExtra();
+ Q_ASSERT(toplevel->windowHandle());
+ }
+ d->window->setParent(toplevel->windowHandle());
d->updateGeometry();
}
}
diff --git a/src/widgets/kernel/qwindowcontainer_p.h b/src/widgets/kernel/qwindowcontainer_p.h
index e2446bef42..a21f9bd35a 100644
--- a/src/widgets/kernel/qwindowcontainer_p.h
+++ b/src/widgets/kernel/qwindowcontainer_p.h
@@ -57,6 +57,7 @@ public:
explicit QWindowContainer(QWindow *embeddedWindow, QWidget *parent = 0, Qt::WindowFlags f = 0);
~QWindowContainer();
+ static void toplevelAboutToBeDestroyed(QWidget *parent);
static void parentWasChanged(QWidget *parent);
static void parentWasMoved(QWidget *parent);
static void parentWasRaised(QWidget *parent);
diff --git a/src/widgets/kernel/win.pri b/src/widgets/kernel/win.pri
index 18bd692476..76bb709e2b 100644
--- a/src/widgets/kernel/win.pri
+++ b/src/widgets/kernel/win.pri
@@ -3,5 +3,5 @@
INCLUDEPATH += ../3rdparty/wintab
!wince*:!winrt {
- LIBS *= -lshell32
+ LIBS_PRIVATE *= -lshell32
}