Changeset View
Changeset View
Standalone View
Standalone View
kcms/fonts/fonts.cpp
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | |||||
42 | #include <KAboutData> | 42 | #include <KAboutData> | ||
43 | #include <KLocalizedString> | 43 | #include <KLocalizedString> | ||
44 | #include <KPluginFactory> | 44 | #include <KPluginFactory> | ||
45 | #include <KFontDialog> | 45 | #include <KFontDialog> | ||
46 | #include <KWindowSystem> | 46 | #include <KWindowSystem> | ||
47 | 47 | | |||
48 | #include "../krdb/krdb.h" | 48 | #include "../krdb/krdb.h" | ||
49 | #include "previewimageprovider.h" | 49 | #include "previewimageprovider.h" | ||
50 | #include "kxftconfig.h" | ||||
50 | 51 | | |||
51 | #include "fontssettings.h" | 52 | #include "fontssettings.h" | ||
53 | #include "fontsaasettings.h" | ||||
52 | 54 | | |||
53 | /**** DLL Interface ****/ | 55 | /**** DLL Interface ****/ | ||
54 | K_PLUGIN_FACTORY_WITH_JSON(KFontsFactory, "kcm_fonts.json", registerPlugin<KFonts>();) | 56 | K_PLUGIN_FACTORY_WITH_JSON(KFontsFactory, "kcm_fonts.json", registerPlugin<KFonts>();) | ||
55 | 57 | | |||
56 | //from KFontRequester | 58 | //from KFontRequester | ||
57 | // Determine if the font with given properties is available on the system, | 59 | // Determine if the font with given properties is available on the system, | ||
58 | // otherwise find and return the best fitting combination. | 60 | // otherwise find and return the best fitting combination. | ||
59 | static QFont nearestExistingFont(const QFont &font) | 61 | static QFont nearestExistingFont(const QFont &font) | ||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | 62 | { | |||
101 | // Select the font with confirmed properties. | 103 | // Select the font with confirmed properties. | ||
102 | QFont result = dbase.font(family, style, int(size)); | 104 | QFont result = dbase.font(family, style, int(size)); | ||
103 | if (dbase.isSmoothlyScalable(family, style) && result.pointSize() == floor(size)) { | 105 | if (dbase.isSmoothlyScalable(family, style) && result.pointSize() == floor(size)) { | ||
104 | result.setPointSizeF(size); | 106 | result.setPointSizeF(size); | ||
105 | } | 107 | } | ||
106 | return result; | 108 | return result; | ||
107 | } | 109 | } | ||
108 | 110 | | |||
109 | /**** FontAASettings ****/ | | |||
110 | #if defined(HAVE_FONTCONFIG) && HAVE_X11 | | |||
111 | FontAASettings::FontAASettings(QObject *parent) | | |||
112 | : QObject(parent) | | |||
113 | , m_state() | | |||
114 | , m_originalState() | | |||
115 | , m_subPixelOptionsModel(new QStandardItemModel(this)) | | |||
116 | , m_hintingOptionsModel(new QStandardItemModel(this)) | | |||
117 | { | | |||
118 | m_state.subPixel = KXftConfig::SubPixel::None; | | |||
119 | for (int t = KXftConfig::SubPixel::None; t <= KXftConfig::SubPixel::Vbgr; ++t) { | | |||
120 | QStandardItem *item = new QStandardItem(KXftConfig::description((KXftConfig::SubPixel::Type)t)); | | |||
121 | m_subPixelOptionsModel->appendRow(item); | | |||
122 | } | | |||
123 | | ||||
124 | m_state.hinting = KXftConfig::Hint::None; | | |||
125 | for (int s = KXftConfig::Hint::None; s <= KXftConfig::Hint::Full; ++s) { | | |||
126 | QStandardItem * item = new QStandardItem(KXftConfig::description((KXftConfig::Hint::Style)s)); | | |||
127 | m_hintingOptionsModel->appendRow(item); | | |||
128 | } | | |||
129 | } | | |||
130 | | ||||
131 | void FontAASettings::load() | | |||
132 | { | | |||
133 | double from, to; | | |||
134 | KXftConfig xft; | | |||
135 | | ||||
136 | if (xft.getExcludeRange(from, to)) { | | |||
137 | m_state.excludeFrom = from; | | |||
138 | m_state.excludeTo = to; | | |||
139 | setExclude(true); | | |||
140 | } else { | | |||
141 | m_state.excludeFrom = 8; | | |||
142 | m_state.excludeTo = 15; | | |||
143 | setExclude(false); | | |||
144 | } | | |||
145 | m_originalState.exclude = m_state.exclude; | | |||
146 | m_originalState.excludeFrom = m_state.excludeFrom; | | |||
147 | m_originalState.excludeTo = m_state.excludeTo; | | |||
148 | excludeToChanged(); | | |||
149 | excludeFromChanged(); | | |||
150 | | ||||
151 | // start with empty subpixel type | | |||
152 | KXftConfig::SubPixel::Type spType = KXftConfig::SubPixel::NotSet; | | |||
153 | // get subpixel type from config | | |||
154 | xft.getSubPixelType(spType); | | |||
155 | m_originalState.subPixel = spType; | | |||
156 | // if it is not set, we set it to rgb | | |||
157 | if (spType == KXftConfig::SubPixel::NotSet) { | | |||
158 | spType = KXftConfig::SubPixel::Rgb; | | |||
159 | } | | |||
160 | setSubPixel(spType); | | |||
161 | m_state.subPixelHasLocalConfig = xft.subPixelTypeHasLocalConfig(); | | |||
162 | | ||||
163 | // start with empty hint style | | |||
164 | KXftConfig::Hint::Style hStyle = KXftConfig::Hint::NotSet; | | |||
165 | // get value from config; | | |||
166 | xft.getHintStyle(hStyle); | | |||
167 | m_originalState.hinting = hStyle; | | |||
168 | // if it is not set, we set it to slight hinting | | |||
169 | if (hStyle == KXftConfig::Hint::NotSet) { | | |||
170 | hStyle = KXftConfig::Hint::Slight; | | |||
171 | } | | |||
172 | setHinting(hStyle); | | |||
173 | m_state.hintingHasLocalConfig = xft.hintStyleHasLocalConfig(); | | |||
174 | | ||||
175 | KConfig _cfgfonts("kcmfonts"); | | |||
176 | KConfigGroup cfgfonts(&_cfgfonts, "General"); | | |||
177 | | ||||
178 | int dpicfg; | | |||
179 | if (KWindowSystem::isPlatformWayland()) { | | |||
180 | dpicfg = cfgfonts.readEntry("forceFontDPIWayland", 0); | | |||
181 | } else { | | |||
182 | dpicfg = cfgfonts.readEntry("forceFontDPI", 0); | | |||
183 | } | | |||
184 | | ||||
185 | if (dpicfg <= 0) { | | |||
186 | m_originalState.dpi = 0; | | |||
187 | } else { | | |||
188 | m_originalState.dpi = dpicfg; | | |||
189 | }; | | |||
190 | | ||||
191 | setDpi(dpicfg); | | |||
192 | | ||||
193 | KSharedConfig::Ptr config = KSharedConfig::openConfig("kdeglobals"); | | |||
194 | KConfigGroup cg(config, "General"); | | |||
195 | | ||||
196 | if (cfgfonts.readEntry("dontChangeAASettings", true)) { | | |||
197 | setAntiAliasing(true); //AASystem | | |||
198 | m_state.antiAliasingHasLocalConfig = false; | | |||
199 | } else if (cg.readEntry("XftAntialias", true)) { | | |||
200 | setAntiAliasing(true); //AAEnabled | | |||
201 | m_state.antiAliasingHasLocalConfig = xft.antiAliasingHasLocalConfig(); | | |||
202 | } else { | | |||
203 | setAntiAliasing(false); //AADisabled | | |||
204 | m_state.antiAliasingHasLocalConfig = xft.antiAliasingHasLocalConfig(); | | |||
205 | } | | |||
206 | m_originalState.antiAliasing = m_state.antiAliasing; | | |||
207 | m_originalState.antiAliasingHasLocalConfig = m_state.antiAliasingHasLocalConfig; | | |||
208 | } | | |||
209 | | ||||
210 | bool FontAASettings::save(KXftConfig::AntiAliasing::State aaState) | | |||
211 | { | | |||
212 | KXftConfig xft; | | |||
213 | | ||||
214 | KSharedConfig::Ptr config = KSharedConfig::openConfig("kdeglobals"); | | |||
215 | KConfigGroup grp(config, "General"); | | |||
216 | | ||||
217 | xft.setAntiAliasing(aaState); | | |||
218 | if (m_state.exclude) { | | |||
219 | xft.setExcludeRange(m_state.excludeFrom, m_state.excludeTo); | | |||
220 | } else { | | |||
221 | xft.setExcludeRange(0, 0); | | |||
222 | } | | |||
223 | | ||||
224 | KXftConfig::SubPixel::Type spType = (KXftConfig::SubPixel::Type)m_state.subPixel; | | |||
225 | | ||||
226 | if (subPixelNeedsSave()) { | | |||
227 | xft.setSubPixelType(spType); | | |||
228 | } else { | | |||
229 | xft.setSubPixelType(KXftConfig::SubPixel::NotSet); | | |||
230 | } | | |||
231 | grp.writeEntry("XftSubPixel", KXftConfig::toStr(spType)); | | |||
232 | if (aaState == KXftConfig::AntiAliasing::NotSet) { | | |||
233 | grp.revertToDefault("XftAntialias"); | | |||
234 | } else { | | |||
235 | grp.writeEntry("XftAntialias", aaState == KXftConfig::AntiAliasing::Enabled); | | |||
236 | } | | |||
237 | | ||||
238 | bool mod = false; | | |||
239 | KXftConfig::Hint::Style hStyle = (KXftConfig::Hint::Style)m_state.hinting; | | |||
240 | | ||||
241 | if (hintingNeedsSave()) { | | |||
242 | xft.setHintStyle(hStyle); | | |||
243 | } else { | | |||
244 | xft.setHintStyle(KXftConfig::Hint::NotSet); | | |||
245 | } | | |||
246 | | ||||
247 | QString hs(KXftConfig::toStr(hStyle)); | | |||
248 | | ||||
249 | if (hs != grp.readEntry("XftHintStyle")) { | | |||
250 | if (KXftConfig::Hint::NotSet == hStyle) { | | |||
251 | grp.revertToDefault("XftHintStyle"); | | |||
252 | } else { | | |||
253 | grp.writeEntry("XftHintStyle", hs); | | |||
254 | } | | |||
255 | } | | |||
256 | mod = true; | | |||
257 | config->sync(); | | |||
258 | | ||||
259 | if (!mod) { | | |||
260 | mod = xft.changed(); | | |||
261 | } | | |||
262 | | ||||
263 | xft.apply(); | | |||
264 | | ||||
265 | KConfig _cfgfonts("kcmfonts"); | | |||
266 | KConfigGroup cfgfonts(&_cfgfonts, "General"); | | |||
267 | | ||||
268 | if (KWindowSystem::isPlatformWayland()) { | | |||
269 | cfgfonts.writeEntry("forceFontDPIWayland", m_state.dpi); | | |||
270 | } else { | | |||
271 | cfgfonts.writeEntry("forceFontDPI", m_state.dpi); | | |||
272 | } | | |||
273 | | ||||
274 | cfgfonts.sync(); | | |||
275 | | ||||
276 | #if HAVE_X11 | | |||
277 | // if the setting is reset in the module, remove the dpi value, | | |||
278 | // otherwise don't explicitly remove it and leave any possible system-wide value | | |||
279 | if (m_state.dpi == 0 && m_originalState.dpi != 0 && !KWindowSystem::isPlatformWayland()) { | | |||
280 | QProcess proc; | | |||
281 | proc.setProcessChannelMode(QProcess::ForwardedChannels); | | |||
282 | proc.start("xrdb", QStringList() << "-quiet" << "-remove" << "-nocpp"); | | |||
283 | if (proc.waitForStarted()) { | | |||
284 | proc.write(QByteArray("Xft.dpi\n")); | | |||
285 | proc.closeWriteChannel(); | | |||
286 | proc.waitForFinished(); | | |||
287 | } | | |||
288 | } | | |||
289 | #endif | | |||
290 | | ||||
291 | QApplication::processEvents(); // Process font change ourselves | | |||
292 | | ||||
293 | // Don't overwrite global settings unless explicitly asked for - e.g. the system | | |||
294 | // fontconfig setup may be much more complex than this module can provide. | | |||
295 | // TODO: With AASystem the changes already made by this module should be reverted somehow. | | |||
296 | #if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) | | |||
297 | if (mod || (m_state.antiAliasing != m_originalState.antiAliasing) || m_state.dpi != m_originalState.dpi) { | | |||
298 | m_originalState.antiAliasing = m_state.antiAliasing; | | |||
299 | m_originalState.dpi = m_state.dpi; | | |||
300 | emit aliasingChangeApplied(); | | |||
301 | } | | |||
302 | #else | | |||
303 | #if HAVE_X11 | | |||
304 | if (m_state.dpi != m_originalState.dpi) { | | |||
305 | m_originalState.dpi = m_state.dpi; | | |||
306 | } | | |||
307 | #endif | | |||
308 | #endif | | |||
309 | | ||||
310 | m_originalState.exclude = m_state.exclude; | | |||
311 | m_originalState.excludeTo = m_state.excludeTo; | | |||
312 | m_originalState.excludeFrom = m_state.excludeFrom; | | |||
313 | | ||||
314 | m_originalState.subPixel = m_state.subPixel; | | |||
315 | m_originalState.hinting = m_state.hinting; | | |||
316 | | ||||
317 | return mod; | | |||
318 | } | | |||
319 | | ||||
320 | void FontAASettings::defaults() | | |||
321 | { | | |||
322 | setExclude(false); | | |||
323 | setExcludeTo(15); | | |||
324 | setExcludeFrom(8); | | |||
325 | setAntiAliasing(true); | | |||
326 | m_originalState.antiAliasing = m_state.antiAliasing; | | |||
327 | m_state.antiAliasingHasLocalConfig = false; | | |||
328 | setDpi(0); | | |||
329 | setSubPixel(KXftConfig::SubPixel::Rgb); | | |||
330 | m_state.subPixelHasLocalConfig = false; | | |||
331 | setHinting(KXftConfig::Hint::Slight); | | |||
332 | m_state.hintingHasLocalConfig = false; | | |||
333 | } | | |||
334 | | ||||
335 | #endif | | |||
336 | | ||||
337 | void FontAASettings::setExclude(bool exclude) | | |||
338 | { | | |||
339 | if (exclude == m_state.exclude) { | | |||
340 | return; | | |||
341 | } | | |||
342 | | ||||
343 | m_state.exclude = exclude; | | |||
344 | emit excludeChanged(); | | |||
345 | } | | |||
346 | | ||||
347 | bool FontAASettings::exclude() const | | |||
348 | { | | |||
349 | return m_state.exclude; | | |||
350 | } | | |||
351 | | ||||
352 | void FontAASettings::setExcludeTo(int excludeTo) | | |||
353 | { | | |||
354 | if (m_state.excludeTo == excludeTo) { | | |||
355 | return; | | |||
356 | } | | |||
357 | | ||||
358 | m_state.excludeTo = excludeTo; | | |||
359 | emit excludeToChanged(); | | |||
360 | } | | |||
361 | | ||||
362 | int FontAASettings::excludeTo() const | | |||
363 | { | | |||
364 | return m_state.excludeTo; | | |||
365 | } | | |||
366 | | ||||
367 | void FontAASettings::setExcludeFrom(int excludeFrom) | | |||
368 | { | | |||
369 | if (m_state.excludeFrom == excludeFrom) { | | |||
370 | return; | | |||
371 | } | | |||
372 | | ||||
373 | m_state.excludeFrom = excludeFrom; | | |||
374 | emit excludeFromChanged(); | | |||
375 | } | | |||
376 | | ||||
377 | int FontAASettings::excludeFrom() const | | |||
378 | { | | |||
379 | return m_state.excludeFrom; | | |||
380 | } | | |||
381 | | ||||
382 | void FontAASettings::setAntiAliasing(bool antiAliasing) | | |||
383 | { | | |||
384 | if (m_state.antiAliasing == antiAliasing) { | | |||
385 | return; | | |||
386 | } | | |||
387 | | ||||
388 | m_state.antiAliasing = antiAliasing; | | |||
389 | emit aliasingChanged(); | | |||
390 | } | | |||
391 | | ||||
392 | bool FontAASettings::antiAliasing() const | | |||
393 | { | | |||
394 | return m_state.antiAliasing; | | |||
395 | } | | |||
396 | | ||||
397 | bool FontAASettings::antiAliasingNeedsSave() const | | |||
398 | { | | |||
399 | return m_state.antiAliasingHasLocalConfig || (m_state.antiAliasing != m_originalState.antiAliasing); | | |||
400 | } | | |||
401 | | ||||
402 | bool FontAASettings::subPixelNeedsSave() const | | |||
403 | { | | |||
404 | return m_state.subPixelHasLocalConfig || (m_state.subPixel != m_originalState.subPixel); | | |||
405 | } | | |||
406 | | ||||
407 | bool FontAASettings::hintingNeedsSave() const | | |||
408 | { | | |||
409 | return m_state.hintingHasLocalConfig || (m_state.hinting != m_originalState.hinting); | | |||
410 | } | | |||
411 | | ||||
412 | void FontAASettings::setDpi(const int &dpi) | | |||
413 | { | | |||
414 | if (m_state.dpi == dpi) { | | |||
415 | return; | | |||
416 | } | | |||
417 | | ||||
418 | m_state.dpi = dpi; | | |||
419 | emit dpiChanged(); | | |||
420 | } | | |||
421 | | ||||
422 | int FontAASettings::dpi() const | | |||
423 | { | | |||
424 | return m_state.dpi; | | |||
425 | } | | |||
426 | | ||||
427 | void FontAASettings::setSubPixel(int idx) | | |||
428 | { | | |||
429 | if (m_state.subPixel == idx) { | | |||
430 | return; | | |||
431 | } | | |||
432 | | ||||
433 | m_state.subPixel = idx; | | |||
434 | emit subPixelCurrentIndexChanged(); | | |||
435 | } | | |||
436 | | ||||
437 | void FontAASettings::setSubPixelCurrentIndex(int idx) | | |||
438 | { | | |||
439 | setSubPixel(KXftConfig::SubPixel::None + idx); | | |||
440 | } | | |||
441 | | ||||
442 | int FontAASettings::subPixelCurrentIndex() | | |||
443 | { | | |||
444 | return m_state.subPixel - KXftConfig::SubPixel::None; | | |||
445 | } | | |||
446 | | ||||
447 | void FontAASettings::setHinting(int idx) | | |||
448 | { | | |||
449 | if (m_state.hinting == idx) { | | |||
450 | return; | | |||
451 | } | | |||
452 | | ||||
453 | m_state.hinting = idx; | | |||
454 | emit hintingCurrentIndexChanged(); | | |||
455 | } | | |||
456 | | ||||
457 | void FontAASettings::setHintingCurrentIndex(int idx) | | |||
458 | { | | |||
459 | setHinting(KXftConfig::Hint::None + idx); | | |||
460 | } | | |||
461 | | ||||
462 | int FontAASettings::hintingCurrentIndex() | | |||
463 | { | | |||
464 | return m_state.hinting - KXftConfig::Hint::None; | | |||
465 | } | | |||
466 | | ||||
467 | bool FontAASettings::needsSave() const | | |||
468 | { | | |||
469 | return m_state != m_originalState; | | |||
470 | } | | |||
471 | | ||||
472 | bool FontAASettings::isDefaults() const | | |||
473 | { | | |||
474 | State defaultState{}; | | |||
475 | defaultState.exclude = false; | | |||
476 | defaultState.excludeTo = 15; | | |||
477 | defaultState.excludeFrom = 8; | | |||
478 | defaultState.antiAliasing = true; | | |||
479 | defaultState.dpi = 0; | | |||
480 | defaultState.subPixel = KXftConfig::SubPixel::Rgb; | | |||
481 | defaultState.hinting = KXftConfig::Hint::Slight; | | |||
482 | return m_state == defaultState; | | |||
483 | } | | |||
484 | | ||||
485 | bool FontAASettings::State::operator==(const State& other) const | | |||
486 | { | | |||
487 | if ( | | |||
488 | exclude != other.exclude | | |||
489 | || antiAliasing != other.antiAliasing | | |||
490 | || dpi != other.dpi | | |||
491 | || subPixel != other.subPixel | | |||
492 | || hinting != other.hinting | | |||
493 | ) { | | |||
494 | return false; | | |||
495 | } | | |||
496 | | ||||
497 | if (exclude && (excludeFrom != other.excludeFrom || excludeTo != other.excludeTo)) { | | |||
498 | return false; | | |||
499 | } | | |||
500 | | ||||
501 | return true; | | |||
502 | } | | |||
503 | | ||||
504 | bool FontAASettings::State::operator!=(const State& other) const | | |||
505 | { | | |||
506 | return !(*this == other); | | |||
507 | } | | |||
508 | | ||||
509 | /**** KFonts ****/ | 111 | /**** KFonts ****/ | ||
510 | 112 | | |||
511 | KFonts::KFonts(QObject *parent, const QVariantList &args) | 113 | KFonts::KFonts(QObject *parent, const QVariantList &args) | ||
512 | : KQuickAddons::ManagedConfigModule(parent, args) | 114 | : KQuickAddons::ManagedConfigModule(parent, args) | ||
513 | , m_settings(new FontsSettings(this)) | 115 | , m_settings(new FontsSettings(this)) | ||
514 | , m_fontAASettings(new FontAASettings(this)) | 116 | , m_settingsAA(new FontsAASettings(this)) | ||
117 | , m_subPixelOptionsModel(new QStandardItemModel(this)) | ||||
118 | , m_hintingOptionsModel(new QStandardItemModel(this)) | ||||
515 | { | 119 | { | ||
516 | KAboutData* about = new KAboutData("kcm_fonts", i18n("Fonts"), | 120 | KAboutData* about = new KAboutData("kcm_fonts", i18n("Fonts"), | ||
517 | "0.1", QString(), KAboutLicense::LGPL); | 121 | "0.1", QString(), KAboutLicense::LGPL); | ||
518 | about->addAuthor(i18n("Antonis Tsiapaliokas"), QString(), "antonis.tsiapaliokas@kde.org"); | 122 | about->addAuthor(i18n("Antonis Tsiapaliokas"), QString(), "antonis.tsiapaliokas@kde.org"); | ||
519 | setAboutData(about); | 123 | setAboutData(about); | ||
520 | qmlRegisterType<QStandardItemModel>(); | 124 | qmlRegisterType<QStandardItemModel>(); | ||
521 | qmlRegisterType<FontsSettings>(); | 125 | qmlRegisterType<FontsSettings>(); | ||
126 | qmlRegisterType<FontsAASettings>(); | ||||
522 | 127 | | |||
523 | setButtons(Apply | Default | Help); | 128 | setButtons(Apply | Default | Help); | ||
524 | 129 | | |||
525 | connect(m_fontAASettings, &FontAASettings::subPixelCurrentIndexChanged, this, &KFonts::settingsChanged); | 130 | for (KXftConfig::SubPixel::Type t : {KXftConfig::SubPixel::None, KXftConfig::SubPixel::Rgb, KXftConfig::SubPixel::Bgr, KXftConfig::SubPixel::Vrgb, KXftConfig::SubPixel::Vbgr}) { | ||
526 | connect(m_fontAASettings, &FontAASettings::hintingCurrentIndexChanged, this, &KFonts::settingsChanged); | 131 | auto item = new QStandardItem(KXftConfig::description(t)); | ||
ervin: Please no C cast, use static_cast instead.
Also was a good place to use auto (DRY and all that)… | |||||
527 | connect(m_fontAASettings, &FontAASettings::excludeChanged, this, &KFonts::settingsChanged); | 132 | m_subPixelOptionsModel->appendRow(item); | ||
528 | connect(m_fontAASettings, &FontAASettings::excludeFromChanged, this, &KFonts::settingsChanged); | 133 | } | ||
529 | connect(m_fontAASettings, &FontAASettings::excludeToChanged, this, &KFonts::settingsChanged); | 134 | | ||
530 | connect(m_fontAASettings, &FontAASettings::antiAliasingChanged, this, &KFonts::settingsChanged); | 135 | for (KXftConfig::Hint::Style s : {KXftConfig::Hint::None, KXftConfig::Hint::Slight, KXftConfig::Hint::Medium, KXftConfig::Hint::Full}) { | ||
531 | connect(m_fontAASettings, &FontAASettings::aliasingChanged, this, &KFonts::settingsChanged); | 136 | auto item = new QStandardItem(KXftConfig::description(s)); | ||
ervin: ditto (and no space after *) | |||||
This C cast is unnecessary. Also the * is merely redundant with auto (you can keep it but it's not necessary). ervin: This C cast is unnecessary. Also the * is merely redundant with auto (you can keep it but it's… | |||||
532 | connect(m_fontAASettings, &FontAASettings::dpiChanged, this, &KFonts::settingsChanged); | 137 | m_hintingOptionsModel->appendRow(item); | ||
138 | } | ||||
139 | connect(m_settingsAA, &FontsAASettings::hintingChanged, this, &KFonts::hintingCurrentIndexChanged); | ||||
140 | connect(m_settingsAA, &FontsAASettings::subPixelChanged, this, &KFonts::subPixelCurrentIndexChanged); | ||||
533 | } | 141 | } | ||
534 | 142 | | |||
535 | KFonts::~KFonts() | 143 | KFonts::~KFonts() | ||
536 | { | 144 | { | ||
537 | } | 145 | } | ||
538 | 146 | | |||
539 | FontsSettings *KFonts::fontsSettings() const | 147 | FontsSettings *KFonts::fontsSettings() const | ||
540 | { | 148 | { | ||
541 | return m_settings; | 149 | return m_settings; | ||
542 | } | 150 | } | ||
543 | 151 | | |||
544 | void KFonts::defaults() | 152 | FontsAASettings *KFonts::fontsAASettings() const | ||
153 | { | ||||
154 | return m_settingsAA; | ||||
155 | } | ||||
156 | | ||||
157 | QAbstractItemModel *KFonts::subPixelOptionsModel() const | ||||
545 | { | 158 | { | ||
546 | ManagedConfigModule::defaults(); | 159 | return m_subPixelOptionsModel; | ||
547 | m_fontAASettings->defaults(); | 160 | } | ||
161 | | ||||
162 | QAbstractItemModel *KFonts::hintingOptionsModel() const | ||||
163 | { | ||||
164 | return m_hintingOptionsModel; | ||||
548 | } | 165 | } | ||
549 | 166 | | |||
550 | void KFonts::setNearestExistingFonts() | 167 | void KFonts::setNearestExistingFonts() | ||
551 | { | 168 | { | ||
552 | m_settings->setFont(nearestExistingFont(m_settings->font())); | 169 | m_settings->setFont(nearestExistingFont(m_settings->font())); | ||
553 | m_settings->setFixed(nearestExistingFont(m_settings->fixed())); | 170 | m_settings->setFixed(nearestExistingFont(m_settings->fixed())); | ||
554 | m_settings->setSmallestReadableFont(nearestExistingFont(m_settings->smallestReadableFont())); | 171 | m_settings->setSmallestReadableFont(nearestExistingFont(m_settings->smallestReadableFont())); | ||
555 | m_settings->setToolBarFont(nearestExistingFont(m_settings->toolBarFont())); | 172 | m_settings->setToolBarFont(nearestExistingFont(m_settings->toolBarFont())); | ||
556 | m_settings->setMenuFont(nearestExistingFont(m_settings->menuFont())); | 173 | m_settings->setMenuFont(nearestExistingFont(m_settings->menuFont())); | ||
557 | m_settings->setActiveFont(nearestExistingFont(m_settings->activeFont())); | 174 | m_settings->setActiveFont(nearestExistingFont(m_settings->activeFont())); | ||
558 | } | 175 | } | ||
559 | 176 | | |||
560 | void KFonts::load() | 177 | void KFonts::load() | ||
561 | { | 178 | { | ||
562 | // first load all the settings | 179 | // first load all the settings | ||
563 | ManagedConfigModule::load(); | 180 | ManagedConfigModule::load(); | ||
564 | m_fontAASettings->load(); | | |||
565 | 181 | | |||
566 | // Then set the existing fonts based on those settings | 182 | // Then set the existing fonts based on those settings | ||
567 | setNearestExistingFonts(); | 183 | setNearestExistingFonts(); | ||
568 | 184 | | |||
569 | // Load preview | 185 | // Load preview | ||
570 | // NOTE: This needs to be done AFTER AA settings is loaded | 186 | // NOTE: This needs to be done AFTER AA settings is loaded | ||
571 | // otherwise AA settings will be reset in process of loading | 187 | // otherwise AA settings will be reset in process of loading | ||
572 | // previews | 188 | // previews | ||
573 | engine()->addImageProvider("preview", new PreviewImageProvider(m_settings->font())); | 189 | engine()->addImageProvider("preview", new PreviewImageProvider(m_settings->font())); | ||
574 | 190 | | |||
575 | // KCM expect save state to be false at this point (can be true because of setNearestExistingFonts | 191 | // KCM expect save state to be false at this point (can be true because of setNearestExistingFonts | ||
576 | setNeedsSave(false); | 192 | setNeedsSave(false); | ||
577 | } | 193 | } | ||
578 | 194 | | |||
579 | void KFonts::save() | 195 | void KFonts::save() | ||
580 | { | 196 | { | ||
581 | ManagedConfigModule::save(); | 197 | auto dpiItem = m_settingsAA->findItem("forceFontDPI"); | ||
198 | auto dpiWaylandItem = m_settingsAA->findItem("forceFontDPIWayland"); | ||||
199 | auto antiAliasingItem = m_settingsAA->findItem("antiAliasing"); | ||||
200 | Q_ASSERT(dpiItem && dpiWaylandItem && antiAliasingItem); | ||||
201 | if (dpiItem->isSaveNeeded() || dpiWaylandItem->isSaveNeeded() || antiAliasingItem->isSaveNeeded()) { | ||||
crossi: ```antiAliasingItem->isSaveNeeded() ?``` | |||||
202 | emit aliasingChangeApplied(); | ||||
203 | } | ||||
582 | 204 | | |||
583 | KConfig _cfgfonts("kcmfonts"); | 205 | auto forceFontDPIChanged = dpiItem->isSaveNeeded(); | ||
584 | KConfigGroup cfgfonts(&_cfgfonts, "General"); | | |||
585 | 206 | | |||
586 | FontAASettings::AASetting aaSetting = FontAASettings::AASystem; | 207 | ManagedConfigModule::save(); | ||
587 | if (m_fontAASettings->antiAliasingNeedsSave()) { | 208 | | ||
588 | aaSetting = m_fontAASettings->antiAliasing() ? FontAASettings::AAEnabled : FontAASettings::AADisabled; | 209 | #if HAVE_X11 | ||
589 | } | 210 | // if the setting is reset in the module, remove the dpi value, | ||
590 | cfgfonts.writeEntry("dontChangeAASettings", aaSetting == FontAASettings::AASystem); | 211 | // otherwise don't explicitly remove it and leave any possible system-wide value | ||
591 | 212 | if (m_settingsAA->forceFontDPI() == 0 && forceFontDPIChanged && !KWindowSystem::isPlatformWayland()) { | |||
592 | if (aaSetting == FontAASettings::AAEnabled) { | 213 | QProcess proc; | ||
593 | m_fontAASettings->save(KXftConfig::AntiAliasing::Enabled); | 214 | proc.setProcessChannelMode(QProcess::ForwardedChannels); | ||
594 | } else if (aaSetting == FontAASettings::AADisabled) { | 215 | proc.start("xrdb", QStringList() << "-quiet" << "-remove" << "-nocpp"); | ||
595 | m_fontAASettings->save(KXftConfig::AntiAliasing::Disabled); | 216 | if (proc.waitForStarted()) { | ||
596 | } else { | 217 | proc.write(QByteArray("Xft.dpi\n")); | ||
597 | m_fontAASettings->save(KXftConfig::AntiAliasing::NotSet); | 218 | proc.closeWriteChannel(); | ||
219 | proc.waitForFinished(); | ||||
220 | } | ||||
598 | } | 221 | } | ||
222 | QApplication::processEvents(); | ||||
223 | #endif | ||||
224 | | ||||
599 | 225 | | |||
600 | KGlobalSettings::self()->emitChange(KGlobalSettings::FontChanged); | 226 | KGlobalSettings::self()->emitChange(KGlobalSettings::FontChanged); | ||
601 | 227 | | |||
602 | runRdb(KRdbExportXftSettings | KRdbExportGtkTheme); | 228 | runRdb(KRdbExportXftSettings | KRdbExportGtkTheme); | ||
603 | 229 | | |||
604 | emit fontsHaveChanged(); | 230 | emit fontsHaveChanged(); | ||
605 | } | 231 | } | ||
606 | 232 | | |||
607 | bool KFonts::isSaveNeeded() const | | |||
608 | { | | |||
609 | return m_fontAASettings->needsSave(); | | |||
610 | } | | |||
611 | | ||||
612 | bool KFonts::isDefaults() const | | |||
613 | { | | |||
614 | return m_fontAASettings->isDefaults(); | | |||
615 | } | | |||
616 | | ||||
617 | void KFonts::adjustAllFonts() | 233 | void KFonts::adjustAllFonts() | ||
618 | { | 234 | { | ||
619 | QFont font = m_settings->font(); | 235 | QFont font = m_settings->font(); | ||
620 | KFontChooser::FontDiffFlags fontDiffFlags; | 236 | KFontChooser::FontDiffFlags fontDiffFlags; | ||
621 | int ret = KFontDialog::getFontDiff(font, fontDiffFlags, KFontChooser::NoDisplayFlags); | 237 | int ret = KFontDialog::getFontDiff(font, fontDiffFlags, KFontChooser::NoDisplayFlags); | ||
622 | 238 | | |||
623 | if (ret == KDialog::Accepted && fontDiffFlags) { | 239 | if (ret == KDialog::Accepted && fontDiffFlags) { | ||
624 | if (!m_settings->isImmutable("font")) { | 240 | if (!m_settings->isImmutable("font")) { | ||
Show All 33 Lines | 272 | if (fontDiffFlags & KFontChooser::FontDiffStyle) { | |||
658 | font.setStyle(newFont.style()); | 274 | font.setStyle(newFont.style()); | ||
659 | font.setUnderline(newFont.underline()); | 275 | font.setUnderline(newFont.underline()); | ||
660 | font.setStyleName(newFont.styleName()); | 276 | font.setStyleName(newFont.styleName()); | ||
661 | } | 277 | } | ||
662 | 278 | | |||
663 | return font; | 279 | return font; | ||
664 | } | 280 | } | ||
665 | 281 | | |||
282 | int KFonts::subPixelCurrentIndex() const | ||||
283 | { | ||||
284 | return m_settingsAA->subPixel() - KXftConfig::SubPixel::None; | ||||
285 | } | ||||
286 | | ||||
287 | void KFonts::setSubPixelCurrentIndex(int idx) | ||||
288 | { | ||||
289 | m_settingsAA->setSubPixel(static_cast<KXftConfig::SubPixel::Type>(KXftConfig::SubPixel::None + idx)); | ||||
290 | } | ||||
291 | | ||||
292 | int KFonts::hintingCurrentIndex() const | ||||
293 | { | ||||
294 | return m_settingsAA->hinting() - KXftConfig::Hint::None; | ||||
295 | } | ||||
296 | | ||||
297 | void KFonts::setHintingCurrentIndex(int idx) | ||||
298 | { | ||||
299 | m_settingsAA->setHinting(static_cast<KXftConfig::Hint::Style>(KXftConfig::Hint::None + idx)); | ||||
300 | } | ||||
301 | | ||||
666 | #include "fonts.moc" | 302 | #include "fonts.moc" | ||
667 | 303 | |
Please no C cast, use static_cast instead.
Also was a good place to use auto (DRY and all that) ;-)