diff options
Diffstat (limited to 'src/widgets/kernel/qapplication.cpp')
-rw-r--r-- | src/widgets/kernel/qapplication.cpp | 135 |
1 files changed, 66 insertions, 69 deletions
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index abd0231b00..78c842f7e1 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtWidgets module of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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 Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** 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. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** 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. ** ** $QT_END_LICENSE$ @@ -64,6 +64,7 @@ #include <QtWidgets/qgraphicsproxywidget.h> #include <QtGui/qstylehints.h> #include <QtGui/qinputmethod.h> +#include <QtGui/private/qwindow_p.h> #include <qpa/qplatformtheme.h> #ifndef QT_NO_WHATSTHIS #include <QtWidgets/QWhatsThis> @@ -116,6 +117,14 @@ static void initResources() QT_BEGIN_NAMESPACE +// Helper macro for static functions to check on the existence of the application class. +#define CHECK_QAPP_INSTANCE(...) \ + if (Q_LIKELY(QCoreApplication::instance())) { \ + } else { \ + qWarning("Must construct a QApplication first."); \ + return __VA_ARGS__; \ + } + Q_CORE_EXPORT void qt_call_post_routines(); QApplicationPrivate *QApplicationPrivate::self = 0; @@ -431,9 +440,7 @@ inline bool QApplicationPrivate::isAlien(QWidget *widget) bool Q_WIDGETS_EXPORT qt_tab_all_widgets() { - if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) - return theme->themeHint(QPlatformTheme::TabAllWidgets).toBool(); - return true; + return QGuiApplication::styleHints()->tabFocusBehavior() == Qt::TabFocusAllControls; } // ######## move to QApplicationPrivate @@ -629,6 +636,9 @@ void QApplicationPrivate::initialize() // needed for a static build. qRegisterWidgetsVariant(); + // needed for widgets in QML + QAbstractDeclarativeData::setWidgetParent = QWidgetPrivate::setWidgetParentHelper; + if (application_type != QApplicationPrivate::Tty) (void) QApplication::style(); // trigger creation of application style #ifndef QT_NO_STATEMACHINE @@ -636,7 +646,7 @@ void QApplicationPrivate::initialize() qRegisterGuiStateMachine(); #endif - if (qgetenv("QT_USE_NATIVE_WINDOWS").toInt() > 0) + if (qEnvironmentVariableIntValue("QT_USE_NATIVE_WINDOWS") > 0) QCoreApplication::setAttribute(Qt::AA_NativeWindows); #ifdef Q_OS_WINCE @@ -658,8 +668,12 @@ void QApplicationPrivate::initialize() initializeMultitouch(); if (QApplication::desktopSettingsAware()) - if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) + if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) { QApplicationPrivate::enabledAnimations = theme->themeHint(QPlatformTheme::UiEffects).toInt(); +#ifndef QT_NO_WHEELEVENT + QApplicationPrivate::wheel_scroll_lines = theme->themeHint(QPlatformTheme::WheelScrollLines).toInt(); +#endif + } is_app_running = true; // no longer starting up } @@ -821,7 +835,7 @@ QApplication::~QApplication() if (QWidgetPrivate::allWidgets) { QWidgetSet *mySet = QWidgetPrivate::allWidgets; QWidgetPrivate::allWidgets = 0; - for (QWidgetSet::ConstIterator it = mySet->constBegin(); it != mySet->constEnd(); ++it) { + for (QWidgetSet::ConstIterator it = mySet->constBegin(), cend = mySet->constEnd(); it != cend; ++it) { QWidget *w = *it; if (!w->parent()) // window w->destroy(true, true); @@ -1184,7 +1198,7 @@ void QApplication::setStyle(QStyle *style) // clean up the old style if (QApplicationPrivate::app_style) { if (QApplicationPrivate::is_app_running && !QApplicationPrivate::is_app_closing) { - for (QWidgetList::ConstIterator it = all.constBegin(); it != all.constEnd(); ++it) { + for (QWidgetList::ConstIterator it = all.constBegin(), cend = all.constEnd(); it != cend; ++it) { QWidget *w = *it; if (!(w->windowType() == Qt::Desktop) && // except desktop w->testAttribute(Qt::WA_WState_Polished)) { // has been polished @@ -1232,8 +1246,8 @@ void QApplication::setStyle(QStyle *style) // re-polish existing widgets if necessary if (QApplicationPrivate::is_app_running && !QApplicationPrivate::is_app_closing) { - for (QWidgetList::ConstIterator it1 = all.constBegin(); it1 != all.constEnd(); ++it1) { - QWidget *w = *it1; + for (QWidgetList::ConstIterator it = all.constBegin(), cend = all.constEnd(); it != cend; ++it) { + QWidget *w = *it; if (w->windowType() != Qt::Desktop && w->testAttribute(Qt::WA_WState_Polished)) { if (w->style() == QApplicationPrivate::app_style) QApplicationPrivate::app_style->polish(w); // repolish @@ -1244,8 +1258,8 @@ void QApplication::setStyle(QStyle *style) } } - for (QWidgetList::ConstIterator it2 = all.constBegin(); it2 != all.constEnd(); ++it2) { - QWidget *w = *it2; + for (QWidgetList::ConstIterator it = all.constBegin(), cend = all.constEnd(); it != cend; ++it) { + QWidget *w = *it; if (w->windowType() != Qt::Desktop && !w->testAttribute(Qt::WA_SetStyle)) { QEvent e(QEvent::StyleChange); QApplication::sendEvent(w, &e); @@ -1410,12 +1424,15 @@ void QApplication::setGlobalStrut(const QSize& strut) */ QPalette QApplication::palette(const QWidget* w) { + typedef PaletteHash::const_iterator PaletteHashConstIt; + PaletteHash *hash = app_palettes(); if (w && hash && hash->size()) { - QHash<QByteArray, QPalette>::ConstIterator it = hash->constFind(w->metaObject()->className()); - if (it != hash->constEnd()) + PaletteHashConstIt it = hash->constFind(w->metaObject()->className()); + const PaletteHashConstIt cend = hash->constEnd(); + if (it != cend) return *it; - for (it = hash->constBegin(); it != hash->constEnd(); ++it) { + for (it = hash->constBegin(); it != cend; ++it) { if (w->inherits(it.key())) return it.value(); } @@ -1474,7 +1491,7 @@ void QApplicationPrivate::setPalette_helper(const QPalette &palette, const char* QApplication::sendEvent(QApplication::instance(), &e); QWidgetList wids = QApplication::allWidgets(); - for (QWidgetList::ConstIterator it = wids.constBegin(); it != wids.constEnd(); ++it) { + for (QWidgetList::ConstIterator it = wids.constBegin(), cend = wids.constEnd(); it != cend; ++it) { QWidget *w = *it; if (all || (!className && w->isWindow()) || w->inherits(className)) // matching class QApplication::sendEvent(w, &e); @@ -1576,6 +1593,8 @@ QFont QApplication::font() QFont QApplication::font(const QWidget *widget) { + typedef FontHash::const_iterator FontHashConstIt; + FontHash *hash = app_fonts(); if (widget && hash && hash->size()) { @@ -1587,11 +1606,11 @@ QFont QApplication::font(const QWidget *widget) return hash->value(QByteArrayLiteral("QMiniFont")); } #endif - QHash<QByteArray, QFont>::ConstIterator it = - hash->constFind(widget->metaObject()->className()); - if (it != hash->constEnd()) + FontHashConstIt it = hash->constFind(widget->metaObject()->className()); + const FontHashConstIt cend = hash->constEnd(); + if (it != cend) return it.value(); - for (it = hash->constBegin(); it != hash->constEnd(); ++it) { + for (it = hash->constBegin(); it != cend; ++it) { if (widget->inherits(it.key())) return it.value(); } @@ -1656,7 +1675,7 @@ void QApplication::setFont(const QFont &font, const char *className) QApplication::sendEvent(QApplication::instance(), &e); QWidgetList wids = QApplication::allWidgets(); - for (QWidgetList::ConstIterator it = wids.constBegin(); it != wids.constEnd(); ++it) { + for (QWidgetList::ConstIterator it = wids.constBegin(), cend = wids.constEnd(); it != cend; ++it) { QWidget *w = *it; if (all || (!className && w->isWindow()) || w->inherits(className)) // matching class sendEvent(w, &e); @@ -1761,7 +1780,7 @@ QWidgetList QApplication::topLevelWidgets() QWidgetList list; QWidgetList all = allWidgets(); - for (QWidgetList::ConstIterator it = all.constBegin(); it != all.constEnd(); ++it) { + for (QWidgetList::ConstIterator it = all.constBegin(), cend = all.constEnd(); it != cend; ++it) { QWidget *w = *it; if (w->isWindow() && w->windowType() != Qt::Desktop) list.append(w); @@ -2140,7 +2159,7 @@ void QApplication::setActiveWindow(QWidget* act) if (QApplicationPrivate::focus_widget) { if (QApplicationPrivate::focus_widget->testAttribute(Qt::WA_InputMethodEnabled)) - qApp->inputMethod()->commit(); + QGuiApplication::inputMethod()->commit(); QFocusEvent focusAboutToChange(QEvent::FocusAboutToChange, Qt::ActiveWindowFocusReason); QApplication::sendEvent(QApplicationPrivate::focus_widget, &focusAboutToChange); @@ -2485,7 +2504,7 @@ bool QApplicationPrivate::isWindowBlocked(QWindow *window, QWindow **blockingWin } QWidget *popupWidget = QApplication::activePopupWidget(); QWindow *popupWindow = popupWidget ? popupWidget->windowHandle() : 0; - if (popupWindow == window) { + if (popupWindow == window || (!popupWindow && QWindowPrivate::get(window)->isPopup())) { *blockingWindow = 0; return false; } @@ -2844,6 +2863,7 @@ void QApplicationPrivate::sendSyntheticEnterLeave(QWidget *widget) */ QDesktopWidget *QApplication::desktop() { + CHECK_QAPP_INSTANCE(Q_NULLPTR) if (!qt_desktopWidget || // not created yet !(qt_desktopWidget->windowType() == Qt::Desktop)) { // reparented away qt_desktopWidget = new QDesktopWidget(); @@ -2881,7 +2901,7 @@ void QApplication::setStartDragTime(int ms) int QApplication::startDragTime() { - return qApp->styleHints()->startDragTime(); + return QGuiApplication::styleHints()->startDragTime(); } /* @@ -2919,7 +2939,7 @@ void QApplication::setStartDragDistance(int l) int QApplication::startDragDistance() { - return qApp->styleHints()->startDragDistance(); + return QGuiApplication::styleHints()->startDragDistance(); } /*! @@ -3122,39 +3142,15 @@ bool QApplication::notify(QObject *receiver, QEvent *e) } switch (e->type()) { - case QEvent::KeyPress: - { - bool isWidget = receiver->isWidgetType(); - bool isWindow = receiver->isWindowType(); - bool isGraphicsWidget = false; -#ifndef QT_NO_GRAPHICSVIEW - isGraphicsWidget = !isWidget && !isWindow && qobject_cast<QGraphicsWidget *>(receiver); -#endif - if (!isWidget && !isGraphicsWidget && !isWindow) { - return d->notify_helper(receiver, e); - } - - QKeyEvent* key = static_cast<QKeyEvent*>(e); -#ifndef QT_NO_SHORTCUT - // Try looking for a Shortcut before sending key events - QObject *shortcutReceiver = receiver; - if (!isWidget && isWindow) { - QWindow *w = qobject_cast<QWindow *>(receiver); - QObject *focus = w ? w->focusObject() : 0; - if (focus) - shortcutReceiver = focus; - } - if (qApp->d_func()->shortcutMap.tryShortcutEvent(shortcutReceiver, key)) - return true; -#endif - qt_in_tab_key_event = (key->key() == Qt::Key_Backtab - || key->key() == Qt::Key_Tab - || key->key() == Qt::Key_Left - || key->key() == Qt::Key_Up - || key->key() == Qt::Key_Right - || key->key() == Qt::Key_Down); - - } + case QEvent::KeyPress: { + int key = static_cast<QKeyEvent*>(e)->key(); + qt_in_tab_key_event = (key == Qt::Key_Backtab + || key == Qt::Key_Tab + || key == Qt::Key_Left + || key == Qt::Key_Up + || key == Qt::Key_Right + || key == Qt::Key_Down); + } default: break; } @@ -3334,7 +3330,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e) while (w) { QWheelEvent we(relpos, wheel->globalPos(), wheel->pixelDelta(), wheel->angleDelta(), wheel->delta(), wheel->orientation(), wheel->buttons(), - wheel->modifiers(), wheel->phase()); + wheel->modifiers(), wheel->phase(), wheel->source()); we.spont = wheel->spontaneous(); res = d->notify_helper(w, w == receiver ? wheel : &we); eventAccepted = ((w == receiver) ? wheel : &we)->isAccepted(); @@ -3986,7 +3982,7 @@ void QApplication::setCursorFlashTime(int msecs) int QApplication::cursorFlashTime() { - return qApp->styleHints()->cursorFlashTime(); + return QGuiApplication::styleHints()->cursorFlashTime(); } /*! @@ -4004,7 +4000,7 @@ void QApplication::setDoubleClickInterval(int ms) int QApplication::doubleClickInterval() { - return qApp->styleHints()->mouseDoubleClickInterval(); + return QGuiApplication::styleHints()->mouseDoubleClickInterval(); } /*! @@ -4032,7 +4028,7 @@ void QApplication::setKeyboardInputInterval(int ms) int QApplication::keyboardInputInterval() { - return qApp->styleHints()->keyboardInputInterval(); + return QGuiApplication::styleHints()->keyboardInputInterval(); } /*! @@ -4123,6 +4119,7 @@ void QApplication::setEffectEnabled(Qt::UIEffect effect, bool enable) */ bool QApplication::isEffectEnabled(Qt::UIEffect effect) { + CHECK_QAPP_INSTANCE(false) return QColormap::instance().depth() >= 16 && (QApplicationPrivate::enabledAnimations & QPlatformTheme::GeneralUiEffect) && (QApplicationPrivate::enabledAnimations & uiEffectToFlag(effect)); |