summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-09-26 16:08:55 +0200
committerLiang Qi <liang.qi@qt.io>2017-09-26 16:14:54 +0200
commitaadfe7d634de04519102c5827ca885dc2e2199c9 (patch)
treed92db346ca95332b177036a53f1f6beb2e24fb74 /src/widgets/kernel
parent4b6c1448047362b8c38d265e6414f0e3e59b8d37 (diff)
parenta732e16d5fd9dbf8a0289fec9f948b12e9ba2c19 (diff)
Merge remote-tracking branch 'origin/5.10' into dev
Conflicts: src/gui/kernel/qguiapplication.cpp src/platformsupport/input/libinput/qlibinputpointer.cpp src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.h src/plugins/platforms/cocoa/qcocoawindow.h src/testlib/qtestsystem.h Change-Id: I5975ffb3261c2dd82fe02ec4e57df7c0950226c5
Diffstat (limited to 'src/widgets/kernel')
-rw-r--r--src/widgets/kernel/qaction.cpp6
-rw-r--r--src/widgets/kernel/qaction.h2
-rw-r--r--src/widgets/kernel/qaction_p.h2
-rw-r--r--src/widgets/kernel/qapplication.cpp9
-rw-r--r--src/widgets/kernel/qdesktopwidget.cpp22
-rw-r--r--src/widgets/kernel/qlayout.cpp18
-rw-r--r--src/widgets/kernel/qlayoutitem.cpp2
-rw-r--r--src/widgets/kernel/qshortcut.cpp10
-rw-r--r--src/widgets/kernel/qtooltip.cpp8
-rw-r--r--src/widgets/kernel/qwidget.cpp39
-rw-r--r--src/widgets/kernel/qwidget_p.h1
-rw-r--r--src/widgets/kernel/qwindowcontainer.cpp6
12 files changed, 79 insertions, 46 deletions
diff --git a/src/widgets/kernel/qaction.cpp b/src/widgets/kernel/qaction.cpp
index a7116b1462..2813340ea2 100644
--- a/src/widgets/kernel/qaction.cpp
+++ b/src/widgets/kernel/qaction.cpp
@@ -48,7 +48,9 @@
#include "qstylehints.h"
#include <private/qshortcutmap_p.h>
#include <private/qapplication_p.h>
+#if QT_CONFIG(menu)
#include <private/qmenu_p.h>
+#endif
#include <private/qdebug_p.h>
#define QAPP_CHECK(functionName) \
@@ -645,7 +647,7 @@ QIcon QAction::icon() const
return d->icon;
}
-#ifndef QT_NO_MENU
+#if QT_CONFIG(menu)
/*!
Returns the menu contained by this action. Actions that contain
menus can be used to create menu items with submenus, or inserted
@@ -672,7 +674,7 @@ void QAction::setMenu(QMenu *menu)
menu->d_func()->setOverrideMenuAction(this);
d->sendDataChanged();
}
-#endif // QT_NO_MENU
+#endif // QT_CONFIG(menu)
/*!
If \a b is true then this action will be considered a separator.
diff --git a/src/widgets/kernel/qaction.h b/src/widgets/kernel/qaction.h
index 2cb30d0fc9..84bf92d2ac 100644
--- a/src/widgets/kernel/qaction.h
+++ b/src/widgets/kernel/qaction.h
@@ -121,7 +121,7 @@ public:
void setPriority(Priority priority);
Priority priority() const;
-#ifndef QT_NO_MENU
+#if QT_CONFIG(menu)
QMenu *menu() const;
void setMenu(QMenu *menu);
#endif
diff --git a/src/widgets/kernel/qaction_p.h b/src/widgets/kernel/qaction_p.h
index 4c1537b63b..19ae47c7b9 100644
--- a/src/widgets/kernel/qaction_p.h
+++ b/src/widgets/kernel/qaction_p.h
@@ -53,7 +53,9 @@
#include <QtWidgets/private/qtwidgetsglobal_p.h>
#include "QtWidgets/qaction.h"
+#if QT_CONFIG(menu)
#include "QtWidgets/qmenu.h"
+#endif
#if QT_CONFIG(graphicsview)
#include "private/qgraphicswidget_p.h"
#endif
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index d141abce24..93e2db4b1a 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -2228,8 +2228,15 @@ QWidget *QApplicationPrivate::focusNextPrevChild_helper(QWidget *toplevel, bool
if (test->isWindow())
seenWindow = true;
+ // If the next focus widget has a focus proxy, we need to check to ensure
+ // that the proxy is in the correct parent-child direction (according to
+ // \a next). This is to ensure that we can tab in and out of compound widgets
+ // without getting stuck in a tab-loop between parent and child.
+ QWidget *focusProxy = test->d_func()->deepestFocusProxy();
+
if ((test->focusPolicy() & focus_flag) == focus_flag
- && !(test->d_func()->extra && test->d_func()->extra->focus_proxy)
+ && !(next && focusProxy && focusProxy->isAncestorOf(test))
+ && !(!next && focusProxy && test->isAncestorOf(focusProxy))
&& test->isVisibleTo(toplevel) && test->isEnabled()
&& !(w->windowType() == Qt::SubWindow && !w->isAncestorOf(test))
&& (toplevel->windowType() != Qt::SubWindow || toplevel->isAncestorOf(test))) {
diff --git a/src/widgets/kernel/qdesktopwidget.cpp b/src/widgets/kernel/qdesktopwidget.cpp
index ff32540715..09e39c7cff 100644
--- a/src/widgets/kernel/qdesktopwidget.cpp
+++ b/src/widgets/kernel/qdesktopwidget.cpp
@@ -352,26 +352,8 @@ int QDesktopWidget::screenNumber(const QPoint &p) const
int QDesktopWidgetPrivate::screenNumber(const QPoint &p)
{
- const QList<QScreen *> screens = QGuiApplication::screens();
- if (!screens.isEmpty()) {
- const QList<QScreen *> primaryScreens = screens.first()->virtualSiblings();
- // Find the screen index on the primary virtual desktop first
- foreach (QScreen *screen, primaryScreens) {
- if (screen->geometry().contains(p))
- return screens.indexOf(screen);
- }
- // If the screen index is not found on primary virtual desktop, find
- // the screen index on all screens except the first which was for
- // sure in the previous loop. Some other screens may repeat. Find
- // only when there is more than one virtual desktop.
- if (screens.count() != primaryScreens.count()) {
- for (int i = 1; i < screens.size(); ++i) {
- if (screens[i]->geometry().contains(p))
- return i;
- }
- }
- }
- return primaryScreen(); //even better would be closest screen
+ QScreen *screen = QGuiApplication::screenAt(p);
+ return screen ? QGuiApplication::screens().indexOf(screen) : primaryScreen();
}
void QDesktopWidget::resizeEvent(QResizeEvent *)
diff --git a/src/widgets/kernel/qlayout.cpp b/src/widgets/kernel/qlayout.cpp
index 129c12885a..1e455b0d64 100644
--- a/src/widgets/kernel/qlayout.cpp
+++ b/src/widgets/kernel/qlayout.cpp
@@ -41,9 +41,13 @@
#include "qapplication.h"
#include "qlayoutengine_p.h"
+#if QT_CONFIG(menubar)
#include "qmenubar.h"
+#endif
#include "qtoolbar.h"
+#if QT_CONFIG(sizegrip)
#include "qsizegrip.h"
+#endif
#include "qevent.h"
#include "qstyle.h"
#include "qvariant.h"
@@ -583,7 +587,7 @@ void QLayoutPrivate::doResize(const QSize &r)
const int mbTop = rect.top();
rect.setTop(mbTop + mbh);
q->setGeometry(rect);
-#ifndef QT_NO_MENUBAR
+#if QT_CONFIG(menubar)
if (menubar)
menubar->setGeometry(rect.left(), mbTop, r.width(), mbh);
#endif
@@ -615,7 +619,7 @@ void QLayout::widgetEvent(QEvent *e)
{
QChildEvent *c = (QChildEvent *)e;
if (c->child()->isWidgetType()) {
-#ifndef QT_NO_MENUBAR
+#if QT_CONFIG(menubar)
if (c->child() == d->menubar)
d->menubar = 0;
#endif
@@ -664,7 +668,7 @@ int QLayout::totalHeightForWidth(int w) const
top += wd->topmargin + wd->bottommargin;
}
int h = heightForWidth(w - side) + top;
-#ifndef QT_NO_MENUBAR
+#if QT_CONFIG(menubar)
h += menuBarHeightForWidth(d->menubar, w);
#endif
return h;
@@ -687,7 +691,7 @@ QSize QLayout::totalMinimumSize() const
}
QSize s = minimumSize();
-#ifndef QT_NO_MENUBAR
+#if QT_CONFIG(menubar)
top += menuBarHeightForWidth(d->menubar, s.width() + side);
#endif
return s + QSize(side, top);
@@ -712,7 +716,7 @@ QSize QLayout::totalSizeHint() const
QSize s = sizeHint();
if (hasHeightForWidth())
s.setHeight(heightForWidth(s.width() + side));
-#ifndef QT_NO_MENUBAR
+#if QT_CONFIG(menubar)
top += menuBarHeightForWidth(d->menubar, s.width());
#endif
return s + QSize(side, top);
@@ -735,7 +739,7 @@ QSize QLayout::totalMaximumSize() const
}
QSize s = maximumSize();
-#ifndef QT_NO_MENUBAR
+#if QT_CONFIG(menubar)
top += menuBarHeightForWidth(d->menubar, s.width());
#endif
@@ -813,7 +817,7 @@ void QLayoutPrivate::reparentChildWidgets(QWidget *mw)
Q_Q(QLayout);
int n = q->count();
-#ifndef QT_NO_MENUBAR
+#if QT_CONFIG(menubar)
if (menubar && menubar->parentWidget() != mw) {
menubar->setParent(mw);
}
diff --git a/src/widgets/kernel/qlayoutitem.cpp b/src/widgets/kernel/qlayoutitem.cpp
index 51793bf060..0bdac43c56 100644
--- a/src/widgets/kernel/qlayoutitem.cpp
+++ b/src/widgets/kernel/qlayoutitem.cpp
@@ -41,7 +41,9 @@
#include "qapplication.h"
#include "qlayoutengine_p.h"
+#if QT_CONFIG(menubar)
#include "qmenubar.h"
+#endif
#include "qtoolbar.h"
#include "qevent.h"
#include "qstyle.h"
diff --git a/src/widgets/kernel/qshortcut.cpp b/src/widgets/kernel/qshortcut.cpp
index 891cf563d6..0585a59e89 100644
--- a/src/widgets/kernel/qshortcut.cpp
+++ b/src/widgets/kernel/qshortcut.cpp
@@ -45,8 +45,12 @@
#if QT_CONFIG(whatsthis)
#include <qwhatsthis.h>
#endif
+#if QT_CONFIG(menu)
#include <qmenu.h>
+#endif
+#if QT_CONFIG(menubar)
#include <qmenubar.h>
+#endif
#include <qapplication.h>
#include <private/qapplication_p.h>
#include <private/qshortcutmap_p.h>
@@ -143,7 +147,7 @@ bool qWidgetShortcutContextMatcher(QObject *object, Qt::ShortcutContext context)
static bool correctWidgetContext(Qt::ShortcutContext context, QWidget *w, QWidget *active_window)
{
bool visible = w->isVisible();
-#ifndef QT_NO_MENUBAR
+#if QT_CONFIG(menubar)
if (QMenuBar *menuBar = qobject_cast<QMenuBar *>(w)) {
if (menuBar->isNativeMenuBar())
visible = true;
@@ -208,7 +212,7 @@ static bool correctWidgetContext(Qt::ShortcutContext context, QWidget *w, QWidge
static bool correctGraphicsWidgetContext(Qt::ShortcutContext context, QGraphicsWidget *w, QWidget *active_window)
{
bool visible = w->isVisible();
-#if defined(Q_OS_DARWIN) && !defined(QT_NO_MENUBAR)
+#if defined(Q_OS_DARWIN) && QT_CONFIG(menubar)
if (!qApp->testAttribute(Qt::AA_DontUseNativeMenuBar) && qobject_cast<QMenuBar *>(w))
visible = true;
#endif
@@ -274,7 +278,7 @@ static bool correctActionContext(Qt::ShortcutContext context, QAction *a, QWidge
#endif
for (int i = 0; i < widgets.size(); ++i) {
QWidget *w = widgets.at(i);
-#ifndef QT_NO_MENU
+#if QT_CONFIG(menu)
if (QMenu *menu = qobject_cast<QMenu *>(w)) {
#ifdef Q_OS_DARWIN
// On Mac, menu item shortcuts are processed before reaching any window.
diff --git a/src/widgets/kernel/qtooltip.cpp b/src/widgets/kernel/qtooltip.cpp
index 12badcee3d..f30a83611d 100644
--- a/src/widgets/kernel/qtooltip.cpp
+++ b/src/widgets/kernel/qtooltip.cpp
@@ -40,6 +40,8 @@
# include <private/qcore_mac_p.h>
#endif
+#include <QtWidgets/private/qtwidgetsglobal_p.h>
+
#include <qapplication.h>
#include <qdesktopwidget.h>
#include <private/qdesktopwidget_p.h>
@@ -49,7 +51,9 @@
#include <qstyleoption.h>
#include <qstylepainter.h>
#include <qtimer.h>
+#if QT_CONFIG(effects)
#include <private/qeffects_p.h>
+#endif
#include <qtextdocument.h>
#include <qdebug.h>
#include <private/qstylesheetstyle_p.h>
@@ -286,7 +290,7 @@ void QTipLabel::timerEvent(QTimerEvent *e)
|| e->timerId() == expireTimer.timerId()){
hideTimer.stop();
expireTimer.stop();
-#if 0 /* Used to be included in Qt4 for Q_WS_MAC */ && !defined(QT_NO_EFFECTS)
+#if 0 /* Used to be included in Qt4 for Q_WS_MAC */ && QT_CONFIG(effects)
if (QApplication::isEffectEnabled(Qt::UI_FadeTooltip)){
// Fade out tip on mac (makes it invisible).
// The tip will not be deleted until a new tip is shown.
@@ -506,7 +510,7 @@ void QToolTip::showText(const QPoint &pos, const QString &text, QWidget *w, cons
QTipLabel::instance->setObjectName(QLatin1String("qtooltip_label"));
-#if !defined(QT_NO_EFFECTS) && !0 /* Used to be included in Qt4 for Q_WS_MAC */
+#if QT_CONFIG(effects) && !0 /* Used to be included in Qt4 for Q_WS_MAC */
if (QApplication::isEffectEnabled(Qt::UI_FadeTooltip))
qFadeEffect(QTipLabel::instance);
else if (QApplication::isEffectEnabled(Qt::UI_AnimateTooltip))
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index c245c7e2e7..4794a26804 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -45,7 +45,9 @@
#include "qdesktopwidget_p.h"
#include "qevent.h"
#include "qlayout.h"
+#if QT_CONFIG(menu)
#include "qmenu.h"
+#endif
#include "qmetaobject.h"
#include "qpixmap.h"
#include "qpointer.h"
@@ -2439,7 +2441,7 @@ void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, int
{
Q_Q(const QWidget);
-#ifndef QT_NO_SCROLLAREA
+#if QT_CONFIG(scrollarea)
bool resetBrushOrigin = false;
QPointF oldBrushOrigin;
//If we are painting the viewport of a scrollarea, we must apply an offset to the brush in case we are drawing a texture
@@ -2452,7 +2454,7 @@ void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, int
painter->setBrushOrigin(-priv->contentsOffset());
}
-#endif // QT_NO_SCROLLAREA
+#endif // QT_CONFIG(scrollarea)
const QBrush autoFillBrush = q->palette().brush(q->backgroundRole());
@@ -2479,10 +2481,10 @@ void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, int
q->style()->drawPrimitive(QStyle::PE_Widget, &opt, painter, q);
}
-#ifndef QT_NO_SCROLLAREA
+#if QT_CONFIG(scrollarea)
if (resetBrushOrigin)
painter->setBrushOrigin(oldBrushOrigin);
-#endif // QT_NO_SCROLLAREA
+#endif // QT_CONFIG(scrollarea)
}
/*
@@ -6521,9 +6523,9 @@ void QWidget::setFocus(Qt::FocusReason reason)
if (!isEnabled())
return;
- QWidget *f = this;
- while (f->d_func()->extra && f->d_func()->extra->focus_proxy)
- f = f->d_func()->extra->focus_proxy;
+ QWidget *f = d_func()->deepestFocusProxy();
+ if (!f)
+ f = this;
if (QApplication::focusWidget() == f
#if 0 // Used to be included in Qt4 for Q_WS_WIN
@@ -6620,6 +6622,27 @@ void QWidget::setFocus(Qt::FocusReason reason)
}
}
+
+/*!\internal
+ * A focus proxy can have its own focus proxy, which can have its own
+ * proxy, and so on. This helper function returns the widget that sits
+ * at the bottom of the proxy chain, and therefore the one that should
+ * normally get focus if this widget receives a focus request.
+ */
+QWidget *QWidgetPrivate::deepestFocusProxy() const
+{
+ Q_Q(const QWidget);
+
+ QWidget *focusProxy = q->focusProxy();
+ if (!focusProxy)
+ return nullptr;
+
+ while (QWidget *nextFocusProxy = focusProxy->focusProxy())
+ focusProxy = nextFocusProxy;
+
+ return focusProxy;
+}
+
void QWidgetPrivate::setFocus_sys()
{
Q_Q(QWidget);
@@ -8983,7 +9006,7 @@ bool QWidget::event(QEvent *event)
case Qt::CustomContextMenu:
emit customContextMenuRequested(static_cast<QContextMenuEvent *>(event)->pos());
break;
-#ifndef QT_NO_MENU
+#if QT_CONFIG(menu)
case Qt::ActionsContextMenu:
if (d->actions.count()) {
QMenu::exec(d->actions, static_cast<QContextMenuEvent *>(event)->globalPos(),
diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h
index 57da51dcba..26f8b53392 100644
--- a/src/widgets/kernel/qwidget_p.h
+++ b/src/widgets/kernel/qwidget_p.h
@@ -369,6 +369,7 @@ public:
void lower_sys();
void stackUnder_sys(QWidget *);
+ QWidget *deepestFocusProxy() const;
void setFocus_sys();
void updateFocusChild();
diff --git a/src/widgets/kernel/qwindowcontainer.cpp b/src/widgets/kernel/qwindowcontainer.cpp
index a17c69c5ce..d2ad7a466e 100644
--- a/src/widgets/kernel/qwindowcontainer.cpp
+++ b/src/widgets/kernel/qwindowcontainer.cpp
@@ -44,7 +44,9 @@
#include <qpa/qplatformintegration.h>
#include <QDebug>
+#if QT_CONFIG(mdiarea)
#include <QMdiSubWindow>
+#endif
#include <QAbstractScrollArea>
QT_BEGIN_NAMESPACE
@@ -98,10 +100,10 @@ public:
QWidget *p = q->parentWidget();
while (p) {
if (false
-#ifndef QT_NO_MDIAREA
+#if QT_CONFIG(mdiarea)
|| qobject_cast<QMdiSubWindow *>(p) != 0
#endif
-#ifndef QT_NO_SCROLLAREA
+#if QT_CONFIG(scrollarea)
|| qobject_cast<QAbstractScrollArea *>(p) != 0
#endif
) {