iOS: Pick up theme palette from system colors
For now we just fill out the system palette, and react to the system changing theme from dark to light. A further improvement would be to fill in the control-specific palettes. Change-Id: I764db4415f5b55ccb193dae43e9f4386c765b30b Fixes: QTBUG-42944 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>bb10
parent
f9d219b926
commit
91d18c6464
|
|
@ -45,6 +45,7 @@
|
|||
#include "qiosapplicationdelegate.h"
|
||||
#include "qiosviewcontroller.h"
|
||||
#include "quiview.h"
|
||||
#include "qiostheme.h"
|
||||
|
||||
#include <QtCore/private/qcore_mac_p.h>
|
||||
|
||||
|
|
@ -207,6 +208,18 @@ static QIOSScreen* qtPlatformScreenFor(UIScreen *uiScreen)
|
|||
[super sendEvent:event];
|
||||
}
|
||||
|
||||
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection
|
||||
{
|
||||
[super traitCollectionDidChange:previousTraitCollection];
|
||||
|
||||
if (self.screen == UIScreen.mainScreen) {
|
||||
if (previousTraitCollection.userInterfaceStyle != self.traitCollection.userInterfaceStyle) {
|
||||
QIOSTheme::initializeSystemPalette();
|
||||
QWindowSystemInterface::handleThemeChange<QWindowSystemInterface::SynchronousDelivery>(nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -65,9 +65,12 @@ public:
|
|||
|
||||
static const char *name;
|
||||
|
||||
static void initializeSystemPalette();
|
||||
|
||||
private:
|
||||
mutable QHash<QPlatformTheme::Font, QFont *> m_fonts;
|
||||
QPalette m_systemPalette;
|
||||
|
||||
static QPalette s_systemPalette;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@
|
|||
#include <QtCore/private/qcore_mac_p.h>
|
||||
|
||||
#include <QtGui/QFont>
|
||||
#include <QtGui/private/qcoregraphics_p.h>
|
||||
|
||||
#include <QtFontDatabaseSupport/private/qcoretextfontdatabase_p.h>
|
||||
#include <QtGui/private/qguiapplication_p.h>
|
||||
|
|
@ -63,10 +64,8 @@ QT_BEGIN_NAMESPACE
|
|||
const char *QIOSTheme::name = "ios";
|
||||
|
||||
QIOSTheme::QIOSTheme()
|
||||
: m_systemPalette(*QPlatformTheme::palette(QPlatformTheme::SystemPalette))
|
||||
{
|
||||
m_systemPalette.setBrush(QPalette::Highlight, QColor(204, 221, 237));
|
||||
m_systemPalette.setBrush(QPalette::HighlightedText, Qt::black);
|
||||
initializeSystemPalette();
|
||||
}
|
||||
|
||||
QIOSTheme::~QIOSTheme()
|
||||
|
|
@ -74,10 +73,41 @@ QIOSTheme::~QIOSTheme()
|
|||
qDeleteAll(m_fonts);
|
||||
}
|
||||
|
||||
QPalette QIOSTheme::s_systemPalette;
|
||||
|
||||
void QIOSTheme::initializeSystemPalette()
|
||||
{
|
||||
Q_DECL_IMPORT QPalette qt_fusionPalette(void);
|
||||
s_systemPalette = qt_fusionPalette();
|
||||
|
||||
if (@available(ios 13.0, *)) {
|
||||
s_systemPalette.setBrush(QPalette::Window, qt_mac_toQBrush(UIColor.systemGroupedBackgroundColor.CGColor));
|
||||
s_systemPalette.setBrush(QPalette::Active, QPalette::WindowText, qt_mac_toQBrush(UIColor.labelColor.CGColor));
|
||||
|
||||
s_systemPalette.setBrush(QPalette::Base, qt_mac_toQBrush(UIColor.secondarySystemGroupedBackgroundColor.CGColor));
|
||||
s_systemPalette.setBrush(QPalette::Active, QPalette::Text, qt_mac_toQBrush(UIColor.labelColor.CGColor));
|
||||
|
||||
s_systemPalette.setBrush(QPalette::Button, qt_mac_toQBrush(UIColor.secondarySystemBackgroundColor.CGColor));
|
||||
s_systemPalette.setBrush(QPalette::Active, QPalette::ButtonText, qt_mac_toQBrush(UIColor.labelColor.CGColor));
|
||||
|
||||
s_systemPalette.setBrush(QPalette::Active, QPalette::BrightText, qt_mac_toQBrush(UIColor.lightTextColor.CGColor));
|
||||
s_systemPalette.setBrush(QPalette::Active, QPalette::PlaceholderText, qt_mac_toQBrush(UIColor.placeholderTextColor.CGColor));
|
||||
|
||||
s_systemPalette.setBrush(QPalette::Active, QPalette::Link, qt_mac_toQBrush(UIColor.linkColor.CGColor));
|
||||
s_systemPalette.setBrush(QPalette::Active, QPalette::LinkVisited, qt_mac_toQBrush(UIColor.linkColor.CGColor));
|
||||
|
||||
s_systemPalette.setBrush(QPalette::Highlight, QColor(11, 70, 150, 60));
|
||||
s_systemPalette.setBrush(QPalette::HighlightedText, qt_mac_toQBrush(UIColor.labelColor.CGColor));
|
||||
} else {
|
||||
s_systemPalette.setBrush(QPalette::Highlight, QColor(204, 221, 237));
|
||||
s_systemPalette.setBrush(QPalette::HighlightedText, Qt::black);
|
||||
}
|
||||
}
|
||||
|
||||
const QPalette *QIOSTheme::palette(QPlatformTheme::Palette type) const
|
||||
{
|
||||
if (type == QPlatformTheme::SystemPalette)
|
||||
return &m_systemPalette;
|
||||
return &s_systemPalette;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue