summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qguiapplication.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/kernel/qguiapplication.cpp')
-rw-r--r--src/gui/kernel/qguiapplication.cpp253
1 files changed, 149 insertions, 104 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index f1d90f9caa..469563c415 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -141,7 +141,7 @@ Qt::KeyboardModifiers QGuiApplicationPrivate::modifier_buttons = Qt::NoModifier;
QPointF QGuiApplicationPrivate::lastCursorPosition(qInf(), qInf());
-QWindow *QGuiApplicationPrivate::currentMouseWindow = 0;
+QWindow *QGuiApplicationPrivate::currentMouseWindow = nullptr;
QString QGuiApplicationPrivate::styleOverride;
@@ -161,8 +161,8 @@ QPointer<QWindow> QGuiApplicationPrivate::currentDragWindow;
QVector<QGuiApplicationPrivate::TabletPointData> QGuiApplicationPrivate::tabletDevicePoints;
-QPlatformIntegration *QGuiApplicationPrivate::platform_integration = 0;
-QPlatformTheme *QGuiApplicationPrivate::platform_theme = 0;
+QPlatformIntegration *QGuiApplicationPrivate::platform_integration = nullptr;
+QPlatformTheme *QGuiApplicationPrivate::platform_theme = nullptr;
QList<QObject *> QGuiApplicationPrivate::generic_plugin_list;
@@ -177,13 +177,13 @@ enum ApplicationResourceFlags
static unsigned applicationResourceFlags = 0;
-QIcon *QGuiApplicationPrivate::app_icon = 0;
+QIcon *QGuiApplicationPrivate::app_icon = nullptr;
-QString *QGuiApplicationPrivate::platform_name = 0;
-QString *QGuiApplicationPrivate::displayName = 0;
-QString *QGuiApplicationPrivate::desktopFileName = 0;
+QString *QGuiApplicationPrivate::platform_name = nullptr;
+QString *QGuiApplicationPrivate::displayName = nullptr;
+QString *QGuiApplicationPrivate::desktopFileName = nullptr;
-QPalette *QGuiApplicationPrivate::app_pal = 0; // default application palette
+QPalette *QGuiApplicationPrivate::app_pal = nullptr; // default application palette
ulong QGuiApplicationPrivate::mousePressTime = 0;
Qt::MouseButton QGuiApplicationPrivate::mousePressButton = Qt::NoButton;
@@ -193,30 +193,30 @@ int QGuiApplicationPrivate::mousePressY = 0;
static int mouseDoubleClickDistance = -1;
static int touchDoubleTapDistance = -1;
-QWindow *QGuiApplicationPrivate::currentMousePressWindow = 0;
+QWindow *QGuiApplicationPrivate::currentMousePressWindow = nullptr;
static Qt::LayoutDirection layout_direction = Qt::LayoutDirectionAuto;
static bool force_reverse = false;
-QGuiApplicationPrivate *QGuiApplicationPrivate::self = 0;
-QTouchDevice *QGuiApplicationPrivate::m_fakeTouchDevice = 0;
+QGuiApplicationPrivate *QGuiApplicationPrivate::self = nullptr;
+QTouchDevice *QGuiApplicationPrivate::m_fakeTouchDevice = nullptr;
int QGuiApplicationPrivate::m_fakeMouseSourcePointId = 0;
#ifndef QT_NO_CLIPBOARD
-QClipboard *QGuiApplicationPrivate::qt_clipboard = 0;
+QClipboard *QGuiApplicationPrivate::qt_clipboard = nullptr;
#endif
QList<QScreen *> QGuiApplicationPrivate::screen_list;
QWindowList QGuiApplicationPrivate::window_list;
-QWindow *QGuiApplicationPrivate::focus_window = 0;
+QWindow *QGuiApplicationPrivate::focus_window = nullptr;
static QBasicMutex applicationFontMutex;
-QFont *QGuiApplicationPrivate::app_font = 0;
+QFont *QGuiApplicationPrivate::app_font = nullptr;
QStyleHints *QGuiApplicationPrivate::styleHints = nullptr;
bool QGuiApplicationPrivate::obey_desktop_settings = true;
-QInputDeviceManager *QGuiApplicationPrivate::m_inputDeviceManager = 0;
+QInputDeviceManager *QGuiApplicationPrivate::m_inputDeviceManager = nullptr;
qreal QGuiApplicationPrivate::m_maxDevicePixelRatio = 0.0;
@@ -236,21 +236,6 @@ static bool qt_detectRTLLanguage()
" and Arabic) to get proper widget layout.") == QLatin1String("RTL"));
}
-static void initPalette()
-{
- if (!QGuiApplicationPrivate::app_pal)
- if (const QPalette *themePalette = QGuiApplicationPrivate::platformTheme()->palette())
- QGuiApplicationPrivate::app_pal = new QPalette(*themePalette);
- if (!QGuiApplicationPrivate::app_pal)
- QGuiApplicationPrivate::app_pal = new QPalette(Qt::gray);
-}
-
-static inline void clearPalette()
-{
- delete QGuiApplicationPrivate::app_pal;
- QGuiApplicationPrivate::app_pal = 0;
-}
-
static void initFontUnlocked()
{
if (!QGuiApplicationPrivate::app_font) {
@@ -266,7 +251,7 @@ static void initFontUnlocked()
static inline void clearFontUnlocked()
{
delete QGuiApplicationPrivate::app_font;
- QGuiApplicationPrivate::app_font = 0;
+ QGuiApplicationPrivate::app_font = nullptr;
}
static void initThemeHints()
@@ -607,6 +592,21 @@ static QWindowGeometrySpecification windowGeometrySpecification = Q_WINDOW_GEOME
\list
\li \c {altgr}, detect the key \c {AltGr} found on some keyboards as
Qt::GroupSwitchModifier (since Qt 5.12).
+ \li \c {darkmode=[1|2]} controls how Qt responds to the activation
+ of the \e{Dark Mode for applications} introduced in Windows 10
+ 1903 (since Qt 5.15).
+
+ A value of 1 causes Qt to switch the window borders to black
+ when \e{Dark Mode for applications} is activated and no High
+ Contrast Theme is in use. This is intended for applications
+ that implement their own theming.
+
+ A value of 2 will in addition cause the Windows Vista style to
+ be deactivated and switch to the Windows style using a
+ simplified palette in dark mode. This is currently
+ experimental pending the introduction of new style that
+ properly adapts to dark mode.
+
\li \c {dialogs=[xp|none]}, \c xp uses XP-style native dialogs and
\c none disables them.
@@ -679,19 +679,19 @@ QGuiApplication::~QGuiApplication()
Q_D(QGuiApplication);
d->eventDispatcher->closingDown();
- d->eventDispatcher = 0;
+ d->eventDispatcher = nullptr;
#ifndef QT_NO_CLIPBOARD
delete QGuiApplicationPrivate::qt_clipboard;
- QGuiApplicationPrivate::qt_clipboard = 0;
+ QGuiApplicationPrivate::qt_clipboard = nullptr;
#endif
#ifndef QT_NO_SESSIONMANAGER
delete d->session_manager;
- d->session_manager = 0;
+ d->session_manager = nullptr;
#endif //QT_NO_SESSIONMANAGER
- clearPalette();
+ QGuiApplicationPrivate::clearPalette();
QFontDatabase::removeAllApplicationFonts();
#ifndef QT_NO_CURSOR
@@ -699,15 +699,15 @@ QGuiApplication::~QGuiApplication()
#endif
delete QGuiApplicationPrivate::app_icon;
- QGuiApplicationPrivate::app_icon = 0;
+ QGuiApplicationPrivate::app_icon = nullptr;
delete QGuiApplicationPrivate::platform_name;
- QGuiApplicationPrivate::platform_name = 0;
+ QGuiApplicationPrivate::platform_name = nullptr;
delete QGuiApplicationPrivate::displayName;
- QGuiApplicationPrivate::displayName = 0;
+ QGuiApplicationPrivate::displayName = nullptr;
delete QGuiApplicationPrivate::m_inputDeviceManager;
- QGuiApplicationPrivate::m_inputDeviceManager = 0;
+ QGuiApplicationPrivate::m_inputDeviceManager = nullptr;
delete QGuiApplicationPrivate::desktopFileName;
- QGuiApplicationPrivate::desktopFileName = 0;
+ QGuiApplicationPrivate::desktopFileName = nullptr;
QGuiApplicationPrivate::mouse_buttons = Qt::NoButton;
QGuiApplicationPrivate::modifier_buttons = Qt::NoModifier;
QGuiApplicationPrivate::lastCursorPosition = {qInf(), qInf()};
@@ -725,7 +725,7 @@ QGuiApplication::~QGuiApplication()
QGuiApplicationPrivate::QGuiApplicationPrivate(int &argc, char **argv, int flags)
: QCoreApplicationPrivate(argc, argv, flags),
- inputMethod(0),
+ inputMethod(nullptr),
lastTouchType(QEvent::TouchEnd),
ownGlobalShareContext(false)
{
@@ -818,7 +818,7 @@ QWindow *QGuiApplication::modalWindow()
{
CHECK_QAPP_INSTANCE(nullptr)
if (QGuiApplicationPrivate::self->modalWindowList.isEmpty())
- return 0;
+ return nullptr;
return QGuiApplicationPrivate::self->modalWindowList.first();
}
@@ -865,7 +865,7 @@ void QGuiApplicationPrivate::showModalWindow(QWindow *modal)
self->modalWindowList.removeFirst();
QEvent e(QEvent::Leave);
QGuiApplication::sendEvent(currentMouseWindow, &e);
- currentMouseWindow = 0;
+ currentMouseWindow = nullptr;
self->modalWindowList.prepend(modal);
}
}
@@ -895,12 +895,12 @@ void QGuiApplicationPrivate::hideModalWindow(QWindow *window)
*/
bool QGuiApplicationPrivate::isWindowBlocked(QWindow *window, QWindow **blockingWindow) const
{
- QWindow *unused = 0;
+ QWindow *unused = nullptr;
if (!blockingWindow)
blockingWindow = &unused;
if (modalWindowList.isEmpty()) {
- *blockingWindow = 0;
+ *blockingWindow = nullptr;
return false;
}
@@ -910,7 +910,7 @@ bool QGuiApplicationPrivate::isWindowBlocked(QWindow *window, QWindow **blocking
// A window is not blocked by another modal window if the two are
// the same, or if the window is a child of the modal window.
if (window == modalWindow || modalWindow->isAncestorOf(window, QWindow::IncludeTransients)) {
- *blockingWindow = 0;
+ *blockingWindow = nullptr;
return false;
}
@@ -951,7 +951,7 @@ bool QGuiApplicationPrivate::isWindowBlocked(QWindow *window, QWindow **blocking
break;
}
}
- *blockingWindow = 0;
+ *blockingWindow = nullptr;
return false;
}
@@ -990,7 +990,7 @@ QObject *QGuiApplication::focusObject()
{
if (focusWindow())
return focusWindow()->focusObject();
- return 0;
+ return nullptr;
}
/*!
@@ -1043,7 +1043,7 @@ QWindowList QGuiApplication::topLevelWindows()
QScreen *QGuiApplication::primaryScreen()
{
if (QGuiApplicationPrivate::screen_list.isEmpty())
- return 0;
+ return nullptr;
return QGuiApplicationPrivate::screen_list.at(0);
}
@@ -1061,7 +1061,9 @@ QList<QScreen *> QGuiApplication::screens()
The \a point is in relation to the virtualGeometry() of each set of virtual
siblings. If the point maps to more than one set of virtual siblings the first
- match is returned.
+ match is returned. If you wish to search only the virtual desktop siblings
+ of a known screen (for example siblings of the screen of your application
+ window \c QWidget::windowHandle()->screen()), use QScreen::virtualSiblingAt().
\since 5.10
*/
@@ -1469,7 +1471,7 @@ void QGuiApplicationPrivate::createPlatformIntegration()
}
if (j < argc) {
- argv[j] = 0;
+ argv[j] = nullptr;
argc = j;
}
@@ -1489,7 +1491,7 @@ void QGuiApplicationPrivate::createEventDispatcher()
{
Q_ASSERT(!eventDispatcher);
- if (platform_integration == 0)
+ if (platform_integration == nullptr)
createPlatformIntegration();
// The platform integration should not mess with the event dispatcher
@@ -1500,7 +1502,7 @@ void QGuiApplicationPrivate::createEventDispatcher()
void QGuiApplicationPrivate::eventDispatcherReady()
{
- if (platform_integration == 0)
+ if (platform_integration == nullptr)
createPlatformIntegration();
platform_integration->initialize();
@@ -1597,7 +1599,7 @@ void QGuiApplicationPrivate::init()
}
if (j < argc) {
- argv[j] = 0;
+ argv[j] = nullptr;
argc = j;
}
@@ -1606,10 +1608,10 @@ void QGuiApplicationPrivate::init()
if (!envPlugins.isEmpty())
pluginList += envPlugins.split(',');
- if (platform_integration == 0)
+ if (platform_integration == nullptr)
createPlatformIntegration();
- initPalette();
+ updatePalette();
QFont::initialize();
initThemeHints();
@@ -1712,19 +1714,21 @@ QGuiApplicationPrivate::~QGuiApplicationPrivate()
#ifndef QT_NO_OPENGL
if (ownGlobalShareContext) {
delete qt_gl_global_share_context();
- qt_gl_set_global_share_context(0);
+ qt_gl_set_global_share_context(nullptr);
}
#endif
platform_integration->destroy();
delete platform_theme;
- platform_theme = 0;
+ platform_theme = nullptr;
delete platform_integration;
- platform_integration = 0;
+ platform_integration = nullptr;
window_list.clear();
screen_list.clear();
+
+ self = nullptr;
}
#if 0
@@ -1782,7 +1786,7 @@ Qt::KeyboardModifiers QGuiApplication::keyboardModifiers()
*/
Qt::KeyboardModifiers QGuiApplication::queryKeyboardModifiers()
{
- CHECK_QAPP_INSTANCE(Qt::KeyboardModifiers(0))
+ CHECK_QAPP_INSTANCE(Qt::KeyboardModifiers{})
QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
return pi->queryKeyboardModifiers();
}
@@ -1812,7 +1816,7 @@ Qt::MouseButtons QGuiApplication::mouseButtons()
QPlatformNativeInterface *QGuiApplication::platformNativeInterface()
{
QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
- return pi ? pi->nativeInterface() : 0;
+ return pi ? pi->nativeInterface() : nullptr;
}
/*!
@@ -1878,6 +1882,10 @@ bool QGuiApplication::event(QEvent *e)
{
if(e->type() == QEvent::LanguageChange) {
setLayoutDirection(qt_detectRTLLanguage()?Qt::RightToLeft:Qt::LeftToRight);
+ for (auto *topLevelWindow : QGuiApplication::topLevelWindows()) {
+ if (topLevelWindow->flags() != Qt::Desktop)
+ postEvent(topLevelWindow, new QEvent(QEvent::LanguageChange));
+ }
} else if (e->type() == QEvent::Quit) {
// Close open windows. This is done in order to deliver de-expose
// events while the event loop is still running.
@@ -2163,7 +2171,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
window = currentMousePressWindow;
} else if (currentMousePressWindow) {
window = currentMousePressWindow;
- currentMousePressWindow = 0;
+ currentMousePressWindow = nullptr;
}
QPointF delta = globalPoint - globalPoint.toPoint();
localPoint = window->mapFromGlobal(globalPoint.toPoint()) + delta;
@@ -2376,7 +2384,7 @@ void QGuiApplicationPrivate::processLeaveEvent(QWindowSystemInterfacePrivate::Le
return;
}
- currentMouseWindow = 0;
+ currentMouseWindow = nullptr;
QEvent event(QEvent::Leave);
QCoreApplication::sendSpontaneousEvent(e->leave.data(), &event);
@@ -2395,7 +2403,7 @@ void QGuiApplicationPrivate::processActivatedEvent(QWindowSystemInterfacePrivate
if (platformWindow->isAlertState())
platformWindow->setAlertState(false);
- QObject *previousFocusObject = previous ? previous->focusObject() : 0;
+ QObject *previousFocusObject = previous ? previous->focusObject() : nullptr;
if (previous) {
QFocusEvent focusAboutToChange(QEvent::FocusAboutToChange);
@@ -2464,7 +2472,7 @@ void QGuiApplicationPrivate::processWindowScreenChangedEvent(QWindowSystemInterf
if (QScreen *screen = wse->screen.data())
topLevelWindow->d_func()->setTopLevelScreen(screen, false /* recreate */);
else // Fall back to default behavior, and try to find some appropriate screen
- topLevelWindow->setScreen(0);
+ topLevelWindow->setScreen(nullptr);
}
// we may have changed scaling, so trigger resize event if needed
if (window->handle()) {
@@ -2890,7 +2898,7 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
break;
}
- Q_ASSERT(w.data() != 0);
+ Q_ASSERT(w.data() != nullptr);
// make the *scene* functions return the same as the *screen* functions
// Note: touchPoint is a reference to the one from activeTouchPoints,
@@ -3266,12 +3274,12 @@ QPlatformDropQtResponse QGuiApplicationPrivate::processDrop(QWindow *w, const QM
*/
QClipboard * QGuiApplication::clipboard()
{
- if (QGuiApplicationPrivate::qt_clipboard == 0) {
+ if (QGuiApplicationPrivate::qt_clipboard == nullptr) {
if (!qApp) {
qWarning("QGuiApplication: Must construct a QGuiApplication before accessing a QClipboard");
- return 0;
+ return nullptr;
}
- QGuiApplicationPrivate::qt_clipboard = new QClipboard(0);
+ QGuiApplicationPrivate::qt_clipboard = new QClipboard(nullptr);
}
return QGuiApplicationPrivate::qt_clipboard;
}
@@ -3287,46 +3295,97 @@ QClipboard * QGuiApplication::clipboard()
*/
/*!
- Returns the default application palette.
+ Returns the current application palette.
+
+ Roles that have not been explicitly set will reflect the system's platform theme.
\sa setPalette()
*/
QPalette QGuiApplication::palette()
{
- initPalette();
+ if (!QGuiApplicationPrivate::app_pal)
+ QGuiApplicationPrivate::updatePalette();
+
return *QGuiApplicationPrivate::app_pal;
}
+void QGuiApplicationPrivate::updatePalette()
+{
+ if (app_pal) {
+ if (setPalette(*app_pal) && qGuiApp)
+ qGuiApp->d_func()->handlePaletteChanged();
+ } else {
+ setPalette(QPalette());
+ }
+}
+
+void QGuiApplicationPrivate::clearPalette()
+{
+ delete app_pal;
+ app_pal = nullptr;
+}
+
/*!
- Changes the default application palette to \a pal.
+ Changes the application palette to \a pal.
+
+ The color roles from this palette are combined with the system's platform
+ theme to form the application's final palette.
\sa palette()
*/
void QGuiApplication::setPalette(const QPalette &pal)
{
- if (!QGuiApplicationPrivate::setPalette(pal))
- return;
-
- QCoreApplication::setAttribute(Qt::AA_SetPalette);
-
- if (qGuiApp)
- qGuiApp->d_func()->sendApplicationPaletteChange();
+ if (QGuiApplicationPrivate::setPalette(pal) && qGuiApp)
+ qGuiApp->d_func()->handlePaletteChanged();
}
bool QGuiApplicationPrivate::setPalette(const QPalette &palette)
{
- if (app_pal && palette.isCopyOf(*app_pal))
+ // Resolve the palette against the theme palette, filling in
+ // any missing roles, while keeping the original resolve mask.
+ QPalette basePalette = qGuiApp ? qGuiApp->d_func()->basePalette() : Qt::gray;
+ basePalette.resolve(0); // The base palette only contributes missing colors roles
+ QPalette resolvedPalette = palette.resolve(basePalette);
+
+ if (app_pal && resolvedPalette == *app_pal && resolvedPalette.resolve() == app_pal->resolve())
return false;
if (!app_pal)
- app_pal = new QPalette(palette);
+ app_pal = new QPalette(resolvedPalette);
else
- *app_pal = palette;
+ *app_pal = resolvedPalette;
+
+ QCoreApplication::setAttribute(Qt::AA_SetPalette, app_pal->resolve() != 0);
return true;
}
+/*
+ Returns the base palette used to fill in missing roles in
+ the current application palette.
+
+ Normally this is the theme palette, but QApplication
+ overrides this for compatibility reasons.
+*/
+QPalette QGuiApplicationPrivate::basePalette() const
+{
+ return platformTheme() ? *platformTheme()->palette() : Qt::gray;
+}
+
+void QGuiApplicationPrivate::handlePaletteChanged(const char *className)
+{
+ if (!className) {
+ Q_ASSERT(app_pal);
+ emit qGuiApp->paletteChanged(*QGuiApplicationPrivate::app_pal);
+ }
+
+ if (is_app_running && !is_app_closing) {
+ QEvent event(QEvent::ApplicationPaletteChange);
+ QGuiApplication::sendEvent(qGuiApp, &event);
+ }
+}
+
void QGuiApplicationPrivate::applyWindowGeometrySpecificationTo(QWindow *window)
{
windowGeometrySpecification.applyTo(window);
@@ -3348,8 +3407,11 @@ void QGuiApplicationPrivate::applyWindowGeometrySpecificationTo(QWindow *window)
*/
QFont QGuiApplication::font()
{
- Q_ASSERT_X(QGuiApplicationPrivate::self, "QGuiApplication::font()", "no QGuiApplication instance");
const auto locker = qt_scoped_lock(applicationFontMutex);
+ if (!QGuiApplicationPrivate::self && !QGuiApplicationPrivate::app_font) {
+ qWarning("QGuiApplication::font(): no QGuiApplication instance and no application font set.");
+ return QFont(); // in effect: QFont((QFontPrivate*)nullptr), so no recursion
+ }
initFontUnlocked();
return *QGuiApplicationPrivate::app_font;
}
@@ -3902,7 +3964,7 @@ Qt::LayoutDirection QGuiApplication::layoutDirection()
QCursor *QGuiApplication::overrideCursor()
{
CHECK_QAPP_INSTANCE(nullptr)
- return qGuiApp->d_func()->cursor_list.isEmpty() ? 0 : &qGuiApp->d_func()->cursor_list.first();
+ return qGuiApp->d_func()->cursor_list.isEmpty() ? nullptr : &qGuiApp->d_func()->cursor_list.first();
}
/*!
@@ -3936,7 +3998,7 @@ static inline void unsetCursor(QWindow *w)
{
if (const QScreen *screen = w->screen())
if (QPlatformCursor *cursor = screen->handle()->cursor())
- cursor->changeCursor(0, w);
+ cursor->changeCursor(nullptr, w);
}
static inline void applyCursor(const QList<QWindow *> &l, const QCursor &c)
@@ -4125,11 +4187,8 @@ QPixmap QGuiApplicationPrivate::getPixmapCursor(Qt::CursorShape cshape)
void QGuiApplicationPrivate::notifyThemeChanged()
{
- if (!testAttribute(Qt::AA_SetPalette)) {
- clearPalette();
- initPalette();
- sendApplicationPaletteChange();
- }
+ updatePalette();
+
if (!(applicationResourceFlags & ApplicationFontExplicitlySet)) {
const auto locker = qt_scoped_lock(applicationFontMutex);
clearFontUnlocked();
@@ -4138,20 +4197,6 @@ void QGuiApplicationPrivate::notifyThemeChanged()
initThemeHints();
}
-void QGuiApplicationPrivate::sendApplicationPaletteChange(bool toAllWidgets, const char *className)
-{
- Q_UNUSED(toAllWidgets)
-
- if (!className)
- emit qGuiApp->paletteChanged(*QGuiApplicationPrivate::app_pal);
-
- if (!is_app_running || is_app_closing)
- return;
-
- QEvent event(QEvent::ApplicationPaletteChange);
- QGuiApplication::sendEvent(QGuiApplication::instance(), &event);
-}
-
#if QT_CONFIG(draganddrop)
void QGuiApplicationPrivate::notifyDragStarted(const QDrag *drag)
{