diff options
author | Yann Bodson <yann.bodson@nokia.com> | 2009-07-14 00:06:15 (GMT) |
---|---|---|
committer | Damian Jansen <damian.jansen@nokia.com> | 2009-07-14 01:58:27 (GMT) |
commit | 3da921b6b33a12e8e665ee52536948ca9824b769 (patch) | |
tree | 375b3e2144918c59601a1630a52c63d5f212e676 /tools/qmlviewer | |
parent | aff53500dbfba0a3338f8ab649c754cce3569ede (diff) | |
download | Qt-3da921b6b33a12e8e665ee52536948ca9824b769.zip Qt-3da921b6b33a12e8e665ee52536948ca9824b769.tar.gz Qt-3da921b6b33a12e8e665ee52536948ca9824b769.tar.bz2 |
Add access to Qt palettes from QML.
Diffstat (limited to 'tools/qmlviewer')
-rw-r--r-- | tools/qmlviewer/qmlviewer.cpp | 25 | ||||
-rw-r--r-- | tools/qmlviewer/qmlviewer.h | 5 |
2 files changed, 30 insertions, 0 deletions
diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index db0dc18..b6ce619 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -17,6 +17,7 @@ #include "qmlviewer.h" #include <QtDeclarative/qmlcontext.h> #include <QtDeclarative/qmlengine.h> +#include "qmlpalette.h" #include "qml.h" #include <private/qperformancelog_p.h> #include "qfxtestengine.h" @@ -133,6 +134,8 @@ QmlViewer::QmlViewer(QFxTestEngine::TestMode testMode, const QString &testDir, Q devicemode = false; skin = 0; canvas = 0; + palette = 0; + disabledPalette = 0; record_autotime = 0; record_period = 20; @@ -383,6 +386,7 @@ void QmlViewer::openQml(const QString& fileName) } } + setupPalettes(); canvas->setUrl(url); QTime t; @@ -407,6 +411,18 @@ void QmlViewer::openQml(const QString& fileName) #endif } +void QmlViewer:: setupPalettes() +{ + delete palette; + palette = new QmlPalette; + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("activePalette", palette); + + delete disabledPalette; + disabledPalette = new QmlPalette; + disabledPalette->setColorGroup(QPalette::Disabled); + ctxt->setContextProperty("disabledPalette", disabledPalette); +} void QmlViewer::setSkin(const QString& skinDirectory) { @@ -486,6 +502,15 @@ void QmlViewer::setRecordFile(const QString& f) record_file = f; } +bool QmlViewer::event(QEvent *event) +{ + if (event->type() == QEvent::PaletteChange) { + setupPalette(); + 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 c533fe0..765d42f 100644 --- a/tools/qmlviewer/qmlviewer.h +++ b/tools/qmlviewer/qmlviewer.h @@ -25,6 +25,7 @@ QT_BEGIN_NAMESPACE class QFxView; class PreviewDeviceSkin; class QFxTestEngine; +class QmlPalette; class QProcess; class QmlViewer : public QWidget @@ -61,6 +62,7 @@ public slots: protected: virtual void keyPressEvent(QKeyEvent *); virtual void timerEvent(QTimerEvent *); + virtual bool event(QEvent *event); void createMenu(QMenuBar *menu, QMenu *flatmenu); @@ -70,11 +72,14 @@ private slots: private: void setupProxy(); + void setupPalettes(); QString currentFileName; PreviewDeviceSkin *skin; QSize skinscreensize; QFxView *canvas; + QmlPalette *palette; + QmlPalette *disabledPalette; void init(QFxTestEngine::TestMode, const QString &, const QString& fileName); QBasicTimer recordTimer; QList<QImage*> frames; |