-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Qt: Serialize icon & theme, properly set them
- Loading branch information
1 parent
95cc79e
commit 6f90c25
Showing
8 changed files
with
128 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
#include <string> | ||
|
||
// Some UI settings that aren't fully frontend-dependent. Note: Not all frontends will support the same settings. | ||
// Note: Any enums should ideally be ordered in the same order we want to show them in UI dropdown menus, so that we can cast indices to enums | ||
// directly. | ||
struct FrontendSettings { | ||
enum class Theme : int { | ||
System = 0, | ||
Light = 1, | ||
Dark = 2, | ||
GreetingsCat = 3, | ||
Cream = 4, | ||
}; | ||
|
||
// Different panda-themed window icons | ||
enum class WindowIcon : int { | ||
Rpog = 0, | ||
Rsyn = 1, | ||
}; | ||
|
||
Theme theme = Theme::Dark; | ||
WindowIcon icon = WindowIcon::Rpog; | ||
|
||
static Theme themeFromString(std::string inString); | ||
static const char* themeToString(Theme theme); | ||
|
||
static WindowIcon iconFromString(std::string inString); | ||
static const char* iconToString(WindowIcon icon); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include "frontend_settings.hpp" | ||
|
||
#include <algorithm> | ||
#include <cctype> | ||
#include <unordered_map> | ||
|
||
// Frontend setting serialization/deserialization functions | ||
|
||
FrontendSettings::Theme FrontendSettings::themeFromString(std::string inString) { | ||
// Transform to lower-case to make the setting case-insensitive | ||
std::transform(inString.begin(), inString.end(), inString.begin(), [](unsigned char c) { return std::tolower(c); }); | ||
|
||
static const std::unordered_map<std::string, Theme> map = { | ||
{"system", Theme::System}, {"light", Theme::Light}, {"dark", Theme::Dark}, {"greetingscat", Theme::GreetingsCat}, {"cream", Theme::Cream}, | ||
}; | ||
|
||
if (auto search = map.find(inString); search != map.end()) { | ||
return search->second; | ||
} | ||
|
||
// Default to dark theme | ||
return Theme::Dark; | ||
} | ||
|
||
const char* FrontendSettings::themeToString(Theme theme) { | ||
switch (theme) { | ||
case Theme::System: return "system"; | ||
case Theme::Light: return "light"; | ||
case Theme::GreetingsCat: return "greetingscat"; | ||
case Theme::Cream: return "cream"; | ||
|
||
case Theme::Dark: | ||
default: return "dark"; | ||
} | ||
} | ||
|
||
FrontendSettings::WindowIcon FrontendSettings::iconFromString(std::string inString) { // Transform to lower-case to make the setting case-insensitive | ||
std::transform(inString.begin(), inString.end(), inString.begin(), [](unsigned char c) { return std::tolower(c); }); | ||
|
||
static const std::unordered_map<std::string, WindowIcon> map = { | ||
{"rpog", WindowIcon::Rpog}, {"rsyn", WindowIcon::Rsyn}, | ||
}; | ||
|
||
if (auto search = map.find(inString); search != map.end()) { | ||
return search->second; | ||
} | ||
|
||
// Default to the icon rpog icon | ||
return WindowIcon::Rpog; | ||
} | ||
|
||
const char* FrontendSettings::iconToString(WindowIcon icon) { | ||
switch (icon) { | ||
case WindowIcon::Rsyn: return "rsyn"; | ||
|
||
case WindowIcon::Rpog: | ||
default: return "rpog"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters