void CInfoDisplay::lookupInfo(const QString &mod_name, const QString &key_text) { qDebug("CInfoDisplay::lookup"); qDebug() << mod_name << key_text; CSwordModuleInfo* m = CPointers::backend()->findModuleByName(mod_name); Q_ASSERT(m); if (!m) return; boost::scoped_ptr<CSwordKey> key( CSwordKey::createInstance(m) ); key->key( key_text ); CDisplayTemplateMgr* mgr = CPointers::displayTemplateManager(); CDisplayTemplateMgr::Settings settings; settings.pageCSS_ID = "infodisplay"; // lookup text and wrap in a "div" with language set to module language QString lang = m->language()->abbrev(); QString renderedText = key->renderedText(); QString divText = "<div class=\"infodisplay\" lang=\""; divText.append(lang); divText.append("\">"); divText.append(renderedText); divText.append("</div>"); QString content = mgr->fillTemplate(CBTConfig::get (CBTConfig::displayStyle), divText, settings); m_htmlPart->setText(content); }
/** Initializes the startup section of the OD. */ CDisplaySettingsPage::CDisplaySettingsPage(CConfigurationDialog *parent) : BtConfigDialog::Page(CResMgr::settings::startup::icon(), parent) { QVBoxLayout *mainLayout = new QVBoxLayout(this); QFormLayout *formLayout = new QFormLayout(); //startup logo m_showLogoLabel = new QLabel(this); m_showLogoCheck = new QCheckBox(this); m_showLogoCheck->setChecked(btConfig().value<bool>("GUI/showSplashScreen", true)); formLayout->addRow(m_showLogoLabel, m_showLogoCheck); m_swordLocaleCombo = new QComboBox(this); m_languageNamesLabel = new QLabel(this); m_languageNamesLabel->setBuddy(m_swordLocaleCombo); formLayout->addRow(m_languageNamesLabel, m_swordLocaleCombo); initSwordLocaleCombo(); m_styleChooserCombo = new QComboBox( this ); //create first to enable buddy for label BT_CONNECT(m_styleChooserCombo, SIGNAL(activated(int)), this, SLOT(updateStylePreview())); m_availableLabel = new QLabel(this); m_availableLabel->setBuddy(m_styleChooserCombo); formLayout->addRow(m_availableLabel, m_styleChooserCombo ); mainLayout->addLayout(formLayout); m_previewLabel = new QLabel(this); m_previewLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); m_stylePreviewViewer = new QLabel(this); m_stylePreviewViewer->setWordWrap(true); m_stylePreviewViewer->setTextFormat(Qt::RichText); m_stylePreviewViewer->setStyleSheet("QLabel { background-color: rgb(255, 255, 255) }"); m_stylePreviewViewer->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); m_stylePreviewViewer->setAlignment(Qt::AlignTop); m_stylePreviewViewer->setMargin(15); mainLayout->addWidget(m_previewLabel); mainLayout->addWidget(m_stylePreviewViewer); CDisplayTemplateMgr * tMgr = CDisplayTemplateMgr::instance(); m_styleChooserCombo->addItems(tMgr->availableTemplates()); for (int i = 0; i < m_styleChooserCombo->count(); ++i) { if (m_styleChooserCombo->itemText(i) == CDisplayTemplateMgr::activeTemplateName()) { m_styleChooserCombo->setCurrentIndex(i); break; } } m_transifexLabel = new QLabel(this); mainLayout->addWidget(m_transifexLabel); retranslateUi(); // also calls updateStylePreview(); }
void CInfoDisplay::setInfo(const ListInfoData& list) { //if the widget is hidden it would be inefficient to render and display the data if (!isVisible()) { return; } if (list.count() == 0) { m_htmlPart->setText("<html></html>"); return; } QString text; ListInfoData::const_iterator end = list.end(); for (ListInfoData::const_iterator it = list.begin(); it != end; ++it) { switch ( (*it).first ) { case Lemma: text.append( decodeStrongs( (*it).second ) ); continue; case Morph: text.append( decodeMorph( (*it).second ) ); continue; case CrossReference: text.append( decodeCrossReference( (*it).second ) ); continue; case Footnote: text.append( decodeFootnote( (*it).second ) ); continue; case WordTranslation: text.append( getWordTranslation( (*it).second ) ); continue; case WordGloss: //text.append( getWordTranslation( (*it).second ) ); continue; case Abbreviation: text.append( decodeAbbreviation( (*it).second ) ); continue; case Text: text.append( (*it).second ); continue; default: continue; }; } CDisplayTemplateMgr* mgr = CPointers::displayTemplateManager(); CDisplayTemplateMgr::Settings settings; settings.pageCSS_ID = "infodisplay"; // settings.langAbbrev = ""; QString content = mgr->fillTemplate(CBTConfig::get (CBTConfig::displayStyle), text, settings); // qWarning("setting text:\n%s", content.latin1()); m_htmlPart->setText(content); }
const QString CDisplayRendering::finishText( const QString& oldText, KeyTree& tree ) { QList<CSwordModuleInfo*> modules = collectModules(&tree); qDebug() << "CDisplayRendering::finishText"; //marking words is very slow, we have to find a better solution /* //mark all words by spans QString text = oldText; QRegExp re("(\\b)(?=\\w)"); //word begin marker int pos = text.find(re, 0); while (pos != -1) { //word begin found //qWarning("found word at %i in %i", pos, text.length()); int endPos = pos + 1; if (!util::tool::inHTMLTag(pos+1, text)) { //the re has a positive look ahead which matches one char before the word start //qWarning("matched %s", text.mid(pos+1, 4).latin1()); //find end of word and put a marker around it endPos = text.find(QRegExp("\\b|[,.:]"), pos+1); if ((endPos != -1) && !util::tool::inHTMLTag(endPos, text) && (endPos - pos >= 3)) { //reuire wordslonger than 3 chars text.insert(endPos, "</span>"); text.insert(pos, "<span class=\"word\">"); endPos += 26; } } pos = text.find(re, endPos); } */ const CLanguageMgr::Language* const lang = (modules.count() >= 1) ? modules.first()->language() : CPointers::languageMgr()->defaultLanguage(); CDisplayTemplateMgr* tMgr = CPointers::displayTemplateManager(); //Q_ASSERT(modules.count() >= 1); CDisplayTemplateMgr::Settings settings; settings.modules = modules; settings.langAbbrev = ((modules.count() == 1) && lang->isValid()) ? lang->abbrev() : QString::null; if (modules.count() == 1) settings.pageDirection = (modules.first()->textDirection() == CSwordModuleInfo::LeftToRight) ? "ltr" : "rtl"; else settings.pageDirection = QString::null; return tMgr->fillTemplate(CBTConfig::get(CBTConfig::displayStyle), oldText, settings); }
QString CDisplayRendering::finishText(const QString &text, const KeyTree &tree) { BtConstModuleList modules = collectModules(tree); //marking words is very slow, we have to find a better solution /* //mark all words by spans QString text = oldText; QRegExp re("(\\b)(?=\\w)"); //word begin marker int pos = text.find(re, 0); while (pos != -1) { //word begin found //qWarning("found word at %i in %i", pos, text.length()); int endPos = pos + 1; if (!util::tool::inHTMLTag(pos+1, text)) { //the re has a positive look ahead which matches one char before the word start //qWarning("matched %s", text.mid(pos+1, 4).latin1()); //find end of word and put a marker around it endPos = text.find(QRegExp("\\b|[,.:]"), pos+1); if ((endPos != -1) && !util::tool::inHTMLTag(endPos, text) && (endPos - pos >= 3)) { //reuire wordslonger than 3 chars text.insert(endPos, "</span>"); text.insert(pos, "<span class=\"word\">"); endPos += 26; } } pos = text.find(re, endPos); } */ const CLanguageMgr::Language* const lang = (modules.count() >= 1) ? modules.first()->language() : CLanguageMgr::instance()->defaultLanguage(); CDisplayTemplateMgr *tMgr = CDisplayTemplateMgr::instance(); //Q_ASSERT(modules.count() >= 1); CDisplayTemplateMgr::Settings settings; settings.modules = modules; if (modules.count() == 1 && lang->isValid()) settings.langAbbrev = lang->abbrev(); if (modules.count() == 1) settings.textDirection = modules.first()->textDirection(); return tMgr->fillTemplate(CDisplayTemplateMgr::activeTemplateName(), text, settings); }
const QString CPrinter::finishText(const QString& text, KeyTree& tree) { ListCSwordModuleInfo modules = tree.collectModules(); Q_ASSERT(modules.count() > 0); const CLanguageMgr::Language* const lang = modules.first()->language(); Q_ASSERT(lang); CDisplayTemplateMgr::Settings settings; //settings.modules = modules; settings.pageCSS_ID = "printer"; settings.langAbbrev = (lang && (modules.count() == 1) && lang->isValid()) ? lang->abbrev() : "unknown"; settings.pageDirection = (modules.count() == 1) ? ((modules.first()->textDirection() == CSwordModuleInfo::LeftToRight) ? "ltr" : "rtl") : QString::null; CDisplayTemplateMgr* tMgr = CPointers::displayTemplateManager(); return tMgr->fillTemplate(CBTConfig::get(CBTConfig::displayStyle), text, settings); }