mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 00:30:05 +00:00 
			
		
		
		
	Initial setup for font settings
This commit is contained in:
		
							parent
							
								
									e0aa327bb7
								
							
						
					
					
						commit
						ad1646d725
					
				
					 7 changed files with 192 additions and 23 deletions
				
			
		|  | @ -103,6 +103,7 @@ private: | |||
| 
 | ||||
| #ifdef SETTINGS_INTERFACE_IMPLEMENTATION | ||||
| template class SettingsInterface<bool>; | ||||
| template class SettingsInterface<double>; | ||||
| template class SettingsInterface<std::int64_t>; | ||||
| template class SettingsInterface<std::string>; | ||||
| 
 | ||||
|  |  | |||
|  | @ -12,10 +12,34 @@ namespace settings | |||
| 
 | ||||
| static const std::string logPrefix_ = "scwx::qt::settings::text_settings"; | ||||
| 
 | ||||
| static const std::string kAlteDIN1451Mittelscrhift_ { | ||||
|    "Alte DIN 1451 Mittelschrift"}; | ||||
| static const std::string kInconsolata_ {"Inconsolata"}; | ||||
| 
 | ||||
| static const std::string kRegular_ {"Regular"}; | ||||
| 
 | ||||
| static const std::unordered_map<types::FontCategory, std::string> | ||||
|    kDefaultFontFamily_ { | ||||
|       {types::FontCategory::Default, kAlteDIN1451Mittelscrhift_}, | ||||
|       {types::FontCategory::Tooltip, kInconsolata_}}; | ||||
| static const std::unordered_map<types::FontCategory, std::string> | ||||
|    kDefaultFontStyle_ {{types::FontCategory::Default, kRegular_}, | ||||
|                        {types::FontCategory::Tooltip, kRegular_}}; | ||||
| static const std::unordered_map<types::FontCategory, double> | ||||
|    kDefaultFontPointSize_ {{types::FontCategory::Default, 12.0}, | ||||
|                            {types::FontCategory::Tooltip, 10.5}}; | ||||
| 
 | ||||
| class TextSettings::Impl | ||||
| { | ||||
| public: | ||||
|    explicit Impl() | ||||
|    struct FontData | ||||
|    { | ||||
|       SettingsVariable<std::string> fontFamily_ {"font_family"}; | ||||
|       SettingsVariable<std::string> fontStyle_ {"font_style"}; | ||||
|       SettingsVariable<double>      fontPointSize_ {"font_point_size"}; | ||||
|    }; | ||||
| 
 | ||||
|    explicit Impl(TextSettings* self) : self_ {self} | ||||
|    { | ||||
|       std::string defaultTooltipMethodValue = | ||||
|          types::GetTooltipMethodName(types::TooltipMethod::ImGui); | ||||
|  | @ -47,16 +71,24 @@ public: | |||
|             // No match found, invalid
 | ||||
|             return false; | ||||
|          }); | ||||
| 
 | ||||
|       InitializeFontVariables(); | ||||
|    } | ||||
| 
 | ||||
|    ~Impl() {} | ||||
| 
 | ||||
|    void InitializeFontVariables(); | ||||
| 
 | ||||
|    TextSettings* self_; | ||||
| 
 | ||||
|    std::unordered_map<types::FontCategory, FontData> fontData_ {}; | ||||
| 
 | ||||
|    SettingsVariable<std::int64_t> hoverTextWrap_ {"hover_text_wrap"}; | ||||
|    SettingsVariable<std::string>  tooltipMethod_ {"tooltip_method"}; | ||||
| }; | ||||
| 
 | ||||
| TextSettings::TextSettings() : | ||||
|     SettingsCategory("text"), p(std::make_unique<Impl>()) | ||||
|     SettingsCategory("text"), p(std::make_unique<Impl>(this)) | ||||
| { | ||||
|    RegisterVariables({&p->hoverTextWrap_, &p->tooltipMethod_}); | ||||
|    SetDefaults(); | ||||
|  | @ -66,6 +98,50 @@ TextSettings::~TextSettings() = default; | |||
| TextSettings::TextSettings(TextSettings&&) noexcept            = default; | ||||
| TextSettings& TextSettings::operator=(TextSettings&&) noexcept = default; | ||||
| 
 | ||||
| void TextSettings::Impl::InitializeFontVariables() | ||||
| { | ||||
|    for (auto fontCategory : types::FontCategoryIterator()) | ||||
|    { | ||||
|       auto  result = fontData_.emplace(fontCategory, FontData {}); | ||||
|       auto& pair   = *result.first; | ||||
|       auto& font   = pair.second; | ||||
| 
 | ||||
|       font.fontFamily_.SetDefault(kDefaultFontFamily_.at(fontCategory)); | ||||
|       font.fontStyle_.SetDefault(kDefaultFontStyle_.at(fontCategory)); | ||||
|       font.fontPointSize_.SetDefault(kDefaultFontPointSize_.at(fontCategory)); | ||||
| 
 | ||||
|       // String values must not be empty
 | ||||
|       font.fontFamily_.SetValidator([](const std::string& value) | ||||
|                                     { return !value.empty(); }); | ||||
|       font.fontStyle_.SetValidator([](const std::string& value) | ||||
|                                    { return !value.empty(); }); | ||||
| 
 | ||||
|       // Font point size must be between 6 and 72
 | ||||
|       font.fontPointSize_.SetMinimum(6.0); | ||||
|       font.fontPointSize_.SetMaximum(72.0); | ||||
| 
 | ||||
|       // TODO: Variable registration
 | ||||
|    } | ||||
| } | ||||
| 
 | ||||
| SettingsVariable<std::string>& | ||||
| TextSettings::font_family(types::FontCategory fontCategory) const | ||||
| { | ||||
|    return p->fontData_.at(fontCategory).fontFamily_; | ||||
| } | ||||
| 
 | ||||
| SettingsVariable<std::string>& | ||||
| TextSettings::font_style(types::FontCategory fontCategory) const | ||||
| { | ||||
|    return p->fontData_.at(fontCategory).fontStyle_; | ||||
| } | ||||
| 
 | ||||
| SettingsVariable<double>& | ||||
| TextSettings::font_point_size(types::FontCategory fontCategory) const | ||||
| { | ||||
|    return p->fontData_.at(fontCategory).fontPointSize_; | ||||
| } | ||||
| 
 | ||||
| SettingsVariable<std::int64_t>& TextSettings::hover_text_wrap() const | ||||
| { | ||||
|    return p->hoverTextWrap_; | ||||
|  |  | |||
|  | @ -2,6 +2,7 @@ | |||
| 
 | ||||
| #include <scwx/qt/settings/settings_category.hpp> | ||||
| #include <scwx/qt/settings/settings_variable.hpp> | ||||
| #include <scwx/qt/types/text_types.hpp> | ||||
| 
 | ||||
| #include <memory> | ||||
| #include <string> | ||||
|  | @ -25,6 +26,13 @@ public: | |||
|    TextSettings(TextSettings&&) noexcept; | ||||
|    TextSettings& operator=(TextSettings&&) noexcept; | ||||
| 
 | ||||
|    SettingsVariable<std::string>& | ||||
|    font_family(types::FontCategory fontCategory) const; | ||||
|    SettingsVariable<std::string>& | ||||
|    font_style(types::FontCategory fontCategory) const; | ||||
|    SettingsVariable<double>& | ||||
|    font_point_size(types::FontCategory fontCategory) const; | ||||
| 
 | ||||
|    SettingsVariable<std::int64_t>& hover_text_wrap() const; | ||||
|    SettingsVariable<std::string>&  tooltip_method() const; | ||||
| 
 | ||||
|  |  | |||
|  | @ -11,12 +11,40 @@ namespace qt | |||
| namespace types | ||||
| { | ||||
| 
 | ||||
| static const std::unordered_map<FontCategory, std::string> fontCategoryName_ { | ||||
|    {FontCategory::Default, "Default"}, | ||||
|    {FontCategory::Tooltip, "Tooltip"}, | ||||
|    {FontCategory::Unknown, "?"}}; | ||||
| 
 | ||||
| static const std::unordered_map<TooltipMethod, std::string> tooltipMethodName_ { | ||||
|    {TooltipMethod::ImGui, "ImGui"}, | ||||
|    {TooltipMethod::QToolTip, "Native Tooltip"}, | ||||
|    {TooltipMethod::QLabel, "Floating Label"}, | ||||
|    {TooltipMethod::Unknown, "?"}}; | ||||
| 
 | ||||
| FontCategory GetFontCategory(const std::string& name) | ||||
| { | ||||
|    auto result = | ||||
|       std::find_if(fontCategoryName_.cbegin(), | ||||
|                    fontCategoryName_.cend(), | ||||
|                    [&](const std::pair<FontCategory, std::string>& pair) -> bool | ||||
|                    { return boost::iequals(pair.second, name); }); | ||||
| 
 | ||||
|    if (result != fontCategoryName_.cend()) | ||||
|    { | ||||
|       return result->first; | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       return FontCategory::Unknown; | ||||
|    } | ||||
| } | ||||
| 
 | ||||
| std::string GetFontCategoryName(FontCategory fontCategory) | ||||
| { | ||||
|    return fontCategoryName_.at(fontCategory); | ||||
| } | ||||
| 
 | ||||
| TooltipMethod GetTooltipMethod(const std::string& name) | ||||
| { | ||||
|    auto result = std::find_if( | ||||
|  |  | |||
|  | @ -11,6 +11,16 @@ namespace qt | |||
| namespace types | ||||
| { | ||||
| 
 | ||||
| enum class FontCategory | ||||
| { | ||||
|    Default, | ||||
|    Tooltip, | ||||
|    Unknown | ||||
| }; | ||||
| typedef scwx::util:: | ||||
|    Iterator<FontCategory, FontCategory::Default, FontCategory::Tooltip> | ||||
|       FontCategoryIterator; | ||||
| 
 | ||||
| enum class TooltipMethod | ||||
| { | ||||
|    ImGui, | ||||
|  | @ -22,6 +32,8 @@ typedef scwx::util:: | |||
|    Iterator<TooltipMethod, TooltipMethod::ImGui, TooltipMethod::QLabel> | ||||
|       TooltipMethodIterator; | ||||
| 
 | ||||
| FontCategory  GetFontCategory(const std::string& name); | ||||
| std::string   GetFontCategoryName(FontCategory fontCategory); | ||||
| TooltipMethod GetTooltipMethod(const std::string& name); | ||||
| std::string   GetTooltipMethodName(TooltipMethod tooltipMethod); | ||||
| 
 | ||||
|  |  | |||
|  | @ -22,6 +22,7 @@ | |||
| #include <QColorDialog> | ||||
| #include <QFileDialog> | ||||
| #include <QFontDialog> | ||||
| #include <QStandardItemModel> | ||||
| #include <QToolButton> | ||||
| 
 | ||||
| namespace scwx | ||||
|  | @ -86,6 +87,7 @@ public: | |||
|        self_ {self}, | ||||
|        radarSiteDialog_ {new RadarSiteDialog(self)}, | ||||
|        fontDialog_ {new QFontDialog(self)}, | ||||
|        fontCategoryModel_ {new QStandardItemModel(self)}, | ||||
|        settings_ {std::initializer_list<settings::SettingsInterfaceBase*> { | ||||
|           &defaultRadarSite_, | ||||
|           &fontSizes_, | ||||
|  | @ -153,6 +155,8 @@ public: | |||
|    RadarSiteDialog*         radarSiteDialog_; | ||||
|    QFontDialog*             fontDialog_; | ||||
| 
 | ||||
|    QStandardItemModel* fontCategoryModel_; | ||||
| 
 | ||||
|    settings::SettingsInterface<std::string>               defaultRadarSite_ {}; | ||||
|    settings::SettingsInterface<std::vector<std::int64_t>> fontSizes_ {}; | ||||
|    settings::SettingsInterface<std::int64_t>              gridWidth_ {}; | ||||
|  | @ -173,6 +177,15 @@ public: | |||
|                       settings::SettingsInterface<std::string>> | ||||
|       inactiveAlertColors_ {}; | ||||
| 
 | ||||
|    std::unordered_map<types::FontCategory, | ||||
|                       settings::SettingsInterface<std::string>> | ||||
|       fontFamilies_ {}; | ||||
|    std::unordered_map<types::FontCategory, | ||||
|                       settings::SettingsInterface<std::string>> | ||||
|       fontStyles_ {}; | ||||
|    std::unordered_map<types::FontCategory, settings::SettingsInterface<double>> | ||||
|       fontPointSizes_ {}; | ||||
| 
 | ||||
|    settings::SettingsInterface<std::int64_t> hoverTextWrap_ {}; | ||||
|    settings::SettingsInterface<std::string>  tooltipMethod_ {}; | ||||
| 
 | ||||
|  | @ -663,6 +676,37 @@ void SettingsDialogImpl::SetupTextTab() | |||
| { | ||||
|    settings::TextSettings& textSettings = settings::TextSettings::Instance(); | ||||
| 
 | ||||
|    self_->ui->fontListView->setModel(fontCategoryModel_); | ||||
|    for (const auto& fontCategory : types::FontCategoryIterator()) | ||||
|    { | ||||
|       // Add font category to list view
 | ||||
|       fontCategoryModel_->appendRow(new QStandardItem( | ||||
|          QString::fromStdString(types::GetFontCategoryName(fontCategory)))); | ||||
| 
 | ||||
|       // Create settings interface
 | ||||
|       auto fontFamilyResult = fontFamilies_.emplace( | ||||
|          fontCategory, settings::SettingsInterface<std::string> {}); | ||||
|       auto fontStyleResult = fontStyles_.emplace( | ||||
|          fontCategory, settings::SettingsInterface<std::string> {}); | ||||
|       auto fontSizeResult = fontPointSizes_.emplace( | ||||
|          fontCategory, settings::SettingsInterface<double> {}); | ||||
| 
 | ||||
|       auto& fontFamily = (*fontFamilyResult.first).second; | ||||
|       auto& fontStyle  = (*fontStyleResult.first).second; | ||||
|       auto& fontSize   = (*fontSizeResult.first).second; | ||||
| 
 | ||||
|       // Add to settings list
 | ||||
|       settings_.push_back(&fontFamily); | ||||
|       settings_.push_back(&fontStyle); | ||||
|       settings_.push_back(&fontSize); | ||||
| 
 | ||||
|       // Set settings variables
 | ||||
|       fontFamily.SetSettingsVariable(textSettings.font_family(fontCategory)); | ||||
|       fontStyle.SetSettingsVariable(textSettings.font_style(fontCategory)); | ||||
|       fontSize.SetSettingsVariable(textSettings.font_point_size(fontCategory)); | ||||
|    } | ||||
|    self_->ui->fontListView->setCurrentIndex(fontCategoryModel_->index(0, 0)); | ||||
| 
 | ||||
|    hoverTextWrap_.SetSettingsVariable(textSettings.hover_text_wrap()); | ||||
|    hoverTextWrap_.SetEditWidget(self_->ui->hoverTextWrapSpinBox); | ||||
|    hoverTextWrap_.SetResetButton(self_->ui->resetHoverTextWrapButton); | ||||
|  |  | |||
|  | @ -469,13 +469,6 @@ | |||
|                  <number>0</number> | ||||
|                 </property> | ||||
|                 <item row="2" column="1"> | ||||
|                  <widget class="QPushButton" name="resetAllFontsButton"> | ||||
|                   <property name="text"> | ||||
|                    <string>Reset All Fonts</string> | ||||
|                   </property> | ||||
|                  </widget> | ||||
|                 </item> | ||||
|                 <item row="2" column="0"> | ||||
|                  <spacer name="horizontalSpacer_2"> | ||||
|                   <property name="orientation"> | ||||
|                    <enum>Qt::Horizontal</enum> | ||||
|  | @ -488,10 +481,17 @@ | |||
|                   </property> | ||||
|                  </spacer> | ||||
|                 </item> | ||||
|                 <item row="1" column="0" colspan="2"> | ||||
|                 <item row="2" column="0"> | ||||
|                  <widget class="QPushButton" name="resetAllFontsButton"> | ||||
|                   <property name="text"> | ||||
|                    <string>Reset All Fonts</string> | ||||
|                   </property> | ||||
|                  </widget> | ||||
|                 </item> | ||||
|                 <item row="1" column="0" colspan="3"> | ||||
|                  <widget class="QListView" name="fontListView"/> | ||||
|                 </item> | ||||
|                 <item row="0" column="0" colspan="2"> | ||||
|                 <item row="0" column="0" colspan="3"> | ||||
|                  <widget class="QLabel" name="label_10"> | ||||
|                   <property name="text"> | ||||
|                    <string>Display Item:</string> | ||||
|  | @ -581,17 +581,6 @@ | |||
|                   </property> | ||||
|                  </widget> | ||||
|                 </item> | ||||
|                 <item row="0" column="4"> | ||||
|                  <widget class="QToolButton" name="resetFontButton"> | ||||
|                   <property name="text"> | ||||
|                    <string>...</string> | ||||
|                   </property> | ||||
|                   <property name="icon"> | ||||
|                    <iconset resource="../../../../scwx-qt.qrc"> | ||||
|                     <normaloff>:/res/icons/font-awesome-6/rotate-left-solid.svg</normaloff>:/res/icons/font-awesome-6/rotate-left-solid.svg</iconset> | ||||
|                   </property> | ||||
|                  </widget> | ||||
|                 </item> | ||||
|                 <item row="5" column="2"> | ||||
|                  <widget class="QLabel" name="fontSizeLabel"> | ||||
|                   <property name="text"> | ||||
|  | @ -640,6 +629,17 @@ | |||
|                   </property> | ||||
|                  </spacer> | ||||
|                 </item> | ||||
|                 <item row="0" column="4"> | ||||
|                  <widget class="QToolButton" name="resetFontButton"> | ||||
|                   <property name="text"> | ||||
|                    <string>...</string> | ||||
|                   </property> | ||||
|                   <property name="icon"> | ||||
|                    <iconset resource="../../../../scwx-qt.qrc"> | ||||
|                     <normaloff>:/res/icons/font-awesome-6/rotate-left-solid.svg</normaloff>:/res/icons/font-awesome-6/rotate-left-solid.svg</iconset> | ||||
|                   </property> | ||||
|                  </widget> | ||||
|                 </item> | ||||
|                </layout> | ||||
|               </widget> | ||||
|              </item> | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat