mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 05:10:04 +00:00 
			
		
		
		
	Connecting font selection to settings dialog, in-work
This commit is contained in:
		
							parent
							
								
									d82fb666f9
								
							
						
					
					
						commit
						4e5aa7b5e1
					
				
					 6 changed files with 245 additions and 95 deletions
				
			
		|  | @ -9,6 +9,7 @@ | |||
| #include <QCheckBox> | ||||
| #include <QComboBox> | ||||
| #include <QCoreApplication> | ||||
| #include <QLabel> | ||||
| #include <QLineEdit> | ||||
| #include <QSpinBox> | ||||
| #include <QWidget> | ||||
|  | @ -33,6 +34,9 @@ public: | |||
| 
 | ||||
|    ~Impl() {} | ||||
| 
 | ||||
|    template<class U> | ||||
|    void SetWidgetText(U* widget, const T& currentValue); | ||||
| 
 | ||||
|    void UpdateEditWidget(); | ||||
|    void UpdateResetButton(); | ||||
| 
 | ||||
|  | @ -105,6 +109,11 @@ void SettingsInterface<T>::SetEditWidget(QWidget* widget) | |||
| 
 | ||||
|    p->editWidget_ = widget; | ||||
| 
 | ||||
|    if (widget == nullptr) | ||||
|    { | ||||
|       return; | ||||
|    } | ||||
| 
 | ||||
|    if (QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(widget)) | ||||
|    { | ||||
|       if constexpr (std::is_same_v<T, std::string>) | ||||
|  | @ -274,33 +283,36 @@ void SettingsInterface<T>::SetResetButton(QAbstractButton* button) | |||
| 
 | ||||
|    p->resetButton_ = button; | ||||
| 
 | ||||
|    QObject::connect(p->resetButton_, | ||||
|                     &QAbstractButton::clicked, | ||||
|                     p->context_.get(), | ||||
|                     [this]() | ||||
|                     { | ||||
|                        T defaultValue = p->variable_->GetDefault(); | ||||
| 
 | ||||
|                        if (p->variable_->GetValue() == defaultValue) | ||||
|    if (p->resetButton_ != nullptr) | ||||
|    { | ||||
|       QObject::connect(p->resetButton_, | ||||
|                        &QAbstractButton::clicked, | ||||
|                        p->context_.get(), | ||||
|                        [this]() | ||||
|                        { | ||||
|                           // If the current value is default, reset the staged
 | ||||
|                           // value
 | ||||
|                           p->variable_->Reset(); | ||||
|                           p->stagedValid_ = true; | ||||
|                           p->UpdateEditWidget(); | ||||
|                           p->UpdateResetButton(); | ||||
|                        } | ||||
|                        else | ||||
|                        { | ||||
|                           // Stage the default value
 | ||||
|                           p->stagedValid_ = | ||||
|                              p->variable_->StageValue(defaultValue); | ||||
|                           p->UpdateEditWidget(); | ||||
|                           p->UpdateResetButton(); | ||||
|                        } | ||||
|                     }); | ||||
|                           T defaultValue = p->variable_->GetDefault(); | ||||
| 
 | ||||
|    p->UpdateResetButton(); | ||||
|                           if (p->variable_->GetValue() == defaultValue) | ||||
|                           { | ||||
|                              // If the current value is default, reset the
 | ||||
|                              // staged value
 | ||||
|                              p->variable_->Reset(); | ||||
|                              p->stagedValid_ = true; | ||||
|                              p->UpdateEditWidget(); | ||||
|                              p->UpdateResetButton(); | ||||
|                           } | ||||
|                           else | ||||
|                           { | ||||
|                              // Stage the default value
 | ||||
|                              p->stagedValid_ = | ||||
|                                 p->variable_->StageValue(defaultValue); | ||||
|                              p->UpdateEditWidget(); | ||||
|                              p->UpdateResetButton(); | ||||
|                           } | ||||
|                        }); | ||||
| 
 | ||||
|       p->UpdateResetButton(); | ||||
|    } | ||||
| } | ||||
| 
 | ||||
| template<class T> | ||||
|  | @ -317,6 +329,39 @@ void SettingsInterface<T>::SetMapToValueFunction( | |||
|    p->mapToValue_ = function; | ||||
| } | ||||
| 
 | ||||
| template<class T> | ||||
| template<class U> | ||||
| void SettingsInterface<T>::Impl::SetWidgetText(U* widget, const T& currentValue) | ||||
| { | ||||
|    if constexpr (std::is_integral_v<T>) | ||||
|    { | ||||
|       widget->setText(QString::number(currentValue)); | ||||
|    } | ||||
|    else if constexpr (std::is_same_v<T, std::string>) | ||||
|    { | ||||
|       if (mapFromValue_ != nullptr) | ||||
|       { | ||||
|          widget->setText(QString::fromStdString(mapFromValue_(currentValue))); | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|          widget->setText(QString::fromStdString(currentValue)); | ||||
|       } | ||||
|    } | ||||
|    else if constexpr (std::is_same_v<T, std::vector<std::int64_t>>) | ||||
|    { | ||||
|       if (mapFromValue_ != nullptr) | ||||
|       { | ||||
|          widget->setText(QString::fromStdString(mapFromValue_(currentValue))); | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|          widget->setText(QString::fromStdString( | ||||
|             fmt::format("{}", fmt::join(currentValue, ", ")))); | ||||
|       } | ||||
|    } | ||||
| } | ||||
| 
 | ||||
| template<class T> | ||||
| void SettingsInterface<T>::Impl::UpdateEditWidget() | ||||
| { | ||||
|  | @ -327,35 +372,11 @@ void SettingsInterface<T>::Impl::UpdateEditWidget() | |||
| 
 | ||||
|    if (QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(editWidget_)) | ||||
|    { | ||||
|       if constexpr (std::is_integral_v<T>) | ||||
|       { | ||||
|          lineEdit->setText(QString::number(currentValue)); | ||||
|       } | ||||
|       else if constexpr (std::is_same_v<T, std::string>) | ||||
|       { | ||||
|          if (mapFromValue_ != nullptr) | ||||
|          { | ||||
|             lineEdit->setText( | ||||
|                QString::fromStdString(mapFromValue_(currentValue))); | ||||
|          } | ||||
|          else | ||||
|          { | ||||
|             lineEdit->setText(QString::fromStdString(currentValue)); | ||||
|          } | ||||
|       } | ||||
|       else if constexpr (std::is_same_v<T, std::vector<std::int64_t>>) | ||||
|       { | ||||
|          if (mapFromValue_ != nullptr) | ||||
|          { | ||||
|             lineEdit->setText( | ||||
|                QString::fromStdString(mapFromValue_(currentValue))); | ||||
|          } | ||||
|          else | ||||
|          { | ||||
|             lineEdit->setText(QString::fromStdString( | ||||
|                fmt::format("{}", fmt::join(currentValue, ", ")))); | ||||
|          } | ||||
|       } | ||||
|       SetWidgetText(lineEdit, currentValue); | ||||
|    } | ||||
|    else if (QLabel* label = dynamic_cast<QLabel*>(editWidget_)) | ||||
|    { | ||||
|       SetWidgetText(label, currentValue); | ||||
|    } | ||||
|    else if (QCheckBox* checkBox = dynamic_cast<QCheckBox*>(editWidget_)) | ||||
|    { | ||||
|  |  | |||
|  | @ -239,6 +239,12 @@ std::optional<T> SettingsVariable<T>::GetStaged() const | |||
|    return p->staged_; | ||||
| } | ||||
| 
 | ||||
| template<class T> | ||||
| T SettingsVariable<T>::GetStagedOrValue() const | ||||
| { | ||||
|    return p->staged_.value_or(GetValue()); | ||||
| } | ||||
| 
 | ||||
| template<class T> | ||||
| T SettingsVariable<T>::GetDefault() const | ||||
| { | ||||
|  |  | |||
|  | @ -103,6 +103,14 @@ public: | |||
|     */ | ||||
|    std::optional<T> GetStaged() const; | ||||
| 
 | ||||
|    /**
 | ||||
|     * Gets the staged value of the settings variable, if defined, otherwise the | ||||
|     * current value. | ||||
|     * | ||||
|     * @return Staged value or current value | ||||
|     */ | ||||
|    T GetStagedOrValue() const; | ||||
| 
 | ||||
|    /**
 | ||||
|     * Validate the value against the defined parameters of the settings | ||||
|     * variable. | ||||
|  |  | |||
|  | @ -79,6 +79,13 @@ public: | |||
| 
 | ||||
|    void InitializeFontVariables(); | ||||
| 
 | ||||
|    friend bool operator==(const FontData& lhs, const FontData& rhs) | ||||
|    { | ||||
|       return (lhs.fontFamily_ == rhs.fontFamily_ && | ||||
|               lhs.fontStyle_ == rhs.fontStyle_ && | ||||
|               lhs.fontPointSize_ == rhs.fontPointSize_); | ||||
|    } | ||||
| 
 | ||||
|    TextSettings* self_; | ||||
| 
 | ||||
|    std::unordered_map<types::FontCategory, FontData> fontData_ {}; | ||||
|  | @ -168,7 +175,8 @@ TextSettings& TextSettings::Instance() | |||
| 
 | ||||
| bool operator==(const TextSettings& lhs, const TextSettings& rhs) | ||||
| { | ||||
|    return (lhs.p->hoverTextWrap_ == rhs.p->hoverTextWrap_ && | ||||
|    return (lhs.p->fontData_ == rhs.p->fontData_ && | ||||
|            lhs.p->hoverTextWrap_ == rhs.p->hoverTextWrap_ && | ||||
|            lhs.p->tooltipMethod_ == rhs.p->tooltipMethod_); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat