From 82d906a20d3769425dec6a3c618262de9bbaee45 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 20 Jun 2014 10:55:18 +0200 Subject: [PATCH] QGuiApplication::paletteChanged(const QPalette &palette) [signal] This allows QQuickSystemPalette to listen to palette changes without installing an expensive event filter on the application object. Change-Id: I8b693e047d993c444e393d7a714a5709692c3560 Reviewed-by: Shawn Rutledge Reviewed-by: Robin Burchell --- src/gui/kernel/qguiapplication.cpp | 10 +++++++ src/gui/kernel/qguiapplication.h | 1 + .../qguiapplication/tst_qguiapplication.cpp | 27 +++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 6ac84c6cab..87c95e6420 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -2652,6 +2652,15 @@ QClipboard * QGuiApplication::clipboard() } #endif +/*! + \since 5.4 + \fn void QGuiApplication::paletteChanged(const QPalette &palette) + + This signal is emitted when the \a palette of the application changes. + + \sa palette() +*/ + /*! Returns the default application palette. @@ -2678,6 +2687,7 @@ void QGuiApplication::setPalette(const QPalette &pal) else *QGuiApplicationPrivate::app_pal = pal; applicationResourceFlags |= ApplicationPaletteExplicitlySet; + emit qGuiApp->paletteChanged(*QGuiApplicationPrivate::app_pal); } QRect QGuiApplicationPrivate::applyWindowGeometrySpecification(const QRect &windowGeometry, const QWindow *window) diff --git a/src/gui/kernel/qguiapplication.h b/src/gui/kernel/qguiapplication.h index 560b2c827d..1b1e1dabff 100644 --- a/src/gui/kernel/qguiapplication.h +++ b/src/gui/kernel/qguiapplication.h @@ -174,6 +174,7 @@ Q_SIGNALS: void commitDataRequest(QSessionManager &sessionManager); void saveStateRequest(QSessionManager &sessionManager); #endif + void paletteChanged(const QPalette &pal); protected: bool event(QEvent *); diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp index 54b6fc6c44..9a6b9f488b 100644 --- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp +++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -72,6 +73,7 @@ private slots: void abortQuitOnShow(); void changeFocusWindow(); void keyboardModifiers(); + void palette(); void modalWindow(); void quitOnLastWindowClosed(); void genericPluginsAndWindowSystemEvents(); @@ -434,6 +436,31 @@ void tst_QGuiApplication::keyboardModifiers() window->close(); } +void tst_QGuiApplication::palette() +{ + int argc = 1; + char *argv[] = { const_cast("tst_qguiapplication") }; + QGuiApplication app(argc, argv); + QSignalSpy signalSpy(&app, SIGNAL(paletteChanged(QPalette))); + + QPalette oldPalette = QGuiApplication::palette(); + QPalette newPalette = QPalette(Qt::red); + + QGuiApplication::setPalette(newPalette); + QCOMPARE(QGuiApplication::palette(), newPalette); + QCOMPARE(signalSpy.count(), 1); + QCOMPARE(signalSpy.at(0).at(0), QVariant(newPalette)); + + QGuiApplication::setPalette(oldPalette); + QCOMPARE(QGuiApplication::palette(), oldPalette); + QCOMPARE(signalSpy.count(), 2); + QCOMPARE(signalSpy.at(1).at(0), QVariant(oldPalette)); + + QGuiApplication::setPalette(oldPalette); + QCOMPARE(QGuiApplication::palette(), oldPalette); + QCOMPARE(signalSpy.count(), 2); +} + class BlockableWindow : public QWindow { Q_OBJECT