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);
}
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);
}
예제 #4
0
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);
}
예제 #5
0
	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);
	}