Changeset View
Changeset View
Standalone View
Standalone View
kcms/fonts/fonts.cpp
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | |||||
44 | #include <KPluginFactory> | 44 | #include <KPluginFactory> | ||
45 | #include <KFontDialog> | 45 | #include <KFontDialog> | ||
46 | #include <KWindowSystem> | 46 | #include <KWindowSystem> | ||
47 | #include <KMessageBox> | 47 | #include <KMessageBox> | ||
48 | 48 | | |||
49 | #include "../krdb/krdb.h" | 49 | #include "../krdb/krdb.h" | ||
50 | #include "previewimageprovider.h" | 50 | #include "previewimageprovider.h" | ||
51 | 51 | | |||
52 | #include "fontssettings.h" | ||||
53 | | ||||
52 | /**** DLL Interface ****/ | 54 | /**** DLL Interface ****/ | ||
53 | K_PLUGIN_FACTORY_WITH_JSON(KFontsFactory, "kcm_fonts.json", registerPlugin<KFonts>();) | 55 | K_PLUGIN_FACTORY_WITH_JSON(KFontsFactory, "kcm_fonts.json", registerPlugin<KFonts>();) | ||
54 | 56 | | |||
55 | //from KFontRequester | 57 | //from KFontRequester | ||
56 | // Determine if the font with given properties is available on the system, | 58 | // Determine if the font with given properties is available on the system, | ||
57 | // otherwise find and return the best fitting combination. | 59 | // otherwise find and return the best fitting combination. | ||
58 | static QFont nearestExistingFont(const QFont &font) | 60 | static QFont nearestExistingFont(const QFont &font) | ||
59 | { | 61 | { | ||
▲ Show 20 Lines • Show All 402 Lines • ▼ Show 20 Line(s) | 463 | { | |||
462 | return m_state != m_originalState; | 464 | return m_state != m_originalState; | ||
463 | } | 465 | } | ||
464 | 466 | | |||
465 | 467 | | |||
466 | /**** KFonts ****/ | 468 | /**** KFonts ****/ | ||
467 | 469 | | |||
468 | KFonts::KFonts(QObject *parent, const QVariantList &args) | 470 | KFonts::KFonts(QObject *parent, const QVariantList &args) | ||
469 | : KQuickAddons::ConfigModule(parent, args) | 471 | : KQuickAddons::ConfigModule(parent, args) | ||
472 | , m_settings(new FontsSettings(this)) | ||||
470 | , m_fontAASettings(new FontAASettings(this)) | 473 | , m_fontAASettings(new FontAASettings(this)) | ||
471 | { | 474 | { | ||
472 | KAboutData* about = new KAboutData("kcm_fonts", i18n("Fonts"), | 475 | KAboutData* about = new KAboutData("kcm_fonts", i18n("Fonts"), | ||
473 | "0.1", QString(), KAboutLicense::LGPL); | 476 | "0.1", QString(), KAboutLicense::LGPL); | ||
474 | about->addAuthor(i18n("Antonis Tsiapaliokas"), QString(), "antonis.tsiapaliokas@kde.org"); | 477 | about->addAuthor(i18n("Antonis Tsiapaliokas"), QString(), "antonis.tsiapaliokas@kde.org"); | ||
475 | setAboutData(about); | 478 | setAboutData(about); | ||
476 | qmlRegisterType<QStandardItemModel>(); | 479 | qmlRegisterType<QStandardItemModel>(); | ||
480 | qmlRegisterType<FontsSettings>(); | ||||
481 | | ||||
477 | setButtons(Apply | Default | Help); | 482 | setButtons(Apply | Default | Help); | ||
478 | 483 | | |||
479 | auto updateState = [this]() { | 484 | auto updateState = [this]() { | ||
480 | setNeedsSave(m_fontAASettings->needsSave()); | 485 | setNeedsSave(m_fontAASettings->needsSave()); | ||
481 | }; | 486 | }; | ||
482 | 487 | | |||
488 | connect(m_settings, &FontsSettings::configChanged, this, &KFonts::updateNeedsSave); | ||||
489 | connect(m_settings, &FontsSettings::fontChanged, this, &KFonts::updateNeedsSave); | ||||
490 | connect(m_settings, &FontsSettings::fixedChanged, this, &KFonts::updateNeedsSave); | ||||
491 | connect(m_settings, &FontsSettings::smallestReadableFont, this, &KFonts::updateNeedsSave); | ||||
492 | connect(m_settings, &FontsSettings::toolBarFont, this, &KFonts::updateNeedsSave); | ||||
493 | connect(m_settings, &FontsSettings::menuFont, this, &KFonts::updateNeedsSave); | ||||
494 | connect(m_settings, &FontsSettings::activeFont, this, &KFonts::updateNeedsSave); | ||||
495 | | ||||
483 | connect(m_fontAASettings, &FontAASettings::subPixelCurrentIndexChanged, this, updateState); | 496 | connect(m_fontAASettings, &FontAASettings::subPixelCurrentIndexChanged, this, updateState); | ||
484 | connect(m_fontAASettings, &FontAASettings::hintingCurrentIndexChanged, this, updateState); | 497 | connect(m_fontAASettings, &FontAASettings::hintingCurrentIndexChanged, this, updateState); | ||
485 | connect(m_fontAASettings, &FontAASettings::excludeChanged, this, updateState); | 498 | connect(m_fontAASettings, &FontAASettings::excludeChanged, this, updateState); | ||
486 | connect(m_fontAASettings, &FontAASettings::excludeFromChanged, this, updateState); | 499 | connect(m_fontAASettings, &FontAASettings::excludeFromChanged, this, updateState); | ||
487 | connect(m_fontAASettings, &FontAASettings::excludeToChanged, this, updateState); | 500 | connect(m_fontAASettings, &FontAASettings::excludeToChanged, this, updateState); | ||
488 | connect(m_fontAASettings, &FontAASettings::antiAliasingChanged, this, updateState); | 501 | connect(m_fontAASettings, &FontAASettings::antiAliasingChanged, this, updateState); | ||
489 | connect(m_fontAASettings, &FontAASettings::aliasingChanged, this, updateState); | 502 | connect(m_fontAASettings, &FontAASettings::aliasingChanged, this, updateState); | ||
490 | connect(m_fontAASettings, &FontAASettings::dpiChanged, this, updateState); | 503 | connect(m_fontAASettings, &FontAASettings::dpiChanged, this, updateState); | ||
491 | } | 504 | } | ||
492 | 505 | | |||
493 | KFonts::~KFonts() | 506 | KFonts::~KFonts() | ||
494 | { | 507 | { | ||
495 | } | 508 | } | ||
496 | 509 | | |||
497 | void KFonts::defaults() | 510 | FontsSettings *KFonts::fontsSettings() const | ||
498 | { | 511 | { | ||
499 | #ifdef Q_OS_MAC | 512 | return m_settings; | ||
500 | setGeneralFont(QFont("Lucida Grande", 13)); | 513 | } | ||
501 | setMenuFont(QFont("Lucida Grande", 13)); | | |||
502 | setFixedWidthFont(QFont("Monaco", 10)); | | |||
503 | setToolbarFont(QFont("Lucida Grande", 11)); | | |||
504 | setSmallFont(QFont("Lucida Grande", 9)); | | |||
505 | setWindowTitleFont(QFont("Lucida Grande", 14)); | | |||
506 | #else | | |||
507 | setGeneralFont(QFont("Noto Sans", 10)); | | |||
508 | setMenuFont(QFont("Noto Sans", 10)); | | |||
509 | setFixedWidthFont(QFont("Hack", 9)); | | |||
510 | setToolbarFont(QFont("Noto Sans", 10)); | | |||
511 | setSmallFont(QFont("Noto Sans", 8)); | | |||
512 | setWindowTitleFont(QFont("Noto Sans", 10)); | | |||
513 | #endif | | |||
514 | 514 | | |||
515 | void KFonts::defaults() | ||||
516 | { | ||||
517 | m_settings->setDefaults(); | ||||
515 | m_fontAASettings->defaults(); | 518 | m_fontAASettings->defaults(); | ||
516 | } | 519 | } | ||
517 | 520 | | |||
518 | void KFonts::load() | 521 | void KFonts::setNearestExistingFonts() | ||
519 | { | 522 | { | ||
520 | KSharedConfig::Ptr config = KSharedConfig::openConfig("kdeglobals"); | 523 | m_settings->setFont(nearestExistingFont(m_settings->font())); | ||
521 | 524 | m_settings->setFixed(nearestExistingFont(m_settings->fixed())); | |||
522 | KConfigGroup cg(config, "General"); | 525 | m_settings->setSmallestReadableFont(nearestExistingFont(m_settings->smallestReadableFont())); | ||
523 | m_generalFont = m_generalFontOriginal = nearestExistingFont(cg.readEntry("font", m_defaultFont)); | 526 | m_settings->setToolBarFont(nearestExistingFont(m_settings->toolBarFont())); | ||
524 | 527 | m_settings->setMenuFont(nearestExistingFont(m_settings->menuFont())); | |||
525 | 528 | m_settings->setActiveFont(nearestExistingFont(m_settings->activeFont())); | |||
526 | m_fixedWidthFont = m_fixedWidthFontOriginal = nearestExistingFont(cg.readEntry("fixed", QFont("Hack", 9))); | 529 | } | ||
527 | | ||||
528 | m_smallFont = m_smallFontOriginal = nearestExistingFont(cg.readEntry("smallestReadableFont", m_defaultFont)); | | |||
529 | | ||||
530 | m_toolbarFont = m_toolbarFontOriginal = nearestExistingFont(cg.readEntry("toolBarFont", m_defaultFont)); | | |||
531 | | ||||
532 | m_menuFont = m_menuFontOriginal = nearestExistingFont(cg.readEntry("menuFont", m_defaultFont)); | | |||
533 | | ||||
534 | cg = KConfigGroup(config, "WM"); | | |||
535 | m_windowTitleFont = m_windowTitleFontOriginal = nearestExistingFont(cg.readEntry("activeFont", m_defaultFont)); | | |||
536 | | ||||
537 | engine()->addImageProvider("preview", new PreviewImageProvider(generalFont())); | | |||
538 | 530 | | |||
539 | emit generalFontChanged(); | 531 | void KFonts::load() | ||
540 | emit fixedWidthFontChanged(); | 532 | { | ||
541 | emit smallFontChanged(); | 533 | m_settings->load(); | ||
542 | emit toolbarFontChanged(); | 534 | setNearestExistingFonts(); | ||
543 | emit menuFontChanged(); | 535 | engine()->addImageProvider("preview", new PreviewImageProvider(m_settings->font())); | ||
544 | emit windowTitleFontChanged(); | | |||
545 | 536 | | |||
546 | m_fontAASettings->load(); | 537 | m_fontAASettings->load(); | ||
547 | setNeedsSave(false); | 538 | setNeedsSave(false); | ||
548 | } | 539 | } | ||
549 | 540 | | |||
550 | void KFonts::save() | 541 | void KFonts::save() | ||
551 | { | 542 | { | ||
552 | KSharedConfig::Ptr config = KSharedConfig::openConfig("kdeglobals"); | 543 | m_settings->save(); | ||
553 | | ||||
554 | KConfigGroup cg(config, "General"); | | |||
555 | cg.writeEntry("font", m_generalFont.toString()); | | |||
556 | cg.writeEntry("fixed", m_fixedWidthFont.toString()); | | |||
557 | cg.writeEntry("smallestReadableFont", m_smallFont.toString()); | | |||
558 | cg.writeEntry("toolBarFont", m_toolbarFont.toString()); | | |||
559 | cg.writeEntry("menuFont", m_menuFont.toString()); | | |||
560 | cg.sync(); | | |||
561 | cg = KConfigGroup(config, "WM"); | | |||
562 | cg.writeEntry("activeFont", m_windowTitleFont.toString()); | | |||
563 | cg.sync(); | | |||
564 | | ||||
565 | m_defaultFontOriginal = m_defaultFont; | | |||
566 | m_generalFontOriginal = m_generalFont; | | |||
567 | m_fixedWidthFontOriginal = m_fixedWidthFont; | | |||
568 | m_smallFontOriginal = m_smallFont; | | |||
569 | m_toolbarFontOriginal = m_toolbarFont; | | |||
570 | m_menuFontOriginal = m_menuFont; | | |||
571 | m_windowTitleFontOriginal = m_windowTitleFont; | | |||
572 | 544 | | |||
573 | KConfig _cfgfonts("kcmfonts"); | 545 | KConfig _cfgfonts("kcmfonts"); | ||
574 | KConfigGroup cfgfonts(&_cfgfonts, "General"); | 546 | KConfigGroup cfgfonts(&_cfgfonts, "General"); | ||
575 | 547 | | |||
576 | FontAASettings::AASetting aaSetting = FontAASettings::AASystem; | 548 | FontAASettings::AASetting aaSetting = FontAASettings::AASystem; | ||
577 | if (m_fontAASettings->antiAliasingNeedsSave()) { | 549 | if (m_fontAASettings->antiAliasingNeedsSave()) { | ||
578 | aaSetting = m_fontAASettings->antiAliasing() ? FontAASettings::AAEnabled : FontAASettings::AADisabled; | 550 | aaSetting = m_fontAASettings->antiAliasing() ? FontAASettings::AAEnabled : FontAASettings::AADisabled; | ||
579 | } | 551 | } | ||
Show All 12 Lines | |||||
592 | runRdb(KRdbExportXftSettings | KRdbExportGtkTheme); | 564 | runRdb(KRdbExportXftSettings | KRdbExportGtkTheme); | ||
593 | 565 | | |||
594 | emit fontsHaveChanged(); | 566 | emit fontsHaveChanged(); | ||
595 | setNeedsSave(false); | 567 | setNeedsSave(false); | ||
596 | } | 568 | } | ||
597 | 569 | | |||
598 | void KFonts::updateNeedsSave() | 570 | void KFonts::updateNeedsSave() | ||
599 | { | 571 | { | ||
600 | setNeedsSave(m_defaultFontOriginal != m_defaultFont || | 572 | setNeedsSave(m_settings->isSaveNeeded() || m_fontAASettings->needsSave()); | ||
601 | m_generalFontOriginal != m_generalFont || | | |||
602 | m_fixedWidthFontOriginal != m_fixedWidthFont || | | |||
603 | m_smallFontOriginal != m_smallFont || | | |||
604 | m_toolbarFontOriginal != m_toolbarFont || | | |||
605 | m_menuFontOriginal != m_menuFont || | | |||
606 | m_windowTitleFontOriginal != m_windowTitleFont || | | |||
607 | m_fontAASettings->needsSave()); | | |||
608 | } | | |||
609 | | ||||
610 | void KFonts::setGeneralFont(const QFont &font) | | |||
611 | { | | |||
612 | if (m_generalFont == font) { | | |||
613 | return; | | |||
614 | } | | |||
615 | | ||||
616 | m_generalFont = font; | | |||
617 | emit generalFontChanged(); | | |||
618 | updateNeedsSave(); | | |||
619 | } | | |||
620 | | ||||
621 | QFont KFonts::generalFont() const | | |||
622 | { | | |||
623 | return m_generalFont; | | |||
624 | } | | |||
625 | | ||||
626 | void KFonts::setFixedWidthFont(const QFont &font) | | |||
627 | { | | |||
628 | if (m_fixedWidthFont == font) { | | |||
629 | return; | | |||
630 | } | | |||
631 | | ||||
632 | m_fixedWidthFont = font; | | |||
633 | emit fixedWidthFontChanged(); | | |||
634 | updateNeedsSave(); | | |||
635 | } | | |||
636 | | ||||
637 | QFont KFonts::fixedWidthFont() const | | |||
638 | { | | |||
639 | return m_fixedWidthFont; | | |||
640 | } | | |||
641 | | ||||
642 | void KFonts::setSmallFont(const QFont &font) | | |||
643 | { | | |||
644 | if (m_smallFont == font) { | | |||
645 | return; | | |||
646 | } | | |||
647 | | ||||
648 | m_smallFont = font; | | |||
649 | emit smallFontChanged(); | | |||
650 | updateNeedsSave(); | | |||
651 | } | | |||
652 | | ||||
653 | QFont KFonts::smallFont() const | | |||
654 | { | | |||
655 | return m_smallFont; | | |||
656 | } | | |||
657 | | ||||
658 | void KFonts::setToolbarFont(const QFont &font) | | |||
659 | { | | |||
660 | if (m_toolbarFont == font) { | | |||
661 | return; | | |||
662 | } | | |||
663 | | ||||
664 | m_toolbarFont = font; | | |||
665 | emit toolbarFontChanged(); | | |||
666 | updateNeedsSave(); | | |||
667 | } | | |||
668 | | ||||
669 | QFont KFonts::toolbarFont() const | | |||
670 | { | | |||
671 | return m_toolbarFont; | | |||
672 | } | | |||
673 | | ||||
674 | void KFonts::setMenuFont(const QFont &font) | | |||
675 | { | | |||
676 | if (m_menuFont == font) { | | |||
677 | return; | | |||
678 | } | | |||
679 | | ||||
680 | m_menuFont = font; | | |||
681 | emit menuFontChanged(); | | |||
682 | updateNeedsSave(); | | |||
683 | } | | |||
684 | | ||||
685 | QFont KFonts::menuFont() const | | |||
686 | { | | |||
687 | return m_menuFont; | | |||
688 | } | | |||
689 | | ||||
690 | void KFonts::setWindowTitleFont(const QFont &font) | | |||
691 | { | | |||
692 | if (m_windowTitleFont == font) { | | |||
693 | return; | | |||
694 | } | | |||
695 | | ||||
696 | m_windowTitleFont = font; | | |||
697 | emit windowTitleFontChanged(); | | |||
698 | updateNeedsSave(); | | |||
699 | } | | |||
700 | | ||||
701 | QFont KFonts::windowTitleFont() const | | |||
702 | { | | |||
703 | return m_windowTitleFont; | | |||
704 | } | 573 | } | ||
705 | 574 | | |||
706 | void KFonts::adjustAllFonts() | 575 | void KFonts::adjustAllFonts() | ||
707 | { | 576 | { | ||
708 | QFont font = m_generalFont; | 577 | QFont font = m_settings->font(); | ||
709 | KFontChooser::FontDiffFlags fontDiffFlags; | 578 | KFontChooser::FontDiffFlags fontDiffFlags; | ||
710 | int ret = KFontDialog::getFontDiff(font, fontDiffFlags, KFontChooser::NoDisplayFlags); | 579 | int ret = KFontDialog::getFontDiff(font, fontDiffFlags, KFontChooser::NoDisplayFlags); | ||
711 | 580 | | |||
712 | if (ret == KDialog::Accepted && fontDiffFlags) { | 581 | if (ret == KDialog::Accepted && fontDiffFlags) { | ||
713 | setGeneralFont(applyFontDiff(m_generalFont, font, fontDiffFlags)); | 582 | m_settings->setFont(applyFontDiff(m_settings->font(), font, fontDiffFlags)); | ||
714 | setMenuFont(applyFontDiff(m_menuFont, font, fontDiffFlags)); | 583 | m_settings->setMenuFont(applyFontDiff(m_settings->menuFont(), font, fontDiffFlags)); | ||
715 | { | 584 | m_settings->setToolBarFont(applyFontDiff(m_settings->toolBarFont(), font, fontDiffFlags)); | ||
716 | const QFont adjustedFont = applyFontDiff(m_fixedWidthFont, font, fontDiffFlags); | 585 | m_settings->setActiveFont(applyFontDiff(m_settings->activeFont(), font, fontDiffFlags)); | ||
586 | m_settings->setSmallestReadableFont(applyFontDiff(m_settings->smallestReadableFont(), font, fontDiffFlags)); | ||||
587 | const QFont adjustedFont = applyFontDiff(m_settings->fixed(), font, fontDiffFlags); | ||||
717 | if (QFontInfo(adjustedFont).fixedPitch()) { | 588 | if (QFontInfo(adjustedFont).fixedPitch()) { | ||
718 | setFixedWidthFont(adjustedFont); | 589 | m_settings->setFixed(adjustedFont); | ||
719 | } | | |||
720 | } | 590 | } | ||
721 | setToolbarFont(applyFontDiff(m_toolbarFont, font, fontDiffFlags)); | | |||
722 | setSmallFont(applyFontDiff(m_smallFont, font, fontDiffFlags)); | | |||
723 | setWindowTitleFont(applyFontDiff(m_windowTitleFont, font, fontDiffFlags)); | | |||
724 | } | 591 | } | ||
725 | } | 592 | } | ||
726 | 593 | | |||
727 | QFont KFonts::applyFontDiff(const QFont &fnt, const QFont &newFont, int fontDiffFlags) | 594 | QFont KFonts::applyFontDiff(const QFont &fnt, const QFont &newFont, int fontDiffFlags) | ||
728 | { | 595 | { | ||
729 | QFont font(fnt); | 596 | QFont font(fnt); | ||
730 | 597 | | |||
731 | if (fontDiffFlags & KFontChooser::FontDiffSize) { | 598 | if (fontDiffFlags & KFontChooser::FontDiffSize) { | ||
▲ Show 20 Lines • Show All 41 Lines • Show Last 20 Lines |