diff options
Diffstat (limited to 'src/widgets/kernel/qapplication.cpp')
-rw-r--r-- | src/widgets/kernel/qapplication.cpp | 175 |
1 files changed, 81 insertions, 94 deletions
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index 93ee820c98..ef046f3ef8 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -1,31 +1,37 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtWidgets module of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL21$ +** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. ** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** @@ -65,6 +71,7 @@ #include <QtGui/qstylehints.h> #include <QtGui/qinputmethod.h> #include <QtGui/private/qwindow_p.h> +#include <QtGui/qtouchdevice.h> #include <qpa/qplatformtheme.h> #ifndef QT_NO_WHATSTHIS #include <QtWidgets/QWhatsThis> @@ -429,8 +436,6 @@ Qt::NavigationMode QApplicationPrivate::navigationMode = Qt::NavigationModeKeypa QWidget *QApplicationPrivate::oldEditFocus = 0; #endif -bool qt_tabletChokeMouse = false; - inline bool QApplicationPrivate::isAlien(QWidget *widget) { return widget && !widget->isWindow(); @@ -788,7 +793,7 @@ void QApplicationPrivate::initializeWidgetFontHash() QWidget *QApplication::activePopupWidget() { return QApplicationPrivate::popupWidgets && !QApplicationPrivate::popupWidgets->isEmpty() ? - QApplicationPrivate::popupWidgets->last() : 0; + QApplicationPrivate::popupWidgets->constLast() : nullptr; } @@ -1021,7 +1026,7 @@ bool QApplication::compressEvent(QEvent *event, QObject *receiver, QPostEventLis \property QApplication::autoMaximizeThreshold \since 4.4 \brief defines a threshold for auto maximizing widgets - + \deprecated \b{The auto maximize threshold is only available as part of Qt for Windows CE.} @@ -1051,8 +1056,8 @@ bool QApplication::compressEvent(QEvent *event, QObject *receiver, QPostEventLis the WA_InputMethodEnabled attribute set, and is typically used to launch a virtual keyboard on devices which have very few or no keys. - \b{ The property only has an effect on platforms which use software input - panels, such as Windows CE.} + \b{ The property only has an effect on platforms that use software input + panels.} The default is platform dependent. */ @@ -1124,7 +1129,7 @@ QStyle *QApplication::style() // QString style; if (!QApplicationPrivate::styleOverride.isEmpty()) { - style = QApplicationPrivate::styleOverride; + style = QApplicationPrivate::styleOverride.toLower(); } else { style = QApplicationPrivate::desktopStyleKey(); } @@ -1132,9 +1137,9 @@ QStyle *QApplication::style() QStyle *&app_style = QApplicationPrivate::app_style; app_style = QStyleFactory::create(style); if (!app_style) { - QStringList styles = QStyleFactory::keys(); - for (int i = 0; i < styles.size(); ++i) { - if ((app_style = QStyleFactory::create(styles.at(i)))) + const QStringList styles = QStyleFactory::keys(); + for (const auto &style : styles) { + if ((app_style = QStyleFactory::create(style))) break; } } @@ -1375,7 +1380,7 @@ int QApplication::colorSpec() void QApplication::setColorSpec(int spec) { - if (qApp) + if (Q_UNLIKELY(qApp)) qWarning("QApplication::setColorSpec: This function must be " "called before the QApplication object is created"); QApplicationPrivate::app_cspec = spec; @@ -1717,9 +1722,11 @@ QString QApplicationPrivate::desktopStyleKey() // first valid one. if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) { const QStringList availableKeys = QStyleFactory::keys(); - foreach (const QString &style, theme->themeHint(QPlatformTheme::StyleNames).toStringList()) + const auto styles = theme->themeHint(QPlatformTheme::StyleNames).toStringList(); + for (const QString &style : styles) { if (availableKeys.contains(style, Qt::CaseInsensitive)) return style; + } } return QString(); } @@ -1749,8 +1756,7 @@ void QApplicationPrivate::notifyWindowIconChanged() QWindowList windowList = QGuiApplication::topLevelWindows(); // send to all top-level QWidgets - for (int i = 0; i < list.size(); ++i) { - QWidget *w = list.at(i); + for (auto *w : list) { windowList.removeOne(w->windowHandle()); QCoreApplication::sendEvent(w, &ev); } @@ -1912,9 +1918,9 @@ bool QApplicationPrivate::tryCloseAllWidgetWindows(QWindowList *processedWindows processedWindows->append(window); } - QWidgetList list = QApplication::topLevelWidgets(); - for (int i = 0; i < list.size(); ++i) { - QWidget *w = list.at(i); +retry: + const QWidgetList list = QApplication::topLevelWidgets(); + for (auto *w : list) { if (w->isVisible() && w->windowType() != Qt::Desktop && !w->testAttribute(Qt::WA_DontShowOnScreen) && !w->data->is_closing) { QWindow *window = w->windowHandle(); @@ -1922,8 +1928,7 @@ bool QApplicationPrivate::tryCloseAllWidgetWindows(QWindowList *processedWindows return false; if (window) processedWindows->append(window); - list = QApplication::topLevelWidgets(); - i = -1; + goto retry; } } return true; @@ -2002,9 +2007,8 @@ bool QApplication::event(QEvent *e) ce->accept(); closeAllWindows(); - QWidgetList list = topLevelWidgets(); - for (int i = 0; i < list.size(); ++i) { - QWidget *w = list.at(i); + const QWidgetList list = topLevelWidgets(); + for (auto *w : list) { if (w->isVisible() && !(w->windowType() == Qt::Desktop) && !(w->windowType() == Qt::Popup) && (!(w->windowType() == Qt::Dialog) || !w->parentWidget())) { ce->ignore(); @@ -2018,9 +2022,8 @@ bool QApplication::event(QEvent *e) } else if (e->type() == QEvent::LocaleChange) { // on Windows the event propagation is taken care by the // WM_SETTINGCHANGE event handler. - QWidgetList list = topLevelWidgets(); - for (int i = 0; i < list.size(); ++i) { - QWidget *w = list.at(i); + const QWidgetList list = topLevelWidgets(); + for (auto *w : list) { if (!(w->windowType() == Qt::Desktop)) { if (!w->testAttribute(Qt::WA_SetLocale)) w->d_func()->setLocale_helper(QLocale(), true); @@ -2064,9 +2067,8 @@ bool QApplication::event(QEvent *e) } if(e->type() == QEvent::LanguageChange) { - QWidgetList list = topLevelWidgets(); - for (int i = 0; i < list.size(); ++i) { - QWidget *w = list.at(i); + const QWidgetList list = topLevelWidgets(); + for (auto *w : list) { if (!(w->windowType() == Qt::Desktop)) postEvent(w, new QEvent(QEvent::LanguageChange)); } @@ -2092,8 +2094,7 @@ void QApplicationPrivate::notifyLayoutDirectionChange() QWindowList windowList = QGuiApplication::topLevelWindows(); // send to all top-level QWidgets - for (int i = 0; i < list.size(); ++i) { - QWidget *w = list.at(i); + for (auto *w : list) { windowList.removeAll(w->windowHandle()); QEvent ev(QEvent::ApplicationLayoutDirectionChange); QCoreApplication::sendEvent(w, &ev); @@ -2144,9 +2145,8 @@ void QApplication::setActiveWindow(QWidget* act) if (QApplicationPrivate::active_window) { if (style()->styleHint(QStyle::SH_Widget_ShareActivation, 0, QApplicationPrivate::active_window)) { - QWidgetList list = topLevelWidgets(); - for (int i = 0; i < list.size(); ++i) { - QWidget *w = list.at(i); + const QWidgetList list = topLevelWidgets(); + for (auto *w : list) { if (w->isVisible() && w->isActiveWindow()) toBeDeactivated.append(w); } @@ -2167,9 +2167,8 @@ void QApplication::setActiveWindow(QWidget* act) if (QApplicationPrivate::active_window) { if (style()->styleHint(QStyle::SH_Widget_ShareActivation, 0, QApplicationPrivate::active_window)) { - QWidgetList list = topLevelWidgets(); - for (int i = 0; i < list.size(); ++i) { - QWidget *w = list.at(i); + const QWidgetList list = topLevelWidgets(); + for (auto *w : list) { if (w->isVisible() && w->isActiveWindow()) toBeActivated.append(w); } @@ -2232,10 +2231,13 @@ QWidget *qt_tlw_for_window(QWindow *wnd) else break; } - if (wnd) - foreach (QWidget *tlw, qApp->topLevelWidgets()) + if (wnd) { + const auto tlws = qApp->topLevelWidgets(); + for (QWidget *tlw : tlws) { if (tlw->windowHandle() == wnd) return tlw; + } + } return 0; } @@ -2327,7 +2329,6 @@ void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave, con return; #endif - QWidget* w ; if ((!enter && !leave) || (enter == leave)) return; #ifdef ALIEN_DEBUG @@ -2338,25 +2339,25 @@ void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave, con bool sameWindow = leave && enter && leave->window() == enter->window(); if (leave && !sameWindow) { - w = leave; + auto *w = leave; do { leaveList.append(w); } while (!w->isWindow() && (w = w->parentWidget())); } if (enter && !sameWindow) { - w = enter; + auto *w = enter; do { - enterList.prepend(w); + enterList.append(w); } while (!w->isWindow() && (w = w->parentWidget())); } if (sameWindow) { int enterDepth = 0; int leaveDepth = 0; - w = enter; - while (!w->isWindow() && (w = w->parentWidget())) + auto *e = enter; + while (!e->isWindow() && (e = e->parentWidget())) enterDepth++; - w = leave; - while (!w->isWindow() && (w = w->parentWidget())) + auto *l = leave; + while (!l->isWindow() && (l = l->parentWidget())) leaveDepth++; QWidget* wenter = enter; QWidget* wleave = leave; @@ -2373,21 +2374,16 @@ void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave, con wleave = wleave->parentWidget(); } - w = leave; - while (w != wleave) { + for (auto *w = leave; w != wleave; w = w->parentWidget()) leaveList.append(w); - w = w->parentWidget(); - } - w = enter; - while (w != wenter) { - enterList.prepend(w); - w = w->parentWidget(); - } + + for (auto *w = enter; w != wenter; w = w->parentWidget()) + enterList.append(w); } QEvent leaveEvent(QEvent::Leave); for (int i = 0; i < leaveList.size(); ++i) { - w = leaveList.at(i); + auto *w = leaveList.at(i); if (!QApplication::activeModalWidget() || QApplicationPrivate::tryModalHelper(w, 0)) { QApplication::sendEvent(w, &leaveEvent); if (w->testAttribute(Qt::WA_Hover) && @@ -2404,9 +2400,9 @@ void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave, con const QPoint globalPos = qIsInf(globalPosF.x()) ? QPoint(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX) : globalPosF.toPoint(); - const QPoint windowPos = enterList.front()->window()->mapFromGlobal(globalPos); - for (int i = 0; i < enterList.size(); ++i) { - w = enterList.at(i); + const QPoint windowPos = qAsConst(enterList).back()->window()->mapFromGlobal(globalPos); + for (auto it = enterList.crbegin(), end = enterList.crend(); it != end; ++it) { + auto *w = *it; if (!QApplication::activeModalWidget() || QApplicationPrivate::tryModalHelper(w, 0)) { const QPointF localPos = w->mapFromGlobal(globalPos); QEnterEvent enterEvent(localPos, windowPos, globalPosF); @@ -2429,7 +2425,7 @@ void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave, con // This is not required on Windows as the cursor is reset on every single mouse move. QWidget *parentOfLeavingCursor = 0; for (int i = 0; i < leaveList.size(); ++i) { - w = leaveList.at(i); + auto *w = leaveList.at(i); if (!isAlien(w)) break; if (w->testAttribute(Qt::WA_SetCursor)) { @@ -2494,7 +2490,7 @@ bool QApplicationPrivate::isBlockedByModal(QWidget *widget) bool QApplicationPrivate::isWindowBlocked(QWindow *window, QWindow **blockingWindow) const { QWindow *unused = 0; - if (!window) { + if (Q_UNLIKELY(!window)) { qWarning().nospace() << "window == 0 passed."; return false; } @@ -3016,7 +3012,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e) if (QApplicationPrivate::is_app_closing) return true; - if (receiver == 0) { // serious error + if (Q_UNLIKELY(!receiver)) { // serious error qWarning("QApplication::notify: Unexpected null receiver"); return true; } @@ -3264,7 +3260,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e) QObject *obj = d->extraData->eventFilters.at(i); if (!obj) continue; - if (obj->d_func()->threadData != w->d_func()->threadData) { + if (Q_UNLIKELY(obj->d_func()->threadData != w->d_func()->threadData)) { qWarning("QApplication: Object event filter cannot be in a different thread."); continue; } @@ -3361,7 +3357,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e) QApplicationPrivate::giveFocusAccordingToFocusPolicy(w, e, relpos); QWheelEvent we(relpos, wheel->globalPos(), wheel->pixelDelta(), wheel->angleDelta(), wheel->delta(), wheel->orientation(), wheel->buttons(), - wheel->modifiers(), phase, wheel->source()); + wheel->modifiers(), phase, wheel->source(), wheel->inverted()); bool eventAccepted; while (w) { we.spont = spontaneous && w == receiver; @@ -3372,7 +3368,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e) // A new scrolling sequence or partial sequence starts and w has accepted // the event. Therefore, we can set wheel_widget, but only if it's not // the end of a sequence. - if (spontaneous && (phase == Qt::ScrollBegin || phase == Qt::ScrollUpdate) && QGuiApplicationPrivate::scrollNoPhaseAllowed) + if (spontaneous && (phase == Qt::ScrollBegin || phase == Qt::ScrollUpdate)) QApplicationPrivate::wheel_widget = w; break; } @@ -3461,7 +3457,6 @@ bool QApplication::notify(QObject *receiver, QEvent *e) w = w->parentWidget(); } tablet->setAccepted(eventAccepted); - qt_tabletChokeMouse = tablet->isAccepted(); } break; #endif // QT_NO_TABLETEVENT @@ -3893,7 +3888,7 @@ void QApplicationPrivate::closePopup(QWidget *popup) } else { // A popup was closed, so the previous popup gets the focus. - QWidget* aw = QApplicationPrivate::popupWidgets->last(); + QWidget* aw = QApplicationPrivate::popupWidgets->constLast(); if (QWidget *fw = aw->focusWidget()) fw->setFocus(Qt::PopupFocusReason); @@ -3932,12 +3927,7 @@ void QApplicationPrivate::openPopup(QWidget *popup) /*! Sets the kind of focus navigation Qt should use to \a mode. - This feature is available in Qt for Embedded Linux, and Windows CE - only. - - \note On Windows CE this feature is disabled by default for touch device - mkspecs. To enable keypad navigation, build Qt with - QT_KEYPAD_NAVIGATION defined. + This feature is available in Qt for Embedded Linux only. \since 4.6 @@ -3951,11 +3941,7 @@ void QApplication::setNavigationMode(Qt::NavigationMode mode) /*! Returns what kind of focus navigation Qt is using. - This feature is available in Qt for Embedded Linux, and Windows CE only. - - \note On Windows CE this feature is disabled by default for touch device - mkspecs. To enable keypad navigation, build Qt with - QT_KEYPAD_NAVIGATION defined. + This feature is available in Qt for Embedded Linux only. \since 4.6 @@ -4040,7 +4026,8 @@ void QApplication::alert(QWidget *widget, int duration) if (QWindow *window= QApplicationPrivate::windowForWidget(widget)) window->alert(duration); } else { - foreach (QWidget *topLevel, topLevelWidgets()) + const auto topLevels = topLevelWidgets(); + for (QWidget *topLevel : topLevels) QApplication::alert(topLevel, duration); } } @@ -4221,7 +4208,7 @@ bool QApplication::isEffectEnabled(Qt::UIEffect effect) */ void QApplication::beep() { - QMetaObject::invokeMethod(QGuiApplication::platformNativeInterface(), "beep"); + QGuiApplicationPrivate::platformIntegration()->beep(); } /*! |