31 #include <xmlsettingsdialog/basesettingsmanager.h> 35 #include "ui_wkfontswidget.h" 44 , Ui_ { std::make_shared<Ui::WkFontsWidget> () }
49 Family2Chooser_ [QWebSettings::StandardFont] = Ui_->StandardChooser_;
50 Family2Chooser_ [QWebSettings::FixedFont] = Ui_->FixedChooser_;
51 Family2Chooser_ [QWebSettings::SerifFont] = Ui_->SerifChooser_;
52 Family2Chooser_ [QWebSettings::SansSerifFont] = Ui_->SansSerifChooser_;
53 Family2Chooser_ [QWebSettings::CursiveFont] = Ui_->CursiveChooser_;
54 Family2Chooser_ [QWebSettings::FantasyFont] = Ui_->FantasyChooser_;
56 Family2Name_ [QWebSettings::StandardFont] =
"StandardFont";
57 Family2Name_ [QWebSettings::FixedFont] =
"FixedFont";
58 Family2Name_ [QWebSettings::SerifFont] =
"SerifFont";
59 Family2Name_ [QWebSettings::SansSerifFont] =
"SansSerifFont";
60 Family2Name_ [QWebSettings::CursiveFont] =
"CursiveFont";
61 Family2Name_ [QWebSettings::FantasyFont] =
"FantasyFont";
68 [
this, pair] { PendingFontChanges_ [pair.first] = pair.second->GetFont (); },
74 Size2Spinbox_ [QWebSettings::DefaultFontSize] = Ui_->SizeDefault_;
75 Size2Spinbox_ [QWebSettings::DefaultFixedFontSize] = Ui_->SizeFixedWidth_;
76 Size2Spinbox_ [QWebSettings::MinimumFontSize] = Ui_->SizeMinimum_;
78 Size2Name_ [QWebSettings::DefaultFontSize] =
"FontSize";
79 Size2Name_ [QWebSettings::DefaultFixedFontSize] =
"FixedFontSize";
80 Size2Name_ [QWebSettings::MinimumFontSize] =
"MinimumFontSize";
87 [
this, pair] { PendingSizeChanges_ [pair.first] = pair.second->value (); },
89 SIGNAL (valueChanged (
int)),
97 [
this] { IsFontZoomDirty_ =
true; },
99 SIGNAL (valueChanged (
int)),
106 Ui_->Zoom_->setToolTip (label);
111 Settables_ << settable;
114 [settable,
this] { Settables_.removeAll (settable); },
115 settable->GetQObject (),
116 SIGNAL (destroyed ()),
121 settable->SetFontFamily (pair.first, pair.second->GetFont ());
124 settable->SetFontSize (pair.first, pair.second->value ());
126 settable->SetFontSizeMultiplier (Ui_->Zoom_->value () / 100.);
129 void WkFontsWidget::ResetFontChoosers ()
133 const auto& option = Family2Name_ [pair.first];
134 pair.second->SetFont (BSM_->property (option).value<QFont> ());
138 void WkFontsWidget::ResetSizeChoosers ()
142 const auto& option = Size2Name_ [pair.first];
143 pair.second->setValue (BSM_->Property (option, 10).toInt ());
147 void WkFontsWidget::ResetZoom ()
149 const auto factor = BSM_->Property (
"FontSizeMultiplier", 1).toDouble ();
150 Ui_->Zoom_->setValue (factor * 100);
153 void WkFontsWidget::on_ChangeAll__released ()
158 Family2Chooser_ [QWebSettings::StandardFont]->GetFont (),
159 Family2Chooser_.keys (),
163 QHash<QString, QList<QWebSettings::FontFamily>> families;
165 families [pair.second->GetFont ().family ()] << pair.first;
168 const auto& maxElem = std::max_element (stlized.begin (), stlized.end (),
169 [] (
auto left,
auto right) {
return left.second.size () < right.second.size (); });
178 dialog->deleteLater ();
179 if (dialog->result () == QDialog::Rejected)
182 const auto& font = dialog->GetFont ();
183 for (
const auto family : dialog->GetFamilies ())
185 PendingFontChanges_ [family] = font;
186 Family2Chooser_ [family]->SetFont (font);
190 SIGNAL (finished (
int)),
197 for (
const auto& pair :
Util::Stlize (PendingFontChanges_))
199 BSM_->setProperty (Family2Name_ [pair.first], pair.second);
202 for (
const auto settable : Settables_)
203 settable->SetFontFamily (pair.first, pair.second);
206 for (
const auto& pair :
Util::Stlize (PendingSizeChanges_))
208 BSM_->setProperty (Size2Name_ [pair.first], pair.second);
211 for (
const auto settable : Settables_)
212 settable->SetFontSize (pair.first, pair.second);
215 if (IsFontZoomDirty_)
217 const auto factor = Ui_->Zoom_->value () / 100.;
219 BSM_->setProperty (
"FontSizeMultiplier", factor);
222 for (
const auto settable : Settables_)
223 settable->SetFontSizeMultiplier (factor);
226 PendingFontChanges_.clear ();
227 PendingSizeChanges_.clear ();
228 IsFontZoomDirty_ =
false;
233 ResetFontChoosers ();
234 ResetSizeChoosers ();
237 PendingFontChanges_.clear ();
238 PendingSizeChanges_.clear ();
239 IsFontZoomDirty_ =
false;
Interface to aid WebKit-view-containing tabs to expose the view fonts configuration to the user...
Executes a given functor upon a signal (or a list of signals).
auto Stlize(Assoc &&assoc) -> detail::StlAssocRange< decltype(assoc.begin()), Assoc, PairType >
Converts an Qt's associative sequence assoc to an STL-like iteratable range.