mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 19:10:06 +00:00
Cleaning up font selection in settings dialog
This commit is contained in:
parent
4e5aa7b5e1
commit
d3a3c3db36
5 changed files with 95 additions and 58 deletions
|
|
@ -27,7 +27,7 @@ template<class T>
|
||||||
class SettingsInterface<T>::Impl
|
class SettingsInterface<T>::Impl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit Impl()
|
explicit Impl(SettingsInterface* self) : self_ {self}
|
||||||
{
|
{
|
||||||
context_->moveToThread(QCoreApplication::instance()->thread());
|
context_->moveToThread(QCoreApplication::instance()->thread());
|
||||||
}
|
}
|
||||||
|
|
@ -40,6 +40,8 @@ public:
|
||||||
void UpdateEditWidget();
|
void UpdateEditWidget();
|
||||||
void UpdateResetButton();
|
void UpdateResetButton();
|
||||||
|
|
||||||
|
SettingsInterface<T>* self_;
|
||||||
|
|
||||||
SettingsVariable<T>* variable_ {nullptr};
|
SettingsVariable<T>* variable_ {nullptr};
|
||||||
bool stagedValid_ {true};
|
bool stagedValid_ {true};
|
||||||
|
|
||||||
|
|
@ -53,17 +55,27 @@ public:
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
SettingsInterface<T>::SettingsInterface() :
|
SettingsInterface<T>::SettingsInterface() :
|
||||||
SettingsInterfaceBase(), p(std::make_unique<Impl>())
|
SettingsInterfaceBase(), p(std::make_unique<Impl>(this))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
template<class T>
|
template<class T>
|
||||||
SettingsInterface<T>::~SettingsInterface() = default;
|
SettingsInterface<T>::~SettingsInterface() = default;
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
SettingsInterface<T>::SettingsInterface(SettingsInterface&&) noexcept = default;
|
SettingsInterface<T>::SettingsInterface(SettingsInterface&& o) noexcept :
|
||||||
|
p {std::move(o.p)}
|
||||||
|
{
|
||||||
|
p->self_ = this;
|
||||||
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
SettingsInterface<T>&
|
SettingsInterface<T>&
|
||||||
SettingsInterface<T>::operator=(SettingsInterface&&) noexcept = default;
|
SettingsInterface<T>::operator=(SettingsInterface&& o) noexcept
|
||||||
|
{
|
||||||
|
p = std::move(o.p);
|
||||||
|
p->self_ = this;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void SettingsInterface<T>::SetSettingsVariable(SettingsVariable<T>& variable)
|
void SettingsInterface<T>::SetSettingsVariable(SettingsVariable<T>& variable)
|
||||||
|
|
@ -77,6 +89,27 @@ SettingsVariable<T>* SettingsInterface<T>::GetSettingsVariable() const
|
||||||
return p->variable_;
|
return p->variable_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
bool SettingsInterface<T>::IsDefault()
|
||||||
|
{
|
||||||
|
bool isDefault = false;
|
||||||
|
|
||||||
|
const std::optional<T> staged = p->variable_->GetStaged();
|
||||||
|
const T defaultValue = p->variable_->GetDefault();
|
||||||
|
const T value = p->variable_->GetValue();
|
||||||
|
|
||||||
|
if (staged.has_value())
|
||||||
|
{
|
||||||
|
isDefault = (p->stagedValid_ && *staged == defaultValue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
isDefault = (value == defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
return isDefault;
|
||||||
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
bool SettingsInterface<T>::Commit()
|
bool SettingsInterface<T>::Commit()
|
||||||
{
|
{
|
||||||
|
|
@ -99,6 +132,14 @@ void SettingsInterface<T>::StageDefault()
|
||||||
p->UpdateResetButton();
|
p->UpdateResetButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void SettingsInterface<T>::StageValue(const T& value)
|
||||||
|
{
|
||||||
|
p->variable_->StageValue(value);
|
||||||
|
p->UpdateEditWidget();
|
||||||
|
p->UpdateResetButton();
|
||||||
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void SettingsInterface<T>::SetEditWidget(QWidget* widget)
|
void SettingsInterface<T>::SetEditWidget(QWidget* widget)
|
||||||
{
|
{
|
||||||
|
|
@ -412,20 +453,9 @@ void SettingsInterface<T>::Impl::UpdateEditWidget()
|
||||||
template<class T>
|
template<class T>
|
||||||
void SettingsInterface<T>::Impl::UpdateResetButton()
|
void SettingsInterface<T>::Impl::UpdateResetButton()
|
||||||
{
|
{
|
||||||
const std::optional<T> staged = variable_->GetStaged();
|
|
||||||
const T defaultValue = variable_->GetDefault();
|
|
||||||
const T value = variable_->GetValue();
|
|
||||||
|
|
||||||
if (resetButton_ != nullptr)
|
if (resetButton_ != nullptr)
|
||||||
{
|
{
|
||||||
if (staged.has_value())
|
resetButton_->setVisible(!self_->IsDefault());
|
||||||
{
|
|
||||||
resetButton_->setVisible(!stagedValid_ || *staged != defaultValue);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
resetButton_->setVisible(value != defaultValue);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,14 @@ public:
|
||||||
*/
|
*/
|
||||||
SettingsVariable<T>* GetSettingsVariable() const;
|
SettingsVariable<T>* GetSettingsVariable() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets whether the staged value (or current value, if none staged) is
|
||||||
|
* set to the default value.
|
||||||
|
*
|
||||||
|
* @return true if the settings variable is set to default, otherwise false.
|
||||||
|
*/
|
||||||
|
bool IsDefault() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the current value of the associated settings variable to the staged
|
* Sets the current value of the associated settings variable to the staged
|
||||||
* value.
|
* value.
|
||||||
|
|
@ -64,6 +72,11 @@ public:
|
||||||
*/
|
*/
|
||||||
void StageDefault() override;
|
void StageDefault() override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stages a value to the associated settings variable.
|
||||||
|
*/
|
||||||
|
void StageValue(const T& value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the edit widget from the settings dialog.
|
* Sets the edit widget from the settings dialog.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -24,10 +24,18 @@ public:
|
||||||
SettingsInterfaceBase(SettingsInterfaceBase&&) noexcept;
|
SettingsInterfaceBase(SettingsInterfaceBase&&) noexcept;
|
||||||
SettingsInterfaceBase& operator=(SettingsInterfaceBase&&) noexcept;
|
SettingsInterfaceBase& operator=(SettingsInterfaceBase&&) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets whether the staged value (or current value, if none staged) is
|
||||||
|
* set to the default value.
|
||||||
|
*
|
||||||
|
* @return true if the settings variable is set to default, otherwise false.
|
||||||
|
*/
|
||||||
|
virtual bool IsDefault() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the current value of the associated settings variable to the staged
|
* Sets the current value of the associated settings variable to the staged
|
||||||
* value.
|
* value.
|
||||||
*
|
*
|
||||||
* @return true if the staged value was committed, false if no staged value
|
* @return true if the staged value was committed, false if no staged value
|
||||||
* is present.
|
* is present.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -312,18 +312,24 @@ void SettingsDialogImpl::ConnectSignals()
|
||||||
self_,
|
self_,
|
||||||
[this](const QFont& font)
|
[this](const QFont& font)
|
||||||
{
|
{
|
||||||
logger_->debug("Selected font: {}",
|
|
||||||
font.toString().toStdString());
|
|
||||||
|
|
||||||
fontFamilies_.at(selectedFontCategory_)
|
fontFamilies_.at(selectedFontCategory_)
|
||||||
.GetSettingsVariable()
|
.StageValue(font.family().toStdString());
|
||||||
->StageValue(font.family().toStdString());
|
|
||||||
fontStyles_.at(selectedFontCategory_)
|
fontStyles_.at(selectedFontCategory_)
|
||||||
.GetSettingsVariable()
|
.StageValue(font.styleName().toStdString());
|
||||||
->StageValue(font.styleName().toStdString());
|
|
||||||
fontPointSizes_.at(selectedFontCategory_)
|
fontPointSizes_.at(selectedFontCategory_)
|
||||||
.GetSettingsVariable()
|
.StageValue(font.pointSizeF());
|
||||||
->StageValue(font.pointSizeF());
|
|
||||||
|
UpdateFontDisplayData();
|
||||||
|
});
|
||||||
|
|
||||||
|
QObject::connect(self_->ui->resetFontButton,
|
||||||
|
&QAbstractButton::clicked,
|
||||||
|
self_,
|
||||||
|
[this]()
|
||||||
|
{
|
||||||
|
fontFamilies_.at(selectedFontCategory_).StageDefault();
|
||||||
|
fontStyles_.at(selectedFontCategory_).StageDefault();
|
||||||
|
fontPointSizes_.at(selectedFontCategory_).StageDefault();
|
||||||
|
|
||||||
UpdateFontDisplayData();
|
UpdateFontDisplayData();
|
||||||
});
|
});
|
||||||
|
|
@ -943,37 +949,6 @@ QFont SettingsDialogImpl::GetSelectedFont()
|
||||||
|
|
||||||
void SettingsDialogImpl::SelectFontCategory(types::FontCategory fontCategory)
|
void SettingsDialogImpl::SelectFontCategory(types::FontCategory fontCategory)
|
||||||
{
|
{
|
||||||
if (selectedFontCategory_ != types::FontCategory::Unknown &&
|
|
||||||
selectedFontCategory_ != fontCategory)
|
|
||||||
{
|
|
||||||
auto& fontFamily = fontFamilies_.at(selectedFontCategory_);
|
|
||||||
auto& fontStyle = fontStyles_.at(selectedFontCategory_);
|
|
||||||
auto& fontSize = fontPointSizes_.at(selectedFontCategory_);
|
|
||||||
|
|
||||||
fontFamily.SetResetButton(nullptr);
|
|
||||||
fontStyle.SetResetButton(nullptr);
|
|
||||||
fontSize.SetResetButton(nullptr);
|
|
||||||
|
|
||||||
fontFamily.SetEditWidget(nullptr);
|
|
||||||
fontStyle.SetEditWidget(nullptr);
|
|
||||||
fontSize.SetEditWidget(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selectedFontCategory_ != fontCategory)
|
|
||||||
{
|
|
||||||
auto& fontFamily = fontFamilies_.at(fontCategory);
|
|
||||||
auto& fontStyle = fontStyles_.at(fontCategory);
|
|
||||||
auto& fontSize = fontPointSizes_.at(fontCategory);
|
|
||||||
|
|
||||||
fontFamily.SetResetButton(self_->ui->resetFontButton);
|
|
||||||
fontStyle.SetResetButton(self_->ui->resetFontButton);
|
|
||||||
fontSize.SetResetButton(self_->ui->resetFontButton);
|
|
||||||
|
|
||||||
fontFamily.SetEditWidget(self_->ui->fontNameLabel);
|
|
||||||
fontStyle.SetEditWidget(self_->ui->fontStyleLabel);
|
|
||||||
fontSize.SetEditWidget(self_->ui->fontSizeLabel);
|
|
||||||
}
|
|
||||||
|
|
||||||
selectedFontCategory_ = fontCategory;
|
selectedFontCategory_ = fontCategory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -986,6 +961,17 @@ void SettingsDialogImpl::UpdateFontDisplayData()
|
||||||
self_->ui->fontSizeLabel->setText(QString::number(font.pointSizeF()));
|
self_->ui->fontSizeLabel->setText(QString::number(font.pointSizeF()));
|
||||||
|
|
||||||
self_->ui->fontPreviewLabel->setFont(font);
|
self_->ui->fontPreviewLabel->setFont(font);
|
||||||
|
|
||||||
|
if (selectedFontCategory_ != types::FontCategory::Unknown)
|
||||||
|
{
|
||||||
|
auto& fontFamily = fontFamilies_.at(selectedFontCategory_);
|
||||||
|
auto& fontStyle = fontStyles_.at(selectedFontCategory_);
|
||||||
|
auto& fontSize = fontPointSizes_.at(selectedFontCategory_);
|
||||||
|
|
||||||
|
self_->ui->resetFontButton->setVisible(!fontFamily.IsDefault() ||
|
||||||
|
!fontStyle.IsDefault() ||
|
||||||
|
!fontSize.IsDefault());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsDialogImpl::ApplyChanges()
|
void SettingsDialogImpl::ApplyChanges()
|
||||||
|
|
|
||||||
|
|
@ -446,7 +446,7 @@
|
||||||
<property name="frameShadow">
|
<property name="frameShadow">
|
||||||
<enum>QFrame::Plain</enum>
|
<enum>QFrame::Plain</enum>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_8" columnstretch="1,1">
|
<layout class="QGridLayout" name="gridLayout_8" columnstretch="2,3">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QFrame" name="frame_5">
|
<widget class="QFrame" name="frame_5">
|
||||||
<property name="frameShape">
|
<property name="frameShape">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue