Reduce allocations required for the palette

pull/867/head
Nicolas Werner 3 years ago
parent d8ead9573b
commit 812e3b5f03
No known key found for this signature in database
GPG Key ID: C8D75E610773F2D9
  1. 6
      src/ui/Theme.cpp

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

Loading…
Cancel
Save