BtFontSettingsPage::BtFontSettingsPage(CConfigurationDialog *parent) : BtConfigDialog::Page(util::getIcon(CResMgr::settings::fonts::icon), parent) { m_languageLabel = new QLabel(this); m_languageComboBox = new QComboBox(this); m_languageLabel->setBuddy(m_languageComboBox); m_languageCheckBox = new QCheckBox(this); connect(m_languageCheckBox, SIGNAL(toggled(bool)), this, SLOT(useOwnFontClicked(bool)) ); QHBoxLayout *hLayout = new QHBoxLayout; hLayout->setContentsMargins(0, 0, 0, 0); hLayout->addWidget(m_languageLabel, 0, Qt::AlignRight); hLayout->addWidget(m_languageComboBox, 1); hLayout->addWidget(m_languageCheckBox); CLanguageMgr::LangMap langMap = CLanguageMgr::instance()->availableLanguages(); typedef CLanguageMgr::Language L; for (CLanguageMgr::LangMapIterator it = langMap.constBegin(); it != langMap.constEnd(); it++) { const L * const l = *it; const QString &(L::*f)() const = l->translatedName().isEmpty() ? &L::abbrev : &L::translatedName; m_fontMap.insert((l->*f)(), btConfig().getFontForLanguage(*l)); } for (FontMap::ConstIterator it = m_fontMap.constBegin(); it != m_fontMap.constEnd(); ++it) { const QString &k = it.key(); if (m_fontMap[k].first) { // show font icon m_languageComboBox->addItem(util::getIcon("fonts.svg"), k); } else { // don't show icon for font m_languageComboBox->addItem(k); } } /// \todo remember the last selected font and jump there. m_fontChooser = new BtFontChooserWidget(this); /** \todo Eeli's wishlist: why not show something relevant here, like a Bible verse in chosen (not tr()'ed!) language? */ // m_fontChooser->setSampleText("SOMETHING"); connect(m_fontChooser, SIGNAL(fontSelected(const QFont&)), this, SLOT(newDisplayWindowFontSelected(const QFont&))); connect(m_languageComboBox, SIGNAL(activated(const QString&)), this, SLOT(newDisplayWindowFontAreaSelected(const QString&))); const BtConfig::FontSettingsPair &v = m_fontMap.value(m_languageComboBox->currentText()); m_fontChooser->setFont(v.second); useOwnFontClicked(v.first); m_languageCheckBox->setChecked(v.first); m_fontChooser->setMinimumSize(m_fontChooser->sizeHint()); QVBoxLayout *fLayout = new QVBoxLayout; fLayout->setContentsMargins(0, 0, 0, 0); fLayout->addLayout(hLayout); fLayout->addWidget(m_fontChooser); m_fontsGroupBox = new QGroupBox(this); m_fontsGroupBox->setFlat(true); m_fontsGroupBox->setLayout(fLayout); QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->addWidget(m_fontsGroupBox); retranslateUi(); }
CLanguageSettingsPage::CLanguageSettingsPage(QWidget* /*parent*/) : BtConfigPage() { namespace DU = util::directory; QVBoxLayout* layout = new QVBoxLayout(this); //Sword locales layout->addWidget( util::tool::explanationLabel( this, tr(""), tr("Select the language in which the Biblical book names are displayed.") )); m_swordLocaleCombo = new QComboBox(this); QLabel* label = new QLabel( tr("Language for names of Bible books:"), this); label->setBuddy(m_swordLocaleCombo); m_swordLocaleCombo->setToolTip(tr("The languages which can be used for the biblical booknames")); QHBoxLayout* hBoxLayout = new QHBoxLayout(); hBoxLayout->addWidget(label); hBoxLayout->addWidget(m_swordLocaleCombo); hBoxLayout->addStretch(); layout->addLayout(hBoxLayout); QStringList languageNames; languageNames.append( languageMgr()->languageForAbbrev("en_US")->translatedName() ); std::list<sword::SWBuf> locales = sword::LocaleMgr::getSystemLocaleMgr()->getAvailableLocales(); for (std::list<sword::SWBuf>::const_iterator it = locales.begin(); it != locales.end(); it++) { // qWarning("working on %s", (*it).c_str()); const CLanguageMgr::Language* const l = CPointers::languageMgr()->languageForAbbrev( sword::LocaleMgr::getSystemLocaleMgr()->getLocale((*it).c_str())->getName() ); if (l->isValid()) { languageNames.append( l->translatedName() ); } else { languageNames.append( sword::LocaleMgr::getSystemLocaleMgr()->getLocale((*it).c_str())->getDescription() ); } } //for languageNames.sort(); m_swordLocaleCombo->addItems( languageNames ); const CLanguageMgr::Language* const l = CPointers::languageMgr()->languageForAbbrev( CBTConfig::get(CBTConfig::language) ); QString currentLanguageName; if ( l->isValid() && languageNames.contains(l->translatedName()) ) { //tranlated language name is in the box currentLanguageName = l->translatedName(); } else { //a language like "German Abbrevs" might be the language to set sword::SWLocale* locale = sword::LocaleMgr::getSystemLocaleMgr()->getLocale( CBTConfig::get(CBTConfig::language).toLocal8Bit() ); if (locale) { currentLanguageName = QString::fromLatin1(locale->getDescription()); } } if (currentLanguageName.isEmpty()) { // set english as default if nothing was chosen Q_ASSERT(languageMgr()->languageForAbbrev("en_US")); currentLanguageName = languageMgr()->languageForAbbrev("en_US")->translatedName(); } //now set the item with the right name as current item for (int i = 0; i < m_swordLocaleCombo->count(); ++i) { if (currentLanguageName == m_swordLocaleCombo->itemText(i)) { m_swordLocaleCombo->setCurrentIndex(i); break; //item found, finish the loop } } layout->addSpacing(20); //Font settings layout->addWidget( util::tool::explanationLabel( this, tr("Fonts"), tr("You can specify a custom font for each language.") ) ); QHBoxLayout* hLayout = new QHBoxLayout(); m_usageCombo = new QComboBox(this); m_usageCombo->setToolTip(tr("The font selection below will apply to all texts in this language")); hLayout->addWidget(m_usageCombo); CLanguageMgr::LangMap langMap = languageMgr()->availableLanguages(); for (CLanguageMgr::LangMapIterator it = langMap.constBegin() ; it != langMap.constEnd(); ++it ) { const QString name = (*it)->translatedName().isEmpty() ? (*it)->abbrev() : (*it)->translatedName(); m_fontMap.insert(name, CBTConfig::get(*it) ); } for ( QMap<QString, CBTConfig::FontSettingsPair>::Iterator it = m_fontMap.begin(); it != m_fontMap.end(); ++it ) { if ( m_fontMap[it.key()].first ) { //show font icon m_usageCombo->addItem(DU::getIcon("fonts.svg"), it.key() ); } else { //don't show icon for font m_usageCombo->addItem(it.key()); } } m_useOwnFontCheck = new QCheckBox(tr("Use custom font"), this); m_useOwnFontCheck->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); connect(m_useOwnFontCheck, SIGNAL(toggled(bool)), SLOT(useOwnFontClicked(bool)) ); hLayout->addWidget(m_useOwnFontCheck); layout->addLayout(hLayout); hLayout->setContentsMargins(0, 0, 0, 0); /// \todo remember the last selected font and jump there. m_fontChooser = new CFontChooser(this); /// \todo Eeli's wishlist: why not show something relevant here, like a Bible verse in chosen (not tr()'ed!) language? QString sampleText; sampleText.append("1 In the beginning God created the heaven and the earth. "); sampleText.append("2 And the earth was without form, and void; and darkness was on the face of the deep."); sampleText.append(" And the Spirit of God moved on the face of the waters."); m_fontChooser->setSampleText(sampleText); layout->addWidget(m_fontChooser); connect(m_fontChooser, SIGNAL(fontSelected(const QFont&)), SLOT(newDisplayWindowFontSelected(const QFont&))); connect(m_usageCombo, SIGNAL(activated(const QString&)), SLOT(newDisplayWindowFontAreaSelected(const QString&))); m_fontChooser->setFont( m_fontMap[m_usageCombo->currentText()].second ); useOwnFontClicked( m_fontMap[m_usageCombo->currentText()].first ); m_useOwnFontCheck->setChecked( m_fontMap[m_usageCombo->currentText()].first ); m_fontChooser->setMinimumSize(m_fontChooser->sizeHint()); }