mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 17:50: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 <scwx/qt/settings/settings_interface.hpp>
|
||||
#include <scwx/qt/settings/text_settings.hpp>
|
||||
#include <scwx/qt/types/alert_types.hpp>
|
||||
#include <scwx/qt/types/font_types.hpp>
|
||||
#include <scwx/qt/types/text_types.hpp>
|
||||
#include <scwx/qt/ui/placefile_settings_widget.hpp>
|
||||
#include <scwx/qt/ui/radar_site_dialog.hpp>
|
||||
|
|
@ -119,7 +120,10 @@ public:
|
|||
}
|
||||
|
||||
// Configure font dialog
|
||||
fontDialog_->setOptions(QFontDialog::FontDialogOption::ScalableFonts);
|
||||
fontDialog_->setOptions(
|
||||
QFontDialog::FontDialogOption::DontUseNativeDialog |
|
||||
QFontDialog::FontDialogOption::ScalableFonts);
|
||||
fontDialog_->setWindowModality(Qt::WindowModality::WindowModal);
|
||||
}
|
||||
~SettingsDialogImpl() = default;
|
||||
|
||||
|
|
@ -133,6 +137,10 @@ public:
|
|||
void ShowColorDialog(QLineEdit* lineEdit, QFrame* frame = nullptr);
|
||||
void UpdateRadarDialogLocation(const std::string& id);
|
||||
|
||||
QFont GetSelectedFont();
|
||||
void SelectFontCategory(types::FontCategory fontCategory);
|
||||
void UpdateFontDisplayData();
|
||||
|
||||
void ApplyChanges();
|
||||
void DiscardChanges();
|
||||
void ResetToDefault();
|
||||
|
|
@ -157,6 +165,8 @@ public:
|
|||
|
||||
QStandardItemModel* fontCategoryModel_;
|
||||
|
||||
types::FontCategory selectedFontCategory_ {types::FontCategory::Unknown};
|
||||
|
||||
settings::SettingsInterface<std::string> defaultRadarSite_ {};
|
||||
settings::SettingsInterface<std::vector<std::int64_t>> fontSizes_ {};
|
||||
settings::SettingsInterface<std::int64_t> gridWidth_ {};
|
||||
|
|
@ -251,18 +261,6 @@ void SettingsDialogImpl::ConnectSignals()
|
|||
}
|
||||
});
|
||||
|
||||
QObject::connect(self_->ui->fontSelectButton,
|
||||
&QAbstractButton::clicked,
|
||||
self_,
|
||||
[this]() { fontDialog_->show(); });
|
||||
|
||||
QObject::connect(
|
||||
fontDialog_,
|
||||
&QFontDialog::fontSelected,
|
||||
self_,
|
||||
[this](const QFont& font)
|
||||
{ logger_->debug("Selected font: {}", font.toString().toStdString()); });
|
||||
|
||||
// Update the Radar Site dialog "map" location with the currently selected
|
||||
// radar site
|
||||
auto& defaultRadarSite = *defaultRadarSite_.GetSettingsVariable();
|
||||
|
|
@ -270,6 +268,66 @@ void SettingsDialogImpl::ConnectSignals()
|
|||
[this](const std::string& newValue)
|
||||
{ UpdateRadarDialogLocation(newValue); });
|
||||
|
||||
QObject::connect(
|
||||
self_->ui->fontListView->selectionModel(),
|
||||
&QItemSelectionModel::selectionChanged,
|
||||
self_,
|
||||
[this](const QItemSelection& selected, const QItemSelection& deselected)
|
||||
{
|
||||
if (selected.size() == 0 && deselected.size() == 0)
|
||||
{
|
||||
// Items which stay selected but change their index are not
|
||||
// included in selected and deselected. Thus, this signal might
|
||||
// be emitted with both selected and deselected empty, if only
|
||||
// the indices of selected items change.
|
||||
return;
|
||||
}
|
||||
|
||||
if (selected.size() > 0)
|
||||
{
|
||||
QModelIndex selectedIndex = selected[0].indexes()[0];
|
||||
QVariant variantData =
|
||||
self_->ui->fontListView->model()->data(selectedIndex);
|
||||
if (variantData.typeId() == QMetaType::QString)
|
||||
{
|
||||
types::FontCategory fontCategory =
|
||||
types::GetFontCategory(variantData.toString().toStdString());
|
||||
SelectFontCategory(fontCategory);
|
||||
UpdateFontDisplayData();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
QObject::connect(self_->ui->fontSelectButton,
|
||||
&QAbstractButton::clicked,
|
||||
self_,
|
||||
[this]()
|
||||
{
|
||||
fontDialog_->setCurrentFont(GetSelectedFont());
|
||||
fontDialog_->show();
|
||||
});
|
||||
|
||||
QObject::connect(fontDialog_,
|
||||
&QFontDialog::fontSelected,
|
||||
self_,
|
||||
[this](const QFont& font)
|
||||
{
|
||||
logger_->debug("Selected font: {}",
|
||||
font.toString().toStdString());
|
||||
|
||||
fontFamilies_.at(selectedFontCategory_)
|
||||
.GetSettingsVariable()
|
||||
->StageValue(font.family().toStdString());
|
||||
fontStyles_.at(selectedFontCategory_)
|
||||
.GetSettingsVariable()
|
||||
->StageValue(font.styleName().toStdString());
|
||||
fontPointSizes_.at(selectedFontCategory_)
|
||||
.GetSettingsVariable()
|
||||
->StageValue(font.pointSizeF());
|
||||
|
||||
UpdateFontDisplayData();
|
||||
});
|
||||
|
||||
QObject::connect(
|
||||
self_->ui->buttonBox,
|
||||
&QDialogButtonBox::clicked,
|
||||
|
|
@ -706,6 +764,8 @@ void SettingsDialogImpl::SetupTextTab()
|
|||
fontSize.SetSettingsVariable(textSettings.font_point_size(fontCategory));
|
||||
}
|
||||
self_->ui->fontListView->setCurrentIndex(fontCategoryModel_->index(0, 0));
|
||||
SelectFontCategory(*types::FontCategoryIterator().begin());
|
||||
UpdateFontDisplayData();
|
||||
|
||||
hoverTextWrap_.SetSettingsVariable(textSettings.hover_text_wrap());
|
||||
hoverTextWrap_.SetEditWidget(self_->ui->hoverTextWrapSpinBox);
|
||||
|
|
@ -861,6 +921,73 @@ void SettingsDialogImpl::UpdateRadarDialogLocation(const std::string& id)
|
|||
}
|
||||
}
|
||||
|
||||
QFont SettingsDialogImpl::GetSelectedFont()
|
||||
{
|
||||
std::string fontFamily = fontFamilies_.at(selectedFontCategory_)
|
||||
.GetSettingsVariable()
|
||||
->GetStagedOrValue();
|
||||
std::string fontStyle = fontStyles_.at(selectedFontCategory_)
|
||||
.GetSettingsVariable()
|
||||
->GetStagedOrValue();
|
||||
units::font_size::points<double> fontSize {
|
||||
fontPointSizes_.at(selectedFontCategory_)
|
||||
.GetSettingsVariable()
|
||||
->GetStagedOrValue()};
|
||||
|
||||
QFont font(QString::fromStdString(fontFamily));
|
||||
font.setStyleName(QString::fromStdString(fontStyle));
|
||||
font.setPointSizeF(fontSize.value());
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void SettingsDialogImpl::UpdateFontDisplayData()
|
||||
{
|
||||
QFont font = GetSelectedFont();
|
||||
|
||||
self_->ui->fontNameLabel->setText(font.family());
|
||||
self_->ui->fontStyleLabel->setText(font.styleName());
|
||||
self_->ui->fontSizeLabel->setText(QString::number(font.pointSizeF()));
|
||||
|
||||
self_->ui->fontPreviewLabel->setFont(font);
|
||||
}
|
||||
|
||||
void SettingsDialogImpl::ApplyChanges()
|
||||
{
|
||||
logger_->info("Applying settings changes");
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@
|
|||
</sizepolicy>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>2</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="general">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
|
|
@ -468,36 +468,16 @@
|
|||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="2" column="1">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<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="3">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QLabel" name="label_10">
|
||||
<property name="text">
|
||||
<string>Display Item:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QListView" name="fontListView"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
@ -538,10 +518,10 @@
|
|||
<item row="7" column="0" colspan="5">
|
||||
<widget class="QFrame" name="frame_7">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
<enum>QFrame::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_7">
|
||||
<item>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue