Changeset View
Changeset View
Standalone View
Standalone View
kcms/fonts/fonts.cpp
Show First 20 Lines • Show All 97 Lines • ▼ Show 20 Line(s) | 85 | if (!dbase.isSmoothlyScalable(family, style)) { | |||
---|---|---|---|---|---|
98 | } | 98 | } | ||
99 | } | 99 | } | ||
100 | 100 | | |||
101 | // Select the font with confirmed properties. | 101 | // Select the font with confirmed properties. | ||
102 | QFont result = dbase.font(family, style, int(size)); | 102 | QFont result = dbase.font(family, style, int(size)); | ||
103 | if (dbase.isSmoothlyScalable(family, style) && result.pointSize() == floor(size)) { | 103 | if (dbase.isSmoothlyScalable(family, style) && result.pointSize() == floor(size)) { | ||
104 | result.setPointSizeF(size); | 104 | result.setPointSizeF(size); | ||
105 | } | 105 | } | ||
106 | return result; | 106 | | ||
107 | bool sameFont = font.toString() == result.toString(); | ||||
108 | // A "Regular" font will have an empty styleName e.g. "DejaVu Sans,12,-1,5,50,0,0,0,0,0" | ||||
109 | // so that setBold(true) can work (we deliberately clear the styleName for "Regular"-like | ||||
110 | // font styles when saving via KConfig, see: writeEntryGui() from kconfiggroupgui.cpp). | ||||
111 | // Here in this method we could end up with a "result" font that's using a Regular style | ||||
112 | // and that has the styleName set, so the the original "font" param. and "result" are | ||||
113 | // actually the same font | ||||
114 | if (!sameFont | ||||
115 | && font.weight() == QFont::Normal && font.styleName().isEmpty() | ||||
bport: You can use && to have only one if there | |||||
ahmadsamir: OK. | |||||
116 | && result.weight() == QFont::Normal | ||||
117 | && (result.styleName() == QLatin1String("Regular") | ||||
118 | || result.styleName() == QLatin1String("Normal") | ||||
119 | || result.styleName() == QLatin1String("Book") | ||||
120 | || result.styleName() == QLatin1String("Roman"))) { | ||||
121 | result.setStyleName(QString()); | ||||
122 | sameFont = font.toString() == result.toString(); | ||||
123 | } | ||||
124 | | ||||
125 | return sameFont ? font : result; | ||||
107 | } | 126 | } | ||
108 | 127 | | |||
109 | /**** FontAASettings ****/ | 128 | /**** FontAASettings ****/ | ||
110 | #if defined(HAVE_FONTCONFIG) && HAVE_X11 | 129 | #if defined(HAVE_FONTCONFIG) && HAVE_X11 | ||
111 | FontAASettings::FontAASettings(QObject *parent) | 130 | FontAASettings::FontAASettings(QObject *parent) | ||
112 | : QObject(parent) | 131 | : QObject(parent) | ||
113 | , m_state() | 132 | , m_state() | ||
114 | , m_originalState() | 133 | , m_originalState() | ||
▲ Show 20 Lines • Show All 429 Lines • ▼ Show 20 Line(s) | |||||
544 | void KFonts::defaults() | 563 | void KFonts::defaults() | ||
545 | { | 564 | { | ||
546 | ManagedConfigModule::defaults(); | 565 | ManagedConfigModule::defaults(); | ||
547 | m_fontAASettings->defaults(); | 566 | m_fontAASettings->defaults(); | ||
548 | } | 567 | } | ||
549 | 568 | | |||
550 | void KFonts::setNearestExistingFonts() | 569 | void KFonts::setNearestExistingFonts() | ||
551 | { | 570 | { | ||
552 | m_settings->setFont(nearestExistingFont(m_settings->font())); | 571 | m_settings->setFont(nearestExistingFont(m_settings->font())); | ||
Those change will compare font twice, here and on setters so I will keep old code there bport: Those change will compare font twice, here and on setters so I will keep old code there | |||||
Indeed; looking at the code generated by kconfig compiler in <builddir>/kcms/fonts/fontsettings.h: /** Set General font */ void setFont( const QFont & v ) { if (v != mFont && !isFontImmutable()) { mFont = v; Q_EMIT fontChanged(); } } I will revert. And another point is that the code in fonts.cpp doesn't need to check for immutability since it's checked by the setters. ahmadsamir: Indeed; looking at the code generated by kconfig compiler in <builddir>/kcms/fonts/fontsettings. | |||||
553 | m_settings->setFixed(nearestExistingFont(m_settings->fixed())); | 572 | m_settings->setFixed(nearestExistingFont(m_settings->fixed())); | ||
554 | m_settings->setSmallestReadableFont(nearestExistingFont(m_settings->smallestReadableFont())); | 573 | m_settings->setSmallestReadableFont(nearestExistingFont(m_settings->smallestReadableFont())); | ||
555 | m_settings->setToolBarFont(nearestExistingFont(m_settings->toolBarFont())); | 574 | m_settings->setToolBarFont(nearestExistingFont(m_settings->toolBarFont())); | ||
556 | m_settings->setMenuFont(nearestExistingFont(m_settings->menuFont())); | 575 | m_settings->setMenuFont(nearestExistingFont(m_settings->menuFont())); | ||
557 | m_settings->setActiveFont(nearestExistingFont(m_settings->activeFont())); | 576 | m_settings->setActiveFont(nearestExistingFont(m_settings->activeFont())); | ||
558 | } | 577 | } | ||
559 | 578 | | |||
560 | void KFonts::load() | 579 | void KFonts::load() | ||
561 | { | 580 | { | ||
562 | // first load all the settings | 581 | // first load all the settings | ||
563 | ManagedConfigModule::load(); | 582 | ManagedConfigModule::load(); | ||
564 | m_fontAASettings->load(); | 583 | m_fontAASettings->load(); | ||
565 | 584 | | |||
566 | // Then set the existing fonts based on those settings | 585 | // Then set the existing fonts based on those settings | ||
567 | setNearestExistingFonts(); | 586 | setNearestExistingFonts(); | ||
568 | 587 | | |||
569 | // Load preview | 588 | // Load preview | ||
570 | // NOTE: This needs to be done AFTER AA settings is loaded | 589 | // NOTE: This needs to be done AFTER AA settings is loaded | ||
571 | // otherwise AA settings will be reset in process of loading | 590 | // otherwise AA settings will be reset in process of loading | ||
572 | // previews | 591 | // previews | ||
573 | engine()->addImageProvider("preview", new PreviewImageProvider(m_settings->font())); | 592 | engine()->addImageProvider("preview", new PreviewImageProvider(m_settings->font())); | ||
574 | 593 | | |||
575 | // KCM expect save state to be false at this point (can be true because of setNearestExistingFonts | 594 | // KCM expect save state to be false at this point (can be true because of setNearestExistingFonts), | ||
595 | // see: https://phabricator.kde.org/D27452 | ||||
576 | setNeedsSave(false); | 596 | setNeedsSave(false); | ||
I will keep that until we have a proper tested fix for https://phabricator.kde.org/D27452 bport: I will keep that until we have a proper tested fix for https://phabricator.kde.org/D27452
can… | |||||
ahmadsamir: OK, fair point, I will revert that bit. | |||||
577 | } | 597 | } | ||
578 | 598 | | |||
579 | void KFonts::save() | 599 | void KFonts::save() | ||
580 | { | 600 | { | ||
581 | ManagedConfigModule::save(); | 601 | ManagedConfigModule::save(); | ||
582 | 602 | | |||
583 | KConfig _cfgfonts("kcmfonts"); | 603 | KConfig _cfgfonts("kcmfonts"); | ||
584 | KConfigGroup cfgfonts(&_cfgfonts, "General"); | 604 | KConfigGroup cfgfonts(&_cfgfonts, "General"); | ||
▲ Show 20 Lines • Show All 83 Lines • Show Last 20 Lines |
You can use && to have only one if there