Reduce allocations required for the palette

This commit is contained in:
Nicolas Werner 2021-12-29 06:01:20 +01:00
parent d8ead9573b
commit 812e3b5f03
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9

View file

@ -12,6 +12,7 @@ Theme::paletteFromTheme(std::string_view theme)
[[maybe_unused]] static auto meta = qRegisterMetaType<Theme>("Theme");
static QPalette original;
if (theme == "light") {
static QPalette lightActive = [] {
QPalette lightActive(
/*windowText*/ QColor(0x33, 0x33, 0x33),
/*button*/ QColor(Qt::GlobalColor::white),
@ -30,7 +31,10 @@ Theme::paletteFromTheme(std::string_view theme)
lightActive.setColor(QPalette::Link, QColor(0x00, 0x77, 0xb5));
lightActive.setColor(QPalette::ButtonText, QColor(0x55, 0x54, 0x59));
return lightActive;
}();
return lightActive;
} else if (theme == "dark") {
static QPalette darkActive = [] {
QPalette darkActive(
/*windowText*/ QColor(0xca, 0xcc, 0xd1),
/*button*/ QColor(Qt::GlobalColor::white),
@ -49,6 +53,8 @@ Theme::paletteFromTheme(std::string_view theme)
darkActive.setColor(QPalette::Link, QColor(0x38, 0xa3, 0xd8));
darkActive.setColor(QPalette::ButtonText, QColor(0x82, 0x82, 0x84));
return darkActive;
}();
return darkActive;
} else {
return original;
}