winrt: Introduce theme palette
Use the colors returned by WinRT's UISettings class to construct the system palette. Change-Id: Id0d99c7b2e3df209de0755ee72a0d2bda67fda8c Reviewed-by: Maurice Kalinowski <maurice.kalinowski@digia.com> Reviewed-by: Jochen Seemann <seemann.jochen@gmail.com>
This commit is contained in:
parent
bb5b25e40d
commit
fff0844735
@ -43,10 +43,13 @@
|
|||||||
#include "qwinrtplatformmessagedialoghelper.h"
|
#include "qwinrtplatformmessagedialoghelper.h"
|
||||||
|
|
||||||
#include <QtCore/qfunctions_winrt.h>
|
#include <QtCore/qfunctions_winrt.h>
|
||||||
|
#include <QtGui/QPalette>
|
||||||
|
|
||||||
#include <wrl.h>
|
#include <wrl.h>
|
||||||
|
#include <windows.ui.h>
|
||||||
#include <windows.ui.viewmanagement.h>
|
#include <windows.ui.viewmanagement.h>
|
||||||
using namespace Microsoft::WRL;
|
using namespace Microsoft::WRL;
|
||||||
|
using namespace ABI::Windows::UI;
|
||||||
using namespace ABI::Windows::UI::ViewManagement;
|
using namespace ABI::Windows::UI::ViewManagement;
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
@ -63,8 +66,67 @@ static IUISettings *uiSettings()
|
|||||||
return settings.Get();
|
return settings.Get();
|
||||||
}
|
}
|
||||||
|
|
||||||
QWinRTTheme::QWinRTTheme()
|
class QWinRTThemePrivate
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
QPalette palette;
|
||||||
|
};
|
||||||
|
|
||||||
|
QWinRTTheme::QWinRTTheme()
|
||||||
|
: d_ptr(new QWinRTThemePrivate)
|
||||||
|
{
|
||||||
|
Q_D(QWinRTTheme);
|
||||||
|
|
||||||
|
HRESULT hr;
|
||||||
|
union { Color ui; QRgb qt; } color;
|
||||||
|
|
||||||
|
hr = uiSettings()->UIElementColor(UIElementType_ActiveCaption, &color.ui);
|
||||||
|
Q_ASSERT_SUCCEEDED(hr);
|
||||||
|
d->palette.setColor(QPalette::ToolTipBase, color.qt);
|
||||||
|
|
||||||
|
hr = uiSettings()->UIElementColor(UIElementType_Background, &color.ui);
|
||||||
|
Q_ASSERT_SUCCEEDED(hr);
|
||||||
|
d->palette.setColor(QPalette::AlternateBase, color.qt);
|
||||||
|
|
||||||
|
hr = uiSettings()->UIElementColor(UIElementType_ButtonFace, &color.ui);
|
||||||
|
Q_ASSERT_SUCCEEDED(hr);
|
||||||
|
d->palette.setColor(QPalette::Button, color.qt);
|
||||||
|
d->palette.setColor(QPalette::Midlight, QColor(color.qt).lighter(110));
|
||||||
|
d->palette.setColor(QPalette::Light, QColor(color.qt).lighter(150));
|
||||||
|
d->palette.setColor(QPalette::Mid, QColor(color.qt).dark(130));
|
||||||
|
d->palette.setColor(QPalette::Dark, QColor(color.qt).dark(150));
|
||||||
|
|
||||||
|
hr = uiSettings()->UIElementColor(UIElementType_ButtonText, &color.ui);
|
||||||
|
Q_ASSERT_SUCCEEDED(hr);
|
||||||
|
d->palette.setColor(QPalette::ButtonText, color.qt);
|
||||||
|
d->palette.setColor(QPalette::Text, color.qt);
|
||||||
|
|
||||||
|
hr = uiSettings()->UIElementColor(UIElementType_CaptionText, &color.ui);
|
||||||
|
Q_ASSERT_SUCCEEDED(hr);
|
||||||
|
d->palette.setColor(QPalette::ToolTipText, color.qt);
|
||||||
|
|
||||||
|
hr = uiSettings()->UIElementColor(UIElementType_Highlight, &color.ui);
|
||||||
|
Q_ASSERT_SUCCEEDED(hr);
|
||||||
|
d->palette.setColor(QPalette::Highlight, color.qt);
|
||||||
|
|
||||||
|
hr = uiSettings()->UIElementColor(UIElementType_HighlightText, &color.ui);
|
||||||
|
Q_ASSERT_SUCCEEDED(hr);
|
||||||
|
d->palette.setColor(QPalette::HighlightedText, color.qt);
|
||||||
|
|
||||||
|
hr = uiSettings()->UIElementColor(UIElementType_Window, &color.ui);
|
||||||
|
Q_ASSERT_SUCCEEDED(hr);
|
||||||
|
d->palette.setColor(QPalette::Window, color.qt);
|
||||||
|
d->palette.setColor(QPalette::Base, color.qt);
|
||||||
|
|
||||||
|
#ifdef Q_OS_WINPHONE
|
||||||
|
hr = uiSettings()->UIElementColor(UIElementType_TextHigh, &color.ui);
|
||||||
|
Q_ASSERT_SUCCEEDED(hr);
|
||||||
|
d->palette.setColor(QPalette::BrightText, color.qt);
|
||||||
|
#else
|
||||||
|
hr = uiSettings()->UIElementColor(UIElementType_Hotlight, &color.ui);
|
||||||
|
Q_ASSERT_SUCCEEDED(hr);
|
||||||
|
d->palette.setColor(QPalette::BrightText, color.qt);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QWinRTTheme::usePlatformNativeDialog(DialogType type) const
|
bool QWinRTTheme::usePlatformNativeDialog(DialogType type) const
|
||||||
@ -135,4 +197,12 @@ QVariant QWinRTTheme::styleHint(QPlatformIntegration::StyleHint hint)
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QPalette *QWinRTTheme::palette(Palette type) const
|
||||||
|
{
|
||||||
|
Q_D(const QWinRTTheme);
|
||||||
|
if (type == SystemPalette)
|
||||||
|
return &d->palette;
|
||||||
|
return QPlatformTheme::palette(type);
|
||||||
|
}
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@ -47,6 +47,7 @@
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
class QWinRTThemePrivate;
|
||||||
class QWinRTTheme : public QPlatformTheme
|
class QWinRTTheme : public QPlatformTheme
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -55,7 +56,13 @@ public:
|
|||||||
bool usePlatformNativeDialog(DialogType type) const;
|
bool usePlatformNativeDialog(DialogType type) const;
|
||||||
QPlatformDialogHelper *createPlatformDialogHelper(DialogType type) const;
|
QPlatformDialogHelper *createPlatformDialogHelper(DialogType type) const;
|
||||||
|
|
||||||
|
const QPalette *palette(Palette type = SystemPalette) const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
static QVariant styleHint(QPlatformIntegration::StyleHint hint);
|
static QVariant styleHint(QPlatformIntegration::StyleHint hint);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QScopedPointer<QWinRTThemePrivate> d_ptr;
|
||||||
|
Q_DECLARE_PRIVATE(QWinRTTheme)
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
Loading…
Reference in New Issue
Block a user