Changeset View
Changeset View
Standalone View
Standalone View
kcms/fonts/fonts.cpp
Show First 20 Lines • Show All 106 Lines • ▼ Show 20 Line(s) | |||||
107 | 107 | | |||
108 | /**** FontAASettings ****/ | 108 | /**** FontAASettings ****/ | ||
109 | #if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) | 109 | #if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) | ||
110 | FontAASettings::FontAASettings(QObject *parent) | 110 | FontAASettings::FontAASettings(QObject *parent) | ||
111 | : QObject(parent) | 111 | : QObject(parent) | ||
112 | , m_subPixelOptionsModel(new QStandardItemModel(this)) | 112 | , m_subPixelOptionsModel(new QStandardItemModel(this)) | ||
113 | , m_hintingOptionsModel(new QStandardItemModel(this)) | 113 | , m_hintingOptionsModel(new QStandardItemModel(this)) | ||
114 | { | 114 | { | ||
115 | for (int t = KXftConfig::SubPixel::NotSet; t <= KXftConfig::SubPixel::Vbgr; ++t) { | 115 | m_state.subPixel = KXftConfig::SubPixel::None; | ||
116 | for (int t = KXftConfig::SubPixel::None; t <= KXftConfig::SubPixel::Vbgr; ++t) { | ||||
116 | QStandardItem *item = new QStandardItem(KXftConfig::description((KXftConfig::SubPixel::Type)t)); | 117 | QStandardItem *item = new QStandardItem(KXftConfig::description((KXftConfig::SubPixel::Type)t)); | ||
117 | m_subPixelOptionsModel->appendRow(item); | 118 | m_subPixelOptionsModel->appendRow(item); | ||
118 | } | 119 | } | ||
119 | 120 | | |||
120 | for (int s = KXftConfig::Hint::NotSet; s <= KXftConfig::Hint::Full; ++s) { | 121 | m_state.hinting = KXftConfig::Hint::None; | ||
122 | for (int s = KXftConfig::Hint::None; s <= KXftConfig::Hint::Full; ++s) { | ||||
121 | QStandardItem * item = new QStandardItem(KXftConfig::description((KXftConfig::Hint::Style)s)); | 123 | QStandardItem * item = new QStandardItem(KXftConfig::description((KXftConfig::Hint::Style)s)); | ||
122 | m_hintingOptionsModel->appendRow(item); | 124 | m_hintingOptionsModel->appendRow(item); | ||
123 | } | 125 | } | ||
124 | } | 126 | } | ||
125 | 127 | | |||
126 | void FontAASettings::load() | 128 | void FontAASettings::load() | ||
127 | { | 129 | { | ||
128 | double from, to; | 130 | double from, to; | ||
129 | KXftConfig xft; | 131 | KXftConfig xft; | ||
130 | 132 | | |||
131 | if (xft.getExcludeRange(from, to)) { | 133 | if (xft.getExcludeRange(from, to)) { | ||
132 | m_excludeFrom = from; | 134 | m_state.excludeFrom = from; | ||
133 | m_excludeTo = to; | 135 | m_state.excludeTo = to; | ||
134 | setExclude(true); | 136 | setExclude(true); | ||
135 | } else { | 137 | } else { | ||
136 | m_excludeFrom = 8; | 138 | m_state.excludeFrom = 8; | ||
137 | m_excludeTo = 15; | 139 | m_state.excludeTo = 15; | ||
138 | setExclude(false); | 140 | setExclude(false); | ||
139 | } | 141 | } | ||
140 | m_excludeFromOriginal = m_excludeFrom; | 142 | m_originalState.exclude = m_state.exclude; | ||
141 | m_excludeToOriginal = m_excludeTo; | 143 | m_originalState.excludeFrom = m_state.excludeFrom; | ||
144 | m_originalState.excludeTo = m_state.excludeTo; | ||||
142 | excludeToChanged(); | 145 | excludeToChanged(); | ||
143 | excludeFromChanged(); | 146 | excludeFromChanged(); | ||
144 | 147 | | |||
145 | KXftConfig::SubPixel::Type spType; | 148 | KXftConfig::SubPixel::Type spType; | ||
146 | xft.getSubPixelType(spType); | 149 | if (!xft.getSubPixelType(spType) || KXftConfig::SubPixel::NotSet == spType) { | ||
150 | spType = KXftConfig::SubPixel::Rgb; | ||||
151 | } | ||||
147 | 152 | | |||
148 | setSubPixelCurrentIndex(spType); | 153 | setSubPixel(spType); | ||
149 | m_subPixelCurrentIndexOriginal = spType; | 154 | m_originalState.subPixel = spType; | ||
155 | m_state.subPixelHasLocalConfig = xft.subPixelTypeHasLocalConfig(); | ||||
150 | 156 | | |||
151 | KXftConfig::Hint::Style hStyle; | 157 | KXftConfig::Hint::Style hStyle; | ||
152 | 158 | | |||
153 | if (!xft.getHintStyle(hStyle) || KXftConfig::Hint::NotSet == hStyle) { | 159 | if (!xft.getHintStyle(hStyle) || KXftConfig::Hint::NotSet == hStyle) { | ||
154 | KConfig kglobals("kdeglobals", KConfig::NoGlobals); | 160 | hStyle = KXftConfig::Hint::Slight; | ||
155 | | ||||
156 | hStyle = KXftConfig::Hint::NotSet; | | |||
157 | xft.setHintStyle(hStyle); | | |||
158 | KConfigGroup(&kglobals, "General").writeEntry("XftHintStyle", KXftConfig::toStr(hStyle)); | | |||
159 | kglobals.sync(); | | |||
160 | runRdb(KRdbExportXftSettings | KRdbExportGtkTheme); | | |||
161 | } | 161 | } | ||
162 | 162 | | |||
163 | setHintingCurrentIndex(hStyle); | 163 | setHinting(hStyle); | ||
164 | m_hintingCurrentIndexOriginal = hStyle; | 164 | m_originalState.hinting = hStyle; | ||
165 | m_state.hintingHasLocalConfig = xft.hintStyleHasLocalConfig(); | ||||
165 | 166 | | |||
166 | KConfig _cfgfonts("kcmfonts"); | 167 | KConfig _cfgfonts("kcmfonts"); | ||
167 | KConfigGroup cfgfonts(&_cfgfonts, "General"); | 168 | KConfigGroup cfgfonts(&_cfgfonts, "General"); | ||
168 | 169 | | |||
169 | int dpicfg; | 170 | int dpicfg; | ||
170 | if (KWindowSystem::isPlatformWayland()) { | 171 | if (KWindowSystem::isPlatformWayland()) { | ||
171 | dpicfg = cfgfonts.readEntry("forceFontDPIWayland", 0); | 172 | dpicfg = cfgfonts.readEntry("forceFontDPIWayland", 0); | ||
172 | } else { | 173 | } else { | ||
173 | dpicfg = cfgfonts.readEntry("forceFontDPI", 0); | 174 | dpicfg = cfgfonts.readEntry("forceFontDPI", 0); | ||
174 | } | 175 | } | ||
175 | 176 | | |||
176 | if (dpicfg <= 0) { | 177 | if (dpicfg <= 0) { | ||
177 | m_dpiOriginal = 0; | 178 | m_originalState.dpi = 0; | ||
178 | } else { | 179 | } else { | ||
179 | m_dpiOriginal = dpicfg; | 180 | m_originalState.dpi = dpicfg; | ||
180 | }; | 181 | }; | ||
181 | 182 | | |||
182 | setDpi(dpicfg); | 183 | setDpi(dpicfg); | ||
183 | 184 | | |||
184 | KSharedConfig::Ptr config = KSharedConfig::openConfig("kdeglobals"); | 185 | KSharedConfig::Ptr config = KSharedConfig::openConfig("kdeglobals"); | ||
185 | KConfigGroup cg(config, "General"); | 186 | KConfigGroup cg(config, "General"); | ||
186 | 187 | | |||
187 | if (cfgfonts.readEntry("dontChangeAASettings", true)) { | 188 | if (cfgfonts.readEntry("dontChangeAASettings", true)) { | ||
188 | setAntiAliasing(1); //AASystem | 189 | setAntiAliasing(true); //AASystem | ||
190 | m_state.antiAliasingHasLocalConfig = false; | ||||
189 | } else if (cg.readEntry("XftAntialias", true)) { | 191 | } else if (cg.readEntry("XftAntialias", true)) { | ||
190 | setAntiAliasing(0); //AAEnabled | 192 | setAntiAliasing(true); //AAEnabled | ||
193 | m_state.antiAliasingHasLocalConfig = xft.antiAliasingHasLocalConfig(); | ||||
191 | } else { | 194 | } else { | ||
192 | setAntiAliasing(2); //AADisabled | 195 | setAntiAliasing(false); //AADisabled | ||
196 | m_state.antiAliasingHasLocalConfig = xft.antiAliasingHasLocalConfig(); | ||||
193 | } | 197 | } | ||
194 | m_antiAliasingOriginal = m_antiAliasing; | 198 | m_originalState.antiAliasing = m_state.antiAliasing; | ||
199 | m_originalState.antiAliasingHasLocalConfig = m_state.antiAliasingHasLocalConfig; | ||||
195 | } | 200 | } | ||
196 | 201 | | |||
197 | bool FontAASettings::save(KXftConfig::AntiAliasing::State aaState) | 202 | bool FontAASettings::save(KXftConfig::AntiAliasing::State aaState) | ||
198 | { | 203 | { | ||
199 | KXftConfig xft; | 204 | KXftConfig xft; | ||
200 | KConfig kglobals("kdeglobals", KConfig::NoGlobals); | 205 | KConfig kglobals("kdeglobals", KConfig::NoGlobals); | ||
201 | KConfigGroup grp(&kglobals, "General"); | 206 | KConfigGroup grp(&kglobals, "General"); | ||
202 | 207 | | |||
203 | xft.setAntiAliasing(aaState); | 208 | xft.setAntiAliasing(aaState); | ||
204 | if (m_exclude) { | 209 | if (m_state.exclude) { | ||
205 | xft.setExcludeRange(m_excludeFrom, m_excludeTo); | 210 | xft.setExcludeRange(m_state.excludeFrom, m_state.excludeTo); | ||
206 | } else { | 211 | } else { | ||
207 | xft.setExcludeRange(0, 0); | 212 | xft.setExcludeRange(0, 0); | ||
208 | } | 213 | } | ||
209 | 214 | | |||
210 | KXftConfig::SubPixel::Type spType = (KXftConfig::SubPixel::Type)m_subPixelCurrentIndex; | 215 | KXftConfig::SubPixel::Type spType = (KXftConfig::SubPixel::Type)m_state.subPixel; | ||
211 | 216 | | |||
217 | if (subPixelNeedsSave()) { | ||||
212 | xft.setSubPixelType(spType); | 218 | xft.setSubPixelType(spType); | ||
219 | } else { | ||||
220 | xft.setSubPixelType(KXftConfig::SubPixel::NotSet); | ||||
221 | } | ||||
213 | grp.writeEntry("XftSubPixel", KXftConfig::toStr(spType)); | 222 | grp.writeEntry("XftSubPixel", KXftConfig::toStr(spType)); | ||
214 | if (aaState == KXftConfig::AntiAliasing::NotSet) { | 223 | if (aaState == KXftConfig::AntiAliasing::NotSet) { | ||
215 | grp.revertToDefault("XftAntialias"); | 224 | grp.revertToDefault("XftAntialias"); | ||
216 | } else { | 225 | } else { | ||
217 | grp.writeEntry("XftAntialias", aaState == KXftConfig::AntiAliasing::Enabled); | 226 | grp.writeEntry("XftAntialias", aaState == KXftConfig::AntiAliasing::Enabled); | ||
218 | } | 227 | } | ||
219 | 228 | | |||
220 | bool mod = false; | 229 | bool mod = false; | ||
221 | KXftConfig::Hint::Style hStyle = (KXftConfig::Hint::Style)m_hintingCurrentIndex; | 230 | KXftConfig::Hint::Style hStyle = (KXftConfig::Hint::Style)m_state.hinting; | ||
222 | 231 | | |||
232 | if (hintingNeedsSave()) { | ||||
223 | xft.setHintStyle(hStyle); | 233 | xft.setHintStyle(hStyle); | ||
234 | } else { | ||||
235 | xft.setHintStyle(KXftConfig::Hint::NotSet); | ||||
236 | } | ||||
224 | 237 | | |||
225 | QString hs(KXftConfig::toStr(hStyle)); | 238 | QString hs(KXftConfig::toStr(hStyle)); | ||
226 | 239 | | |||
227 | if (hs != grp.readEntry("XftHintStyle")) { | 240 | if (hs != grp.readEntry("XftHintStyle")) { | ||
228 | if (KXftConfig::Hint::NotSet == hStyle) { | 241 | if (KXftConfig::Hint::NotSet == hStyle) { | ||
229 | grp.revertToDefault("XftHintStyle"); | 242 | grp.revertToDefault("XftHintStyle"); | ||
230 | } else { | 243 | } else { | ||
231 | grp.writeEntry("XftHintStyle", hs); | 244 | grp.writeEntry("XftHintStyle", hs); | ||
232 | } | 245 | } | ||
233 | } | 246 | } | ||
234 | mod = true; | 247 | mod = true; | ||
235 | kglobals.sync(); | 248 | kglobals.sync(); | ||
236 | 249 | | |||
237 | if (!mod) { | 250 | if (!mod) { | ||
238 | mod = xft.changed(); | 251 | mod = xft.changed(); | ||
239 | } | 252 | } | ||
240 | 253 | | |||
241 | xft.apply(); | 254 | xft.apply(); | ||
242 | 255 | | |||
243 | KConfig _cfgfonts("kcmfonts"); | 256 | KConfig _cfgfonts("kcmfonts"); | ||
244 | KConfigGroup cfgfonts(&_cfgfonts, "General"); | 257 | KConfigGroup cfgfonts(&_cfgfonts, "General"); | ||
245 | 258 | | |||
246 | if (KWindowSystem::isPlatformWayland()) { | 259 | if (KWindowSystem::isPlatformWayland()) { | ||
247 | cfgfonts.writeEntry("forceFontDPIWayland", m_dpi); | 260 | cfgfonts.writeEntry("forceFontDPIWayland", m_state.dpi); | ||
248 | } else { | 261 | } else { | ||
249 | cfgfonts.writeEntry("forceFontDPI", m_dpi); | 262 | cfgfonts.writeEntry("forceFontDPI", m_state.dpi); | ||
250 | } | 263 | } | ||
251 | 264 | | |||
252 | cfgfonts.sync(); | 265 | cfgfonts.sync(); | ||
253 | 266 | | |||
254 | #if HAVE_X11 | 267 | #if HAVE_X11 | ||
255 | // if the setting is reset in the module, remove the dpi value, | 268 | // if the setting is reset in the module, remove the dpi value, | ||
256 | // otherwise don't explicitly remove it and leave any possible system-wide value | 269 | // otherwise don't explicitly remove it and leave any possible system-wide value | ||
257 | if (m_dpi == 0 && m_dpiOriginal != 0 && !KWindowSystem::isPlatformWayland()) { | 270 | if (m_state.dpi == 0 && m_originalState.dpi != 0 && !KWindowSystem::isPlatformWayland()) { | ||
258 | QProcess proc; | 271 | QProcess proc; | ||
259 | proc.setProcessChannelMode(QProcess::ForwardedChannels); | 272 | proc.setProcessChannelMode(QProcess::ForwardedChannels); | ||
260 | proc.start("xrdb", QStringList() << "-quiet" << "-remove" << "-nocpp"); | 273 | proc.start("xrdb", QStringList() << "-quiet" << "-remove" << "-nocpp"); | ||
261 | if (proc.waitForStarted()) { | 274 | if (proc.waitForStarted()) { | ||
262 | proc.write(QByteArray("Xft.dpi\n")); | 275 | proc.write(QByteArray("Xft.dpi\n")); | ||
263 | proc.closeWriteChannel(); | 276 | proc.closeWriteChannel(); | ||
264 | proc.waitForFinished(); | 277 | proc.waitForFinished(); | ||
265 | } | 278 | } | ||
266 | } | 279 | } | ||
267 | #endif | 280 | #endif | ||
268 | 281 | | |||
269 | QApplication::processEvents(); // Process font change ourselves | 282 | QApplication::processEvents(); // Process font change ourselves | ||
270 | 283 | | |||
271 | // Don't overwrite global settings unless explicitly asked for - e.g. the system | 284 | // Don't overwrite global settings unless explicitly asked for - e.g. the system | ||
272 | // fontconfig setup may be much more complex than this module can provide. | 285 | // fontconfig setup may be much more complex than this module can provide. | ||
273 | // TODO: With AASystem the changes already made by this module should be reverted somehow. | 286 | // TODO: With AASystem the changes already made by this module should be reverted somehow. | ||
274 | #if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) | 287 | #if defined(HAVE_FONTCONFIG) && defined (HAVE_X11) | ||
275 | if (mod || (m_antiAliasing != m_antiAliasingOriginal) || m_dpi != m_dpiOriginal) { | 288 | if (mod || (m_state.antiAliasing != m_originalState.antiAliasing) || m_state.dpi != m_originalState.dpi) { | ||
276 | KMessageBox::information(0, | 289 | KMessageBox::information(0, | ||
277 | i18n( | 290 | i18n( | ||
278 | "<p>Some changes such as anti-aliasing or DPI will only affect newly started applications.</p>" | 291 | "<p>Some changes such as anti-aliasing or DPI will only affect newly started applications.</p>" | ||
279 | ), i18n("Font Settings Changed"), "FontSettingsChanged"); | 292 | ), i18n("Font Settings Changed"), "FontSettingsChanged"); | ||
280 | m_antiAliasingOriginal = m_antiAliasing; | 293 | m_originalState.antiAliasing = m_state.antiAliasing; | ||
281 | m_dpiOriginal = m_dpi; | 294 | m_originalState.dpi = m_state.dpi; | ||
282 | } | 295 | } | ||
283 | #else | 296 | #else | ||
284 | #if HAVE_X11 | 297 | #if HAVE_X11 | ||
285 | if (m_dpi != m_dpiOriginal) { | 298 | if (m_state.dpi != m_originalState.dpi) { | ||
286 | KMessageBox::information(0, | 299 | KMessageBox::information(0, | ||
287 | i18n( | 300 | i18n( | ||
288 | "<p>Some changes such as DPI will only affect newly started applications.</p>" | 301 | "<p>Some changes such as DPI will only affect newly started applications.</p>" | ||
289 | ), i18n("Font Settings Changed"), "FontSettingsChanged"); | 302 | ), i18n("Font Settings Changed"), "FontSettingsChanged"); | ||
290 | m_dpiOriginal = m_dpi; | 303 | m_originalState.dpi = m_state.dpi; | ||
291 | } | 304 | } | ||
292 | #endif | 305 | #endif | ||
293 | #endif | 306 | #endif | ||
294 | 307 | | |||
295 | m_excludeToOriginal = m_excludeTo; | 308 | m_originalState.excludeTo = m_state.excludeTo; | ||
296 | m_excludeFromOriginal = m_excludeFrom; | 309 | m_originalState.excludeFrom = m_state.excludeFrom; | ||
297 | 310 | | |||
298 | m_subPixelCurrentIndexOriginal = m_subPixelCurrentIndex; | 311 | m_originalState.subPixel = m_state.subPixel; | ||
299 | m_hintingCurrentIndexOriginal = m_hintingCurrentIndex; | 312 | m_originalState.hinting = m_state.hinting; | ||
300 | 313 | | |||
301 | return mod; | 314 | return mod; | ||
302 | } | 315 | } | ||
303 | 316 | | |||
304 | void FontAASettings::defaults() | 317 | void FontAASettings::defaults() | ||
305 | { | 318 | { | ||
306 | setExcludeTo(15); | 319 | setExcludeTo(15); | ||
307 | setExcludeFrom(8); | 320 | setExcludeFrom(8); | ||
308 | setAntiAliasing(1); | 321 | setAntiAliasing(true); | ||
309 | m_antiAliasingOriginal = m_antiAliasing; | 322 | m_originalState.antiAliasing = m_state.antiAliasing; | ||
323 | m_state.antiAliasingHasLocalConfig = false; | ||||
310 | setDpi(0); | 324 | setDpi(0); | ||
311 | setSubPixelCurrentIndex(KXftConfig::SubPixel::NotSet); | 325 | setSubPixel(KXftConfig::SubPixel::Rgb); | ||
312 | setHintingCurrentIndex(KXftConfig::Hint::NotSet); | 326 | m_state.subPixelHasLocalConfig = false; | ||
327 | setHinting(KXftConfig::Hint::Slight); | ||||
328 | m_state.hintingHasLocalConfig = false; | ||||
313 | } | 329 | } | ||
314 | 330 | | |||
315 | #endif | 331 | #endif | ||
316 | 332 | | |||
317 | void FontAASettings::setExclude(bool exclude) | 333 | void FontAASettings::setExclude(bool exclude) | ||
318 | { | 334 | { | ||
319 | if (exclude == m_exclude) { | 335 | if (exclude == m_state.exclude) { | ||
320 | return; | 336 | return; | ||
321 | } | 337 | } | ||
322 | 338 | | |||
323 | m_exclude = exclude; | 339 | m_state.exclude = exclude; | ||
324 | emit excludeChanged(); | 340 | emit excludeChanged(); | ||
325 | } | 341 | } | ||
326 | 342 | | |||
327 | bool FontAASettings::exclude() const | 343 | bool FontAASettings::exclude() const | ||
328 | { | 344 | { | ||
329 | return m_exclude; | 345 | return m_state.exclude; | ||
330 | } | 346 | } | ||
331 | 347 | | |||
332 | void FontAASettings::setExcludeTo(const int &excludeTo) | 348 | void FontAASettings::setExcludeTo(const int &excludeTo) | ||
333 | { | 349 | { | ||
334 | if (m_excludeTo == excludeTo) { | 350 | if (m_state.excludeTo == excludeTo) { | ||
335 | return; | 351 | return; | ||
336 | } | 352 | } | ||
337 | 353 | | |||
338 | m_excludeTo = excludeTo; | 354 | m_state.excludeTo = excludeTo; | ||
339 | emit excludeToChanged(); | 355 | emit excludeToChanged(); | ||
340 | } | 356 | } | ||
341 | 357 | | |||
342 | int FontAASettings::excludeTo() const | 358 | int FontAASettings::excludeTo() const | ||
343 | { | 359 | { | ||
344 | return m_excludeTo; | 360 | return m_state.excludeTo; | ||
345 | } | 361 | } | ||
346 | 362 | | |||
347 | void FontAASettings::setExcludeFrom(const int &excludeTo) | 363 | void FontAASettings::setExcludeFrom(const int &excludeTo) | ||
348 | { | 364 | { | ||
349 | if (m_excludeFrom == excludeTo) { | 365 | if (m_state.excludeFrom == excludeTo) { | ||
350 | return; | 366 | return; | ||
351 | } | 367 | } | ||
352 | 368 | | |||
353 | m_excludeFrom = excludeTo; | 369 | m_state.excludeFrom = excludeTo; | ||
354 | emit excludeToChanged(); | 370 | emit excludeToChanged(); | ||
355 | } | 371 | } | ||
356 | 372 | | |||
357 | int FontAASettings::excludeFrom() const | 373 | int FontAASettings::excludeFrom() const | ||
358 | { | 374 | { | ||
359 | return m_excludeFrom; | 375 | return m_state.excludeFrom; | ||
360 | } | 376 | } | ||
361 | 377 | | |||
362 | void FontAASettings::setAntiAliasing(const int &antiAliasing) | 378 | void FontAASettings::setAntiAliasing(bool antiAliasing) | ||
363 | { | 379 | { | ||
364 | if (m_antiAliasing == antiAliasing) { | 380 | if (m_state.antiAliasing == antiAliasing) { | ||
365 | return; | 381 | return; | ||
366 | } | 382 | } | ||
367 | 383 | | |||
368 | m_antiAliasing = antiAliasing; | 384 | m_state.antiAliasing = antiAliasing; | ||
369 | emit aliasingChanged(); | 385 | emit aliasingChanged(); | ||
370 | } | 386 | } | ||
371 | 387 | | |||
372 | int FontAASettings::antiAliasing() const | 388 | bool FontAASettings::antiAliasing() const | ||
373 | { | 389 | { | ||
374 | return m_antiAliasing; | 390 | return m_state.antiAliasing; | ||
391 | } | ||||
392 | | ||||
393 | bool FontAASettings::antiAliasingNeedsSave() const | ||||
394 | { | ||||
395 | return m_state.antiAliasingHasLocalConfig || (m_state.antiAliasing != m_originalState.antiAliasing); | ||||
396 | } | ||||
397 | | ||||
398 | bool FontAASettings::subPixelNeedsSave() const | ||||
399 | { | ||||
400 | return m_state.subPixelHasLocalConfig || (m_state.subPixel != m_originalState.subPixel); | ||||
401 | } | ||||
402 | | ||||
403 | bool FontAASettings::hintingNeedsSave() const | ||||
404 | { | ||||
405 | return m_state.hintingHasLocalConfig || (m_state.hinting != m_originalState.hinting); | ||||
375 | } | 406 | } | ||
376 | 407 | | |||
377 | void FontAASettings::setDpi(const int &dpi) | 408 | void FontAASettings::setDpi(const int &dpi) | ||
378 | { | 409 | { | ||
379 | if (m_dpi == dpi) { | 410 | if (m_state.dpi == dpi) { | ||
380 | return; | 411 | return; | ||
381 | } | 412 | } | ||
382 | 413 | | |||
383 | m_dpi = dpi; | 414 | m_state.dpi = dpi; | ||
384 | emit dpiChanged(); | 415 | emit dpiChanged(); | ||
385 | } | 416 | } | ||
386 | 417 | | |||
387 | int FontAASettings::dpi() const | 418 | int FontAASettings::dpi() const | ||
388 | { | 419 | { | ||
389 | return m_dpi; | 420 | return m_state.dpi; | ||
390 | } | 421 | } | ||
391 | 422 | | |||
392 | void FontAASettings::setSubPixelCurrentIndex(int idx) | 423 | void FontAASettings::setSubPixel(int idx) | ||
393 | { | 424 | { | ||
394 | if (m_subPixelCurrentIndex == idx) { | 425 | if (m_state.subPixel == idx) { | ||
395 | return; | 426 | return; | ||
396 | } | 427 | } | ||
397 | 428 | | |||
398 | m_subPixelCurrentIndex = idx; | 429 | m_state.subPixel = idx; | ||
399 | emit subPixelCurrentIndexChanged(); | 430 | emit subPixelCurrentIndexChanged(); | ||
400 | } | 431 | } | ||
401 | 432 | | |||
433 | void FontAASettings::setSubPixelCurrentIndex(int idx) | ||||
434 | { | ||||
435 | setSubPixel(KXftConfig::SubPixel::None + idx); | ||||
436 | } | ||||
437 | | ||||
402 | int FontAASettings::subPixelCurrentIndex() | 438 | int FontAASettings::subPixelCurrentIndex() | ||
403 | { | 439 | { | ||
404 | return m_subPixelCurrentIndex; | 440 | return m_state.subPixel - KXftConfig::SubPixel::None; | ||
405 | } | 441 | } | ||
406 | 442 | | |||
407 | void FontAASettings::setHintingCurrentIndex(int idx) | 443 | void FontAASettings::setHinting(int idx) | ||
408 | { | 444 | { | ||
409 | if (m_hintingCurrentIndex == idx) { | 445 | if (m_state.hinting == idx) { | ||
410 | return; | 446 | return; | ||
411 | } | 447 | } | ||
412 | 448 | | |||
413 | m_hintingCurrentIndex = idx; | 449 | m_state.hinting = idx; | ||
414 | emit hintingCurrentIndexChanged(); | 450 | emit hintingCurrentIndexChanged(); | ||
415 | } | 451 | } | ||
416 | 452 | | |||
453 | void FontAASettings::setHintingCurrentIndex(int idx) | ||||
454 | { | ||||
455 | setHinting(KXftConfig::Hint::None + idx); | ||||
456 | } | ||||
457 | | ||||
417 | int FontAASettings::hintingCurrentIndex() | 458 | int FontAASettings::hintingCurrentIndex() | ||
418 | { | 459 | { | ||
419 | return m_hintingCurrentIndex; | 460 | return m_state.hinting - KXftConfig::Hint::None; | ||
420 | } | 461 | } | ||
421 | 462 | | |||
422 | bool FontAASettings::needsSave() const | 463 | bool FontAASettings::needsSave() const | ||
423 | { | 464 | { | ||
424 | return m_excludeTo != m_excludeToOriginal | 465 | return m_state != m_originalState; | ||
425 | || m_excludeFrom != m_excludeFromOriginal | | |||
426 | || m_antiAliasing != m_antiAliasingOriginal | | |||
427 | || m_dpi != m_dpiOriginal | | |||
428 | || m_subPixelCurrentIndex != m_subPixelCurrentIndexOriginal | | |||
429 | || m_hintingCurrentIndex != m_hintingCurrentIndexOriginal; | | |||
430 | } | 466 | } | ||
431 | 467 | | |||
432 | 468 | | |||
433 | /**** KFonts ****/ | 469 | /**** KFonts ****/ | ||
434 | 470 | | |||
435 | KFonts::KFonts(QObject *parent, const QVariantList &args) | 471 | KFonts::KFonts(QObject *parent, const QVariantList &args) | ||
436 | : KQuickAddons::ConfigModule(parent, args) | 472 | : KQuickAddons::ConfigModule(parent, args) | ||
437 | , m_fontAASettings(new FontAASettings(this)) | 473 | , m_fontAASettings(new FontAASettings(this)) | ||
438 | { | 474 | { | ||
439 | qApp->setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); | 475 | qApp->setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); | ||
440 | KAboutData* about = new KAboutData("kcm_fonts", i18n("Configure Fonts"), | 476 | KAboutData* about = new KAboutData("kcm_fonts", i18n("Configure Fonts"), | ||
441 | "0.1", QString(), KAboutLicense::LGPL); | 477 | "0.1", QString(), KAboutLicense::LGPL); | ||
442 | about->addAuthor(i18n("Antonis Tsiapaliokas"), QString(), "antonis.tsiapaliokas@kde.org"); | 478 | about->addAuthor(i18n("Antonis Tsiapaliokas"), QString(), "antonis.tsiapaliokas@kde.org"); | ||
443 | setAboutData(about); | 479 | setAboutData(about); | ||
444 | qmlRegisterType<QStandardItemModel>(); | 480 | qmlRegisterType<QStandardItemModel>(); | ||
445 | setButtons(Apply | Default); | 481 | setButtons(Apply | Default); | ||
446 | 482 | | |||
447 | auto updateState = [this]() { | 483 | auto updateState = [this]() { | ||
448 | setNeedsSave(m_fontAASettings->needsSave()); | 484 | setNeedsSave(m_fontAASettings->needsSave()); | ||
449 | }; | 485 | }; | ||
450 | 486 | | |||
451 | connect(m_fontAASettings, &FontAASettings::subPixelCurrentIndexChanged, this, updateState); | 487 | connect(m_fontAASettings, &FontAASettings::subPixelCurrentIndexChanged, this, updateState); | ||
452 | connect(m_fontAASettings, &FontAASettings::hintingCurrentIndexChanged, this, updateState); | 488 | connect(m_fontAASettings, &FontAASettings::hintingCurrentIndexChanged, this, updateState); | ||
489 | connect(m_fontAASettings, &FontAASettings::excludeChanged, this, updateState); | ||||
490 | connect(m_fontAASettings, &FontAASettings::excludeFromChanged, this, updateState); | ||||
453 | connect(m_fontAASettings, &FontAASettings::excludeToChanged, this, updateState); | 491 | connect(m_fontAASettings, &FontAASettings::excludeToChanged, this, updateState); | ||
454 | connect(m_fontAASettings, &FontAASettings::antiAliasingChanged, this, updateState); | 492 | connect(m_fontAASettings, &FontAASettings::antiAliasingChanged, this, updateState); | ||
455 | connect(m_fontAASettings, &FontAASettings::aliasingChanged, this, updateState); | 493 | connect(m_fontAASettings, &FontAASettings::aliasingChanged, this, updateState); | ||
456 | connect(m_fontAASettings, &FontAASettings::dpiChanged, this, updateState); | 494 | connect(m_fontAASettings, &FontAASettings::dpiChanged, this, updateState); | ||
457 | } | 495 | } | ||
458 | 496 | | |||
459 | KFonts::~KFonts() | 497 | KFonts::~KFonts() | ||
460 | { | 498 | { | ||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Line(s) | 555 | { | |||
534 | m_smallFontOriginal = m_smallFont; | 572 | m_smallFontOriginal = m_smallFont; | ||
535 | m_toolbarFontOriginal = m_toolbarFont; | 573 | m_toolbarFontOriginal = m_toolbarFont; | ||
536 | m_menuFontOriginal = m_menuFont; | 574 | m_menuFontOriginal = m_menuFont; | ||
537 | m_windowTitleFontOriginal = m_windowTitleFont; | 575 | m_windowTitleFontOriginal = m_windowTitleFont; | ||
538 | 576 | | |||
539 | KConfig _cfgfonts("kcmfonts"); | 577 | KConfig _cfgfonts("kcmfonts"); | ||
540 | KConfigGroup cfgfonts(&_cfgfonts, "General"); | 578 | KConfigGroup cfgfonts(&_cfgfonts, "General"); | ||
541 | 579 | | |||
542 | FontAASettings::AASetting aaSetting = (FontAASettings::AASetting)m_fontAASettings->antiAliasing(); | 580 | FontAASettings::AASetting aaSetting = FontAASettings::AASystem; | ||
581 | if (m_fontAASettings->antiAliasingNeedsSave()) { | ||||
582 | aaSetting = m_fontAASettings->antiAliasing() ? FontAASettings::AAEnabled : FontAASettings::AADisabled; | ||||
583 | } | ||||
543 | cfgfonts.writeEntry("dontChangeAASettings", aaSetting == FontAASettings::AASystem); | 584 | cfgfonts.writeEntry("dontChangeAASettings", aaSetting == FontAASettings::AASystem); | ||
544 | 585 | | |||
545 | if (aaSetting == FontAASettings::AAEnabled) { | 586 | if (aaSetting == FontAASettings::AAEnabled) { | ||
546 | m_fontAASettings->save(KXftConfig::AntiAliasing::Enabled); | 587 | m_fontAASettings->save(KXftConfig::AntiAliasing::Enabled); | ||
547 | } else if (aaSetting == FontAASettings::AADisabled) { | 588 | } else if (aaSetting == FontAASettings::AADisabled) { | ||
548 | m_fontAASettings->save(KXftConfig::AntiAliasing::Disabled); | 589 | m_fontAASettings->save(KXftConfig::AntiAliasing::Disabled); | ||
549 | } else { | 590 | } else { | ||
550 | m_fontAASettings->save(KXftConfig::AntiAliasing::NotSet); | 591 | m_fontAASettings->save(KXftConfig::AntiAliasing::NotSet); | ||
▲ Show 20 Lines • Show All 151 Lines • ▼ Show 20 Line(s) | 741 | if (fontDiffFlags & KFontChooser::FontDiffStyle) { | |||
702 | font.setStyle(newFont.style()); | 743 | font.setStyle(newFont.style()); | ||
703 | font.setUnderline(newFont.underline()); | 744 | font.setUnderline(newFont.underline()); | ||
704 | font.setStyleName(newFont.styleName()); | 745 | font.setStyleName(newFont.styleName()); | ||
705 | } | 746 | } | ||
706 | 747 | | |||
707 | return font; | 748 | return font; | ||
708 | } | 749 | } | ||
709 | 750 | | |||
751 | bool FontAASettings::State::operator==(const State& other) const | ||||
752 | { | ||||
753 | if ( | ||||
754 | exclude != other.exclude | ||||
755 | || antiAliasing != other.antiAliasing | ||||
756 | || dpi != other.dpi | ||||
757 | || subPixel != other.subPixel | ||||
758 | || hinting != other.hinting | ||||
759 | ) { | ||||
760 | return false; | ||||
761 | } | ||||
762 | | ||||
763 | if (exclude && (excludeFrom != other.excludeFrom || excludeTo != other.excludeTo)) { | ||||
764 | return false; | ||||
765 | } | ||||
766 | | ||||
767 | return true; | ||||
768 | } | ||||
769 | | ||||
770 | bool FontAASettings::State::operator!=(const State& other) const | ||||
771 | { | ||||
772 | return !(*this == other); | ||||
773 | } | ||||
774 | | ||||
710 | #include "fonts.moc" | 775 | #include "fonts.moc" | ||
711 | 776 | |