32 #include <xmlsettingsdialog/basesettingsmanager.h> 37 #include "ui_wkfontswidget.h" 46 , Ui_ { std::make_shared<Ui::WkFontsWidget> () }
70 [
this, pair] { PendingFontChanges_ [pair.first] = pair.second->GetFont (); });
84 Util::Overload<int> (&QSpinBox::valueChanged),
85 [
this, pair] { PendingSizeChanges_ [pair.first] = pair.second->value (); });
90 Util::Overload<int> (&QSpinBox::valueChanged),
91 [
this] { IsFontZoomDirty_ = true; });
96 Ui_->Zoom_->setToolTip (label);
101 Settables_ << settable;
102 connect (settable->GetQObject (),
104 [
this, settable] { Settables_.removeOne (settable); });
107 settable->
SetFontFamily (pair.first, pair.second->GetFont ());
110 settable->SetFontSize (pair.first, pair.second->value ());
112 settable->SetFontSizeMultiplier (Ui_->Zoom_->value () / 100.);
117 Size2Spinbox_ [type]->setValue (size);
118 PendingSizeChanges_ [type] = size;
120 QTimer::singleShot (1000,
this, [
this] { ApplyPendingSizeChanges (); });
123 void WkFontsWidget::ResetFontChoosers ()
127 const auto& option = Family2Name_ [pair.first];
128 pair.second->SetFont (BSM_->property (option).value<QFont> ());
132 void WkFontsWidget::ResetSizeChoosers ()
136 const auto& option = Size2Name_ [pair.first];
137 pair.second->setValue (BSM_->Property (option, 10).toInt ());
141 void WkFontsWidget::ResetZoom ()
143 const auto factor = BSM_->Property (
"FontSizeMultiplier", 1).toDouble ();
144 Ui_->Zoom_->setValue (factor * 100);
147 void WkFontsWidget::ApplyPendingSizeChanges ()
149 for (
const auto& pair :
Util::Stlize (PendingSizeChanges_))
151 BSM_->setProperty (Size2Name_ [pair.first], pair.second);
154 for (
const auto settable : Settables_)
155 settable->SetFontSize (pair.first, pair.second);
158 PendingSizeChanges_.clear ();
161 void WkFontsWidget::on_ChangeAll__released ()
163 QHash<QString, QList<IWkFontsSettable::FontFamily>> families;
165 families [pair.second->GetFont ().family ()] << pair.first;
168 const auto& maxElem = std::max_element (stlized.begin (), stlized.end (),
169 ComparingBy ([] (
auto pair) {
return pair.second.size (); }));
171 const auto dialog =
new MassFontChangeDialog { maxElem->first, maxElem->second,
this };
175 [dialog,
this] (
int result)
177 if (result == QDialog::Rejected)
180 const auto& font = dialog->GetFont ();
181 for (
const auto family : dialog->GetFamilies ())
183 PendingFontChanges_ [family] = font;
184 Family2Chooser_ [family]->SetFont (font);
191 ApplyPendingSizeChanges ();
193 for (
const auto& pair :
Util::Stlize (PendingFontChanges_))
195 BSM_->setProperty (Family2Name_ [pair.first], pair.second);
198 for (
const auto settable : Settables_)
199 settable->SetFontFamily (pair.first, pair.second);
202 if (IsFontZoomDirty_)
204 const auto factor = Ui_->Zoom_->value () / 100.;
206 BSM_->setProperty (
"FontSizeMultiplier", factor);
209 for (
const auto settable : Settables_)
210 settable->SetFontSizeMultiplier (factor);
213 PendingFontChanges_.clear ();
214 IsFontZoomDirty_ =
false;
219 ResetFontChoosers ();
220 ResetSizeChoosers ();
223 PendingFontChanges_.clear ();
224 PendingSizeChanges_.clear ();
225 IsFontZoomDirty_ =
false;
auto Stlize(Assoc &&assoc) -> detail::StlAssocRange< detail::Identity, detail::Identity, decltype(assoc.begin()), Assoc, PairType >
Converts an Qt's associative sequence assoc to an STL-like iteratable range.
Interface to aid WebKit-like-view-containing tabs to expose the view fonts configuration to the user...
virtual void SetFontFamily(FontFamily family, const QFont &font)=0
Sets the font for the given font family.
FontSize
Enumeration for possible font sizes.