From 46fa45fd0f2a40580951903437a5fd1b6c5237ad Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 15 Jul 2009 15:43:35 +1000 Subject: Make QmlPalette properties notifiable. Handle palette changes in QmlPalette. --- src/declarative/util/qmlpalette.cpp | 25 +++++++++++++++++++++++++ src/declarative/util/qmlpalette.h | 31 +++++++++++++++++-------------- tools/qmlviewer/qmlviewer.cpp | 11 +---------- tools/qmlviewer/qmlviewer.h | 1 - 4 files changed, 43 insertions(+), 25 deletions(-) diff --git a/src/declarative/util/qmlpalette.cpp b/src/declarative/util/qmlpalette.cpp index 670966d..eda0ded 100644 --- a/src/declarative/util/qmlpalette.cpp +++ b/src/declarative/util/qmlpalette.cpp @@ -41,6 +41,7 @@ #include "private/qobject_p.h" #include "qmlpalette.h" +#include QT_BEGIN_NAMESPACE @@ -63,7 +64,9 @@ QmlPalette::QmlPalette(QObject *parent) : QObject(*(new QmlPalettePrivate), parent) { Q_D(QmlPalette); + d->palette = qApp->palette(); d->group = QPalette::Active; + qApp->installEventFilter(this); } QmlPalette::~QmlPalette() @@ -160,4 +163,26 @@ QPalette QmlPalette::palette() const return d->palette; } +bool QmlPalette::eventFilter(QObject *watched, QEvent *event) +{ + if (watched == qApp) { + if (event->type() == QEvent::ApplicationPaletteChange) { + QApplication::postEvent(this, new QEvent(QEvent::ApplicationPaletteChange)); + return false; + } + } + return QObject::eventFilter(watched, event); +} + +bool QmlPalette::event(QEvent *event) +{ + Q_D(QmlPalette); + if (event->type() == QEvent::ApplicationPaletteChange) { + d->palette = qApp->palette(); + emit paletteChanged(); + return true; + } + return QObject::event(event); +} + QT_END_NAMESPACE diff --git a/src/declarative/util/qmlpalette.h b/src/declarative/util/qmlpalette.h index f176764..1401ad1 100644 --- a/src/declarative/util/qmlpalette.h +++ b/src/declarative/util/qmlpalette.h @@ -62,19 +62,19 @@ public: QmlPalette(QObject *parent=0); ~QmlPalette(); - Q_PROPERTY(QColor window READ window CONSTANT) - Q_PROPERTY(QColor windowText READ windowText CONSTANT) - Q_PROPERTY(QColor base READ base CONSTANT) - Q_PROPERTY(QColor alternateBase READ alternateBase CONSTANT) - Q_PROPERTY(QColor button READ button CONSTANT) - Q_PROPERTY(QColor buttonText READ buttonText CONSTANT) - Q_PROPERTY(QColor light READ light CONSTANT) - Q_PROPERTY(QColor midlight READ midlight CONSTANT) - Q_PROPERTY(QColor dark READ dark CONSTANT) - Q_PROPERTY(QColor mid READ mid CONSTANT) - Q_PROPERTY(QColor shadow READ shadow CONSTANT) - Q_PROPERTY(QColor highlight READ highlight CONSTANT) - Q_PROPERTY(QColor highlightedText READ highlightedText CONSTANT) + Q_PROPERTY(QColor window READ window NOTIFY paletteChanged) + Q_PROPERTY(QColor windowText READ windowText NOTIFY paletteChanged) + Q_PROPERTY(QColor base READ base NOTIFY paletteChanged) + Q_PROPERTY(QColor alternateBase READ alternateBase NOTIFY paletteChanged) + Q_PROPERTY(QColor button READ button NOTIFY paletteChanged) + Q_PROPERTY(QColor buttonText READ buttonText NOTIFY paletteChanged) + Q_PROPERTY(QColor light READ light NOTIFY paletteChanged) + Q_PROPERTY(QColor midlight READ midlight NOTIFY paletteChanged) + Q_PROPERTY(QColor dark READ dark NOTIFY paletteChanged) + Q_PROPERTY(QColor mid READ mid NOTIFY paletteChanged) + Q_PROPERTY(QColor shadow READ shadow NOTIFY paletteChanged) + Q_PROPERTY(QColor highlight READ highlight NOTIFY paletteChanged) + Q_PROPERTY(QColor highlightedText READ highlightedText NOTIFY paletteChanged) QColor window() const; QColor windowText() const; @@ -98,8 +98,11 @@ public: void setColorGroup(QPalette::ColorGroup); + bool virtual eventFilter(QObject *watched, QEvent *event); + bool virtual event(QEvent *event); + Q_SIGNALS: - void updated(); + void paletteChanged(); }; QT_END_NAMESPACE diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index 6de1b97..677c08b 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -194,7 +194,7 @@ void QmlViewer::createMenu(QMenuBar *menu, QMenu *flatmenu) QAction *snapshotAction = new QAction(tr("&Take Snapsot\tF3"), parent); connect(snapshotAction, SIGNAL(triggered()), this, SLOT(takeSnapShot())); recordMenu->addAction(snapshotAction); - + recordAction = new QAction(tr("Start Recording &Video\tF2"), parent); connect(recordAction, SIGNAL(triggered()), this, SLOT(toggleRecordingWithSelection())); recordMenu->addAction(recordAction); @@ -502,15 +502,6 @@ void QmlViewer::setRecordFile(const QString& f) record_file = f; } -bool QmlViewer::event(QEvent *event) -{ - if (event->type() == QEvent::PaletteChange) { - setupPalettes(); - return true; - } - return QWidget::event(event); -} - void QmlViewer::setRecordPeriod(int ms) { record_period = ms; diff --git a/tools/qmlviewer/qmlviewer.h b/tools/qmlviewer/qmlviewer.h index 765d42f..11316c9 100644 --- a/tools/qmlviewer/qmlviewer.h +++ b/tools/qmlviewer/qmlviewer.h @@ -62,7 +62,6 @@ public slots: protected: virtual void keyPressEvent(QKeyEvent *); virtual void timerEvent(QTimerEvent *); - virtual bool event(QEvent *event); void createMenu(QMenuBar *menu, QMenu *flatmenu); -- cgit v0.12