Changeset View
Changeset View
Standalone View
Standalone View
kcms/fonts/fonts.cpp
Show First 20 Lines • Show All 491 Lines • ▼ Show 20 Line(s) | |||||
492 | bool FontAASettings::State::operator!=(const State& other) const | 492 | bool FontAASettings::State::operator!=(const State& other) const | ||
493 | { | 493 | { | ||
494 | return !(*this == other); | 494 | return !(*this == other); | ||
495 | } | 495 | } | ||
496 | 496 | | |||
497 | /**** KFonts ****/ | 497 | /**** KFonts ****/ | ||
498 | 498 | | |||
499 | KFonts::KFonts(QObject *parent, const QVariantList &args) | 499 | KFonts::KFonts(QObject *parent, const QVariantList &args) | ||
500 | : KQuickAddons::ConfigModule(parent, args) | 500 | : KQuickAddons::ManagedConfigModule(parent, args) | ||
501 | , m_settings(new FontsSettings(this)) | 501 | , m_settings(new FontsSettings(this)) | ||
502 | , m_fontAASettings(new FontAASettings(this)) | 502 | , m_fontAASettings(new FontAASettings(this)) | ||
503 | { | 503 | { | ||
504 | KAboutData* about = new KAboutData("kcm_fonts", i18n("Fonts"), | 504 | KAboutData* about = new KAboutData("kcm_fonts", i18n("Fonts"), | ||
505 | "0.1", QString(), KAboutLicense::LGPL); | 505 | "0.1", QString(), KAboutLicense::LGPL); | ||
506 | about->addAuthor(i18n("Antonis Tsiapaliokas"), QString(), "antonis.tsiapaliokas@kde.org"); | 506 | about->addAuthor(i18n("Antonis Tsiapaliokas"), QString(), "antonis.tsiapaliokas@kde.org"); | ||
507 | setAboutData(about); | 507 | setAboutData(about); | ||
508 | qmlRegisterType<QStandardItemModel>(); | 508 | qmlRegisterType<QStandardItemModel>(); | ||
509 | qmlRegisterType<FontsSettings>(); | 509 | qmlRegisterType<FontsSettings>(); | ||
510 | 510 | | |||
511 | setButtons(Apply | Default | Help); | 511 | setButtons(Apply | Default | Help); | ||
512 | 512 | | |||
513 | auto updateState = [this]() { | 513 | auto updateState = [this]() { | ||
514 | setNeedsSave(m_fontAASettings->needsSave()); | 514 | setNeedsSave(m_fontAASettings->needsSave()); | ||
515 | }; | 515 | }; | ||
516 | 516 | | |||
517 | connect(m_settings, &FontsSettings::configChanged, this, &KFonts::updateNeedsSave); | | |||
518 | connect(m_settings, &FontsSettings::fontChanged, this, &KFonts::updateNeedsSave); | | |||
519 | connect(m_settings, &FontsSettings::fixedChanged, this, &KFonts::updateNeedsSave); | | |||
520 | connect(m_settings, &FontsSettings::smallestReadableFontChanged, this, &KFonts::updateNeedsSave); | | |||
521 | connect(m_settings, &FontsSettings::toolBarFontChanged, this, &KFonts::updateNeedsSave); | | |||
522 | connect(m_settings, &FontsSettings::menuFontChanged, this, &KFonts::updateNeedsSave); | | |||
523 | connect(m_settings, &FontsSettings::activeFontChanged, this, &KFonts::updateNeedsSave); | | |||
524 | | ||||
525 | connect(m_fontAASettings, &FontAASettings::subPixelCurrentIndexChanged, this, updateState); | 517 | connect(m_fontAASettings, &FontAASettings::subPixelCurrentIndexChanged, this, updateState); | ||
526 | connect(m_fontAASettings, &FontAASettings::hintingCurrentIndexChanged, this, updateState); | 518 | connect(m_fontAASettings, &FontAASettings::hintingCurrentIndexChanged, this, updateState); | ||
527 | connect(m_fontAASettings, &FontAASettings::excludeChanged, this, updateState); | 519 | connect(m_fontAASettings, &FontAASettings::excludeChanged, this, updateState); | ||
528 | connect(m_fontAASettings, &FontAASettings::excludeFromChanged, this, updateState); | 520 | connect(m_fontAASettings, &FontAASettings::excludeFromChanged, this, updateState); | ||
529 | connect(m_fontAASettings, &FontAASettings::excludeToChanged, this, updateState); | 521 | connect(m_fontAASettings, &FontAASettings::excludeToChanged, this, updateState); | ||
530 | connect(m_fontAASettings, &FontAASettings::antiAliasingChanged, this, updateState); | 522 | connect(m_fontAASettings, &FontAASettings::antiAliasingChanged, this, updateState); | ||
531 | connect(m_fontAASettings, &FontAASettings::aliasingChanged, this, updateState); | 523 | connect(m_fontAASettings, &FontAASettings::aliasingChanged, this, updateState); | ||
532 | connect(m_fontAASettings, &FontAASettings::dpiChanged, this, updateState); | 524 | connect(m_fontAASettings, &FontAASettings::dpiChanged, this, updateState); | ||
533 | } | 525 | } | ||
534 | 526 | | |||
535 | KFonts::~KFonts() | 527 | KFonts::~KFonts() | ||
536 | { | 528 | { | ||
537 | } | 529 | } | ||
538 | 530 | | |||
539 | FontsSettings *KFonts::fontsSettings() const | 531 | FontsSettings *KFonts::fontsSettings() const | ||
540 | { | 532 | { | ||
541 | return m_settings; | 533 | return m_settings; | ||
542 | } | 534 | } | ||
543 | 535 | | |||
544 | void KFonts::defaults() | 536 | void KFonts::defaults() | ||
545 | { | 537 | { | ||
546 | m_settings->setDefaults(); | 538 | ManagedConfigModule::defaults(); | ||
547 | m_fontAASettings->defaults(); | 539 | m_fontAASettings->defaults(); | ||
548 | } | 540 | } | ||
549 | 541 | | |||
550 | void KFonts::setNearestExistingFonts() | 542 | void KFonts::setNearestExistingFonts() | ||
551 | { | 543 | { | ||
552 | m_settings->setFont(nearestExistingFont(m_settings->font())); | 544 | m_settings->setFont(nearestExistingFont(m_settings->font())); | ||
553 | m_settings->setFixed(nearestExistingFont(m_settings->fixed())); | 545 | m_settings->setFixed(nearestExistingFont(m_settings->fixed())); | ||
554 | m_settings->setSmallestReadableFont(nearestExistingFont(m_settings->smallestReadableFont())); | 546 | m_settings->setSmallestReadableFont(nearestExistingFont(m_settings->smallestReadableFont())); | ||
555 | m_settings->setToolBarFont(nearestExistingFont(m_settings->toolBarFont())); | 547 | m_settings->setToolBarFont(nearestExistingFont(m_settings->toolBarFont())); | ||
556 | m_settings->setMenuFont(nearestExistingFont(m_settings->menuFont())); | 548 | m_settings->setMenuFont(nearestExistingFont(m_settings->menuFont())); | ||
557 | m_settings->setActiveFont(nearestExistingFont(m_settings->activeFont())); | 549 | m_settings->setActiveFont(nearestExistingFont(m_settings->activeFont())); | ||
558 | } | 550 | } | ||
559 | 551 | | |||
560 | void KFonts::load() | 552 | void KFonts::load() | ||
561 | { | 553 | { | ||
562 | // first load all the settings | 554 | // first load all the settings | ||
563 | m_settings->load(); | 555 | ManagedConfigModule::load(); | ||
564 | m_fontAASettings->load(); | 556 | m_fontAASettings->load(); | ||
565 | 557 | | |||
566 | // Then set the existing fonts based on those settings | 558 | // Then set the existing fonts based on those settings | ||
567 | setNearestExistingFonts(); | 559 | setNearestExistingFonts(); | ||
568 | 560 | | |||
569 | // Load preview | 561 | // Load preview | ||
570 | // NOTE: This needs to be done AFTER AA settings is loaded | 562 | // NOTE: This needs to be done AFTER AA settings is loaded | ||
571 | // otherwise AA settings will be resetted in process of loading | 563 | // otherwise AA settings will be resetted in process of loading | ||
572 | // previews | 564 | // previews | ||
573 | engine()->addImageProvider("preview", new PreviewImageProvider(m_settings->font())); | 565 | engine()->addImageProvider("preview", new PreviewImageProvider(m_settings->font())); | ||
574 | 566 | | |||
575 | setNeedsSave(false); | 567 | // reload state after loading by emiting a settings signal | ||
568 | emit m_settings->activeFontChanged(); | ||||
576 | } | 569 | } | ||
577 | 570 | | |||
578 | void KFonts::save() | 571 | void KFonts::save() | ||
579 | { | 572 | { | ||
580 | m_settings->save(); | 573 | ManagedConfigModule::save(); | ||
581 | 574 | | |||
582 | KConfig _cfgfonts("kcmfonts"); | 575 | KConfig _cfgfonts("kcmfonts"); | ||
583 | KConfigGroup cfgfonts(&_cfgfonts, "General"); | 576 | KConfigGroup cfgfonts(&_cfgfonts, "General"); | ||
584 | 577 | | |||
585 | FontAASettings::AASetting aaSetting = FontAASettings::AASystem; | 578 | FontAASettings::AASetting aaSetting = FontAASettings::AASystem; | ||
586 | if (m_fontAASettings->antiAliasingNeedsSave()) { | 579 | if (m_fontAASettings->antiAliasingNeedsSave()) { | ||
587 | aaSetting = m_fontAASettings->antiAliasing() ? FontAASettings::AAEnabled : FontAASettings::AADisabled; | 580 | aaSetting = m_fontAASettings->antiAliasing() ? FontAASettings::AAEnabled : FontAASettings::AADisabled; | ||
588 | } | 581 | } | ||
589 | cfgfonts.writeEntry("dontChangeAASettings", aaSetting == FontAASettings::AASystem); | 582 | cfgfonts.writeEntry("dontChangeAASettings", aaSetting == FontAASettings::AASystem); | ||
590 | 583 | | |||
591 | if (aaSetting == FontAASettings::AAEnabled) { | 584 | if (aaSetting == FontAASettings::AAEnabled) { | ||
592 | m_fontAASettings->save(KXftConfig::AntiAliasing::Enabled); | 585 | m_fontAASettings->save(KXftConfig::AntiAliasing::Enabled); | ||
593 | } else if (aaSetting == FontAASettings::AADisabled) { | 586 | } else if (aaSetting == FontAASettings::AADisabled) { | ||
594 | m_fontAASettings->save(KXftConfig::AntiAliasing::Disabled); | 587 | m_fontAASettings->save(KXftConfig::AntiAliasing::Disabled); | ||
595 | } else { | 588 | } else { | ||
596 | m_fontAASettings->save(KXftConfig::AntiAliasing::NotSet); | 589 | m_fontAASettings->save(KXftConfig::AntiAliasing::NotSet); | ||
597 | } | 590 | } | ||
598 | 591 | | |||
599 | KGlobalSettings::self()->emitChange(KGlobalSettings::FontChanged); | 592 | KGlobalSettings::self()->emitChange(KGlobalSettings::FontChanged); | ||
600 | 593 | | |||
601 | runRdb(KRdbExportXftSettings | KRdbExportGtkTheme); | 594 | runRdb(KRdbExportXftSettings | KRdbExportGtkTheme); | ||
602 | 595 | | |||
603 | emit fontsHaveChanged(); | 596 | emit fontsHaveChanged(); | ||
604 | setNeedsSave(false); | | |||
605 | } | 597 | } | ||
606 | 598 | | |||
607 | void KFonts::updateNeedsSave() | 599 | bool KFonts::isSaveNeeded() const | ||
608 | { | 600 | { | ||
609 | setNeedsSave(m_settings->isSaveNeeded() || m_fontAASettings->needsSave()); | 601 | return m_fontAASettings->needsSave(); | ||
ervin: { should be on its own line | |||||
610 | } | 602 | } | ||
611 | 603 | | |||
612 | void KFonts::adjustAllFonts() | 604 | void KFonts::adjustAllFonts() | ||
613 | { | 605 | { | ||
614 | QFont font = m_settings->font(); | 606 | QFont font = m_settings->font(); | ||
615 | KFontChooser::FontDiffFlags fontDiffFlags; | 607 | KFontChooser::FontDiffFlags fontDiffFlags; | ||
616 | int ret = KFontDialog::getFontDiff(font, fontDiffFlags, KFontChooser::NoDisplayFlags); | 608 | int ret = KFontDialog::getFontDiff(font, fontDiffFlags, KFontChooser::NoDisplayFlags); | ||
617 | 609 | | |||
Show All 35 Lines |
{ should be on its own line