11#include <xmlsettingsdialog/basesettingsmanager.h>
15#include "ui_wkfontswidget.h"
43 for (
const auto& [family, chooser] : Family2Chooser_.asKeyValueRange ())
46 [
this, family, chooser] { PendingFontChanges_ [family] = chooser->GetFont (); });
58 for (
const auto& [size, spinbox] : Size2Spinbox_.asKeyValueRange ())
60 &QSpinBox::valueChanged,
61 [
this, size, spinbox] { PendingSizeChanges_ [size] = spinbox->value (); });
63 connect (Ui_->ChangeAll_,
64 &QPushButton::released,
66 &WkFontsWidget::ChangeAllFonts);
71 Settables_ << settable;
74 [
this, settable] { Settables_.removeOne (settable); });
77 settable->
SetFontFamily (pair.first, pair.second->GetFont ());
80 settable->
SetFontSize (pair.first, pair.second->value ());
85 Size2Spinbox_ [type]->setValue (size);
86 PendingSizeChanges_ [type] = size;
88 QTimer::singleShot (1000,
this, [
this] { ApplyPendingSizeChanges (); });
91 void WkFontsWidget::ResetFontChoosers ()
95 const auto& option = Family2Name_ [pair.first];
96 pair.second->SetFont (BSM_->property (option.data ()).value<QFont> ());
100 void WkFontsWidget::ResetSizeChoosers ()
104 const auto& option = Size2Name_ [pair.first];
105 pair.second->setValue (BSM_->Property (option, 10).toInt ());
109 void WkFontsWidget::ApplyPendingSizeChanges ()
111 for (
const auto& pair :
Util::Stlize (PendingSizeChanges_))
113 BSM_->setProperty (Size2Name_ [pair.first].data (), pair.second);
116 for (
const auto settable : Settables_)
117 settable->SetFontSize (pair.first, pair.second);
120 PendingSizeChanges_.clear ();
123 void WkFontsWidget::ChangeAllFonts ()
125 QHash<QString, QList<IWkFontsSettable::FontFamily>> families;
127 families [pair.second->GetFont ().family ()] << pair.first;
130 const auto& maxPair = *std::max_element (stlized.begin (), stlized.end (),
131 ComparingBy ([] (
auto pair) {
return pair.second.size (); }));
133 const auto dialog =
new MassFontChangeDialog { maxPair.first, maxPair.second,
this };
137 [dialog,
this] (
int result)
139 if (result == QDialog::Rejected)
142 const auto& font = dialog->GetFont ();
143 for (
const auto family : dialog->GetFamilies ())
145 PendingFontChanges_ [family] = font;
146 Family2Chooser_ [family]->SetFont (font);
153 ApplyPendingSizeChanges ();
155 for (
const auto& pair :
Util::Stlize (PendingFontChanges_))
157 BSM_->setProperty (Family2Name_ [pair.first].data (), pair.second);
160 for (
const auto settable : Settables_)
161 settable->SetFontFamily (pair.first, pair.second);
164 PendingFontChanges_.clear ();
169 ResetFontChoosers ();
170 ResetSizeChoosers ();
172 PendingFontChanges_.clear ();
173 PendingSizeChanges_.clear ();
Interface to aid WebKit-like-view-containing tabs to expose the view fonts configuration to the user.
virtual void SetFontSize(FontSize type, int size)=0
Sets the size for the given font size type.
virtual QObject * GetQObject()=0
Returns this tab as a QObject.
virtual void SetFontFamily(FontFamily family, const QFont &font)=0
Sets the font for the given font family.
FontSize
Enumeration for possible font sizes.
auto Stlize(Assoc &&assoc) noexcept
Converts an Qt's associative sequence assoc to an STL-like iteratable range.