Changeset View
Changeset View
Standalone View
Standalone View
kcms/fonts/fonts.cpp
Show All 36 Lines | |||||
37 | 37 | | |||
38 | #include <KAcceleratorManager> | 38 | #include <KAcceleratorManager> | ||
39 | #include <KGlobalSettings> | 39 | #include <KGlobalSettings> | ||
40 | #include <KConfigGroup> | 40 | #include <KConfigGroup> | ||
41 | #include <KConfig> | 41 | #include <KConfig> | ||
42 | #include <KAboutData> | 42 | #include <KAboutData> | ||
43 | #include <KLocalizedString> | 43 | #include <KLocalizedString> | ||
44 | #include <KPluginFactory> | 44 | #include <KPluginFactory> | ||
45 | #include <KFontDialog> | | |||
46 | #include <KWindowSystem> | 45 | #include <KWindowSystem> | ||
47 | 46 | | |||
48 | #include "../krdb/krdb.h" | 47 | #include "../krdb/krdb.h" | ||
49 | #include "previewimageprovider.h" | 48 | #include "previewimageprovider.h" | ||
50 | 49 | | |||
51 | #include "fontssettings.h" | 50 | #include "fontssettings.h" | ||
52 | 51 | | |||
53 | /**** DLL Interface ****/ | 52 | /**** DLL Interface ****/ | ||
▲ Show 20 Lines • Show All 597 Lines • ▼ Show 20 Line(s) | |||||
651 | 650 | | |||
652 | bool KFonts::isDefaults() const | 651 | bool KFonts::isDefaults() const | ||
653 | { | 652 | { | ||
654 | return m_fontAASettings->isDefaults(); | 653 | return m_fontAASettings->isDefaults(); | ||
655 | } | 654 | } | ||
656 | 655 | | |||
657 | void KFonts::adjustAllFonts() | 656 | void KFonts::adjustAllFonts() | ||
658 | { | 657 | { | ||
659 | QFont font = m_settings->font(); | 658 | bool ok = false; | ||
660 | KFontChooser::FontDiffFlags fontDiffFlags; | 659 | QFont font = QFontDialog::getFont(&ok, m_settings->font(), nullptr, i18n("Select Font")); | ||
661 | int ret = KFontDialog::getFontDiff(font, fontDiffFlags, KFontChooser::NoDisplayFlags); | | |||
662 | 660 | | |||
663 | if (ret == KDialog::Accepted && fontDiffFlags) { | 661 | if (ok) { | ||
664 | if (!m_settings->isImmutable("font")) { | 662 | if (!m_settings->isImmutable("font")) { | ||
665 | m_settings->setFont(applyFontDiff(m_settings->font(), font, fontDiffFlags)); | 663 | m_settings->setFont(font); | ||
666 | } | 664 | } | ||
667 | if (!m_settings->isImmutable("menuFont")) { | 665 | if (!m_settings->isImmutable("menuFont")) { | ||
668 | m_settings->setMenuFont(applyFontDiff(m_settings->menuFont(), font, fontDiffFlags)); | 666 | m_settings->setMenuFont(font); | ||
669 | } | 667 | } | ||
670 | if (!m_settings->isImmutable("toolBarFont")) { | 668 | if (!m_settings->isImmutable("toolBarFont")) { | ||
671 | m_settings->setToolBarFont(applyFontDiff(m_settings->toolBarFont(), font, fontDiffFlags)); | 669 | m_settings->setToolBarFont(font); | ||
672 | } | 670 | } | ||
673 | if (!m_settings->isImmutable("activeFont")) { | 671 | if (!m_settings->isImmutable("activeFont")) { | ||
674 | m_settings->setActiveFont(applyFontDiff(m_settings->activeFont(), font, fontDiffFlags)); | 672 | m_settings->setActiveFont(font); | ||
675 | } | 673 | } | ||
676 | if (!m_settings->isImmutable("smallestReadableFont")) { | 674 | if (!m_settings->isImmutable("smallestReadableFont")) { | ||
677 | m_settings->setSmallestReadableFont(applyFontDiff(m_settings->smallestReadableFont(), font, fontDiffFlags)); | 675 | m_settings->setSmallestReadableFont(font); | ||
678 | } | | |||
679 | const QFont adjustedFont = applyFontDiff(m_settings->fixed(), font, fontDiffFlags); | | |||
680 | if (QFontInfo(adjustedFont).fixedPitch() && !m_settings->isImmutable("fixed")) { | | |||
681 | m_settings->setFixed(adjustedFont); | | |||
682 | } | | |||
683 | } | | |||
684 | } | 676 | } | ||
685 | 677 | | |||
686 | QFont KFonts::applyFontDiff(const QFont &fnt, const QFont &newFont, int fontDiffFlags) | 678 | // Try to find a fixed-width/monspace font from the font family the user selected, e.g.: | ||
meven: s/monspace/monospace | |||||
687 | { | 679 | // "Noto Sans" -> "Noto Sans Mono", "Ubuntu" -> "Ubuntu Mono" | ||
688 | QFont font(fnt); | 680 | // we take the first one that comes along, e.g. "Noto Sans Mono" _not_ "Noto Sans Mono Blk" | ||
689 | 681 | QFontDatabase fdb; | |||
690 | if (fontDiffFlags & KFontChooser::FontDiffSize) { | 682 | const QStringList fontFamilies = fdb.families(); | ||
691 | font.setPointSizeF(newFont.pointSizeF()); | 683 | QString mono; | ||
692 | } | 684 | for (const QString &family : fontFamilies) { | ||
693 | if ((fontDiffFlags & KFontChooser::FontDiffFamily)) { | 685 | // QString::endsWith() is cheaper than contains(), so try it first | ||
694 | font.setFamily(newFont.family()); | 686 | if (family.startsWith(font.family()) | ||
687 | && (family.endsWith(QLatin1String("Mono")) | ||||
688 | || family.contains(QLatin1String("Mono")))) { | ||||
689 | mono = family; | ||||
690 | break; | ||||
691 | } | ||||
692 | } | ||||
693 | // fallback if we find nothing | ||||
694 | QFont f = mono.isEmpty() ? QFontDatabase::systemFont(QFontDatabase::FixedFont) : QFont(mono); | ||||
695 | if (!m_settings->isImmutable("fixed")) { | ||||
696 | m_settings->setFixed(f); | ||||
695 | } | 697 | } | ||
696 | if (fontDiffFlags & KFontChooser::FontDiffStyle) { | | |||
697 | font.setWeight(newFont.weight()); | | |||
698 | font.setStyle(newFont.style()); | | |||
699 | font.setUnderline(newFont.underline()); | | |||
700 | font.setStyleName(newFont.styleName()); | | |||
701 | } | 698 | } | ||
702 | | ||||
703 | return font; | | |||
704 | } | 699 | } | ||
705 | 700 | | |||
706 | #include "fonts.moc" | 701 | #include "fonts.moc" | ||
707 | |
s/monspace/monospace