summaryrefslogtreecommitdiff
path: root/src/frontend/cinfodisplay.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend/cinfodisplay.cpp')
-rw-r--r--src/frontend/cinfodisplay.cpp304
1 files changed, 138 insertions, 166 deletions
diff --git a/src/frontend/cinfodisplay.cpp b/src/frontend/cinfodisplay.cpp
index 8165b8b..202eb48 100644
--- a/src/frontend/cinfodisplay.cpp
+++ b/src/frontend/cinfodisplay.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2011 by the BibleTime developers.
+* Copyright 1999-2014 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -20,15 +20,16 @@
#include <QtAlgorithms>
#include <QMenu>
-#include "backend/config/cbtconfig.h"
+#include "backend/config/btconfig.h"
#include "backend/drivers/cswordmoduleinfo.h"
#include "backend/keys/cswordkey.h"
#include "backend/keys/cswordversekey.h"
#include "backend/managers/referencemanager.h"
#include "backend/managers/cdisplaytemplatemgr.h"
+#include "bibletime.h"
#include "frontend/crossrefrendering.h"
-#include "frontend/display/cdisplay.h"
-#include "frontend/display/creaddisplay.h"
+#include "frontend/display/bthtmlreaddisplay.h"
+#include "util/htmlescape.h"
// Sword includes:
#include <listkey.h>
@@ -39,33 +40,36 @@ using namespace sword;
namespace InfoDisplay {
-CInfoDisplay::CInfoDisplay(QWidget *parent) : QWidget(parent) {
- QVBoxLayout* layout = new QVBoxLayout(this);
+CInfoDisplay::CInfoDisplay(BibleTime * parent)
+ : QWidget(parent)
+ , m_mainWindow(parent)
+{
+ QVBoxLayout * const layout = new QVBoxLayout(this);
layout->setContentsMargins(2, 2, 2, 2); // Leave small border
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
- m_htmlPart = CDisplay::createReadInstance(0, this);
- m_htmlPart->setMouseTracking(false); //we don't want strong/lemma/note mouse infos
+ m_htmlPart = new BtHtmlReadDisplay(0, this);
+ m_htmlPart->setMouseTracking(false); // We don't want strong/lemma/note mouse infos
m_htmlPart->view()->setAcceptDrops(false);
- QAction* selectAllAction = new QAction(QIcon(), tr("Select all"), this);
+ QAction * const selectAllAction = new QAction(QIcon(), tr("Select all"), this);
selectAllAction->setShortcut(QKeySequence::SelectAll);
- QObject::connect(selectAllAction, SIGNAL(triggered()), this, SLOT(selectAll()) );
+ QObject::connect(selectAllAction, SIGNAL(triggered()),
+ this, SLOT(selectAll()));
- QAction* copyAction = new QAction(tr("Copy"), this);
- copyAction->setShortcut( QKeySequence(Qt::CTRL + Qt::Key_C) );
- QObject::connect(copyAction, SIGNAL(triggered()), m_htmlPart->connectionsProxy(), SLOT(copySelection()) );
+ QAction * const copyAction = new QAction(tr("Copy"), this);
+ copyAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_C));
+ QObject::connect(copyAction, SIGNAL(triggered()),
+ m_htmlPart->connectionsProxy(), SLOT(copySelection()));
- QMenu* menu = new QMenu(this);
+ QMenu * const menu = new QMenu(this);
menu->addAction(selectAllAction);
menu->addAction(copyAction);
m_htmlPart->installPopup(menu);
- connect(
- m_htmlPart->connectionsProxy(),
- SIGNAL(referenceClicked(const QString&, const QString&)),
- SLOT(lookupInfo(const QString&, const QString&))
- );
+ QObject::connect(m_htmlPart->connectionsProxy(),
+ SIGNAL(referenceClicked(const QString &, const QString &)),
+ SLOT(lookupInfo(const QString &, const QString &)));
layout->addWidget(m_htmlPart->view());
@@ -80,102 +84,101 @@ void CInfoDisplay::unsetInfo() {
"moving the mouse.</small>"));
}
-void CInfoDisplay::setInfo(const QString &data, const QString &lang) {
- CDisplayTemplateMgr *mgr = CDisplayTemplateMgr::instance();
+void CInfoDisplay::setInfo(const QString & renderedData, const QString & lang) {
+ CDisplayTemplateMgr * const mgr = CDisplayTemplateMgr::instance();
Q_ASSERT(mgr != 0);
CDisplayTemplateMgr::Settings settings;
settings.pageCSS_ID = "infodisplay";
QString div = "<div class=\"infodisplay\"";
- if (!lang.isEmpty()) {
- div.append(" lang=\"");
- div.append(lang);
- div.append("\"");
- }
+ if (!lang.isEmpty())
+ div.append(" lang=\"").append(lang).append("\"");
+
div.append(">");
QString content(mgr->fillTemplate(CDisplayTemplateMgr::activeTemplateName(),
- div + data + "</div>",
+ div + renderedData + "</div>",
settings));
m_htmlPart->setText(content);
}
-void CInfoDisplay::lookupInfo(const QString &mod_name, const QString &key_text) {
+void CInfoDisplay::lookupInfo(const QString & mod_name,
+ const QString & key_text)
+{
qDebug() << "CInfoDisplay::lookup";
qDebug() << mod_name << key_text;
- CSwordModuleInfo* m = CSwordBackend::instance()->findModuleByName(mod_name);
+ CSwordModuleInfo * const m = CSwordBackend::instance()->findModuleByName(mod_name);
Q_ASSERT(m);
if (!m)
return;
- QSharedPointer<CSwordKey> key( CSwordKey::createInstance(m) );
+ QSharedPointer<CSwordKey> key(CSwordKey::createInstance(m));
key->setKey(key_text);
setInfo(key->renderedText(), m->language()->abbrev());
}
-void CInfoDisplay::setInfo(const InfoType type, const QString& data) {
+void CInfoDisplay::setInfo(const InfoType type, const QString & data) {
ListInfoData list;
- list.append( qMakePair(type, data) );
-
+ list.append(qMakePair(type, data));
setInfo(list);
}
-void CInfoDisplay::setInfo(const ListInfoData& list) {
- //if the widget is hidden it would be inefficient to render and display the data
- if (!isVisible()) {
+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.isEmpty()) {
m_htmlPart->setText("<html></html>");
return;
}
- QString text;
+ QString renderedText;
ListInfoData::const_iterator end = list.end();
for (ListInfoData::const_iterator it = list.begin(); it != end; ++it) {
- switch ( (*it).first ) {
+ switch ((*it).first) {
case Lemma:
- text.append( decodeStrongs( (*it).second ) );
+ renderedText.append(decodeStrongs((*it).second));
continue;
case Morph:
- text.append( decodeMorph( (*it).second ) );
+ renderedText.append(decodeMorph((*it).second));
continue;
case CrossReference:
- text.append( decodeCrossReference( (*it).second ) );
+ renderedText.append(decodeCrossReference((*it).second));
continue;
case Footnote:
- text.append( decodeFootnote( (*it).second ) );
+ renderedText.append(decodeFootnote((*it).second));
continue;
case WordTranslation:
- text.append( getWordTranslation( (*it).second ) );
+ renderedText.append(getWordTranslation((*it).second));
continue;
case WordGloss:
- //text.append( getWordTranslation( (*it).second ) );
+ //text.append(getWordTranslation((*it).second));
continue;
case Abbreviation:
- text.append( decodeAbbreviation( (*it).second ) );
+ renderedText.append(decodeAbbreviation((*it).second));
continue;
case Text:
- text.append( (*it).second );
+ renderedText.append((*it).second);
continue;
default:
continue;
};
}
-
- setInfo(text);
+ setInfo(renderedText);
}
-void CInfoDisplay::setInfo(CSwordModuleInfo *module) {
+void CInfoDisplay::setInfo(CSwordModuleInfo * const module) {
+ using util::htmlEscape;
+
if (module) {
setInfo(tr("<div class=\"moduleinfo\"><h3>%1</h3><p>%2</p><p>Version: %3</p></div>")
- .arg(module->name())
- .arg(module->config(CSwordModuleInfo::Description))
- .arg(module->config(CSwordModuleInfo::ModuleVersion)));
+ .arg(htmlEscape(module->name()))
+ .arg(htmlEscape(module->config(CSwordModuleInfo::Description)))
+ .arg(htmlEscape(module->config(CSwordModuleInfo::ModuleVersion))));
} else {
unsetInfo();
}
@@ -185,28 +188,21 @@ void CInfoDisplay::selectAll() {
m_htmlPart->selectAll();
}
-const QString CInfoDisplay::decodeAbbreviation( const QString& data ) {
- // QStringList strongs = QStringList::split("|", data);
- QString ret;
- QString text = data;
-
- ret.append(
- QString("<div class=\"abbreviation\"><h3>%1: %2</h3><p>%3</p></div>")
+const QString CInfoDisplay::decodeAbbreviation(const QString & data) {
+ // QStringList strongs = QStringList::split("|", data);
+ return QString("<div class=\"abbreviation\"><h3>%1: %2</h3><p>%3</p></div>")
.arg(tr("Abbreviation"))
.arg("text")
- .arg(text));
-
- return ret;
+ .arg(data);
}
-const QString CInfoDisplay::decodeCrossReference( const QString& data ) {
+const QString CInfoDisplay::decodeCrossReference(const QString & data) {
Q_ASSERT(!data.isEmpty());
- if (data.isEmpty()) {
+ if (data.isEmpty())
return QString("<div class=\"crossrefinfo\"><h3>%1</h3></div>")
.arg(tr("Cross references"));
- }
- // qWarning("setting crossref %s", data.latin1());
+ // qWarning("setting crossref %s", data.latin1());
DisplayOptions dispOpts;
dispOpts.lineBreaks = false;
@@ -223,99 +219,87 @@ const QString CInfoDisplay::decodeCrossReference( const QString& data ) {
CrossRefRendering renderer(dispOpts, filterOpts);
CTextRendering::KeyTree tree;
- // const bool isBible = true;
- CSwordModuleInfo* module = CBTConfig::get(CBTConfig::standardBible);
+ // const bool isBible = true;
+ const CSwordModuleInfo * module = btConfig().getDefaultSwordModuleByType("standardBible");
+ if (!module)
+ module = m_mainWindow->getCurrentModule();
- //a prefixed module gives the module to look into
+ // a prefixed module gives the module to look into
QRegExp re("^[^ ]+:");
- // re.setMinimal(true);
+ // re.setMinimal(true);
int pos = re.indexIn(data);
- if (pos != -1) {
+ if (pos != -1)
pos += re.matchedLength() - 1;
- }
if (pos > 0) {
const QString moduleName = data.left(pos);
- // qWarning("found module %s", moduleName.latin1());
+ // qWarning("found module %s", moduleName.latin1());
module = CSwordBackend::instance()->findModuleByName(moduleName);
- if (!module) {
- module = CBTConfig::get(CBTConfig::standardBible);
- }
- // Q_ASSERT(module);
+ if (!module)
+ module = btConfig().getDefaultSwordModuleByType("standardBible");
+ // Q_ASSERT(module);
}
- //Q_ASSERT(module); //why? the existense of the module is tested later
- CTextRendering::KeyTreeItem::Settings settings (
+ // Q_ASSERT(module); // why? the existense of the module is tested later
+ CTextRendering::KeyTreeItem::Settings settings(
false,
CTextRendering::KeyTreeItem::Settings::CompleteShort
);
if (module && (module->type() == CSwordModuleInfo::Bible)) {
VerseKey vk;
- sword::ListKey refs = vk.ParseVerseList((const char*)data.mid((pos == -1) ? 0 : pos + 1).toUtf8(), "Gen 1:1", true);
+ sword::ListKey refs = vk.parseVerseList((const char*) data.mid((pos == -1) ? 0 : pos + 1).toUtf8(), "Gen 1:1", true);
- for (int i = 0; i < refs.Count(); ++i) {
- SWKey* key = refs.getElement(i);
+ for (int i = 0; i < refs.getCount(); i++) {
+ SWKey * const key = refs.getElement(i);
Q_ASSERT(key);
- VerseKey* vk = dynamic_cast<VerseKey*>(key);
+ VerseKey * const vk = dynamic_cast<VerseKey*>(key);
- CTextRendering::KeyTreeItem* itm = (CTextRendering::KeyTreeItem*)0; //explicit conversion for MS VS
- if (vk && vk->isBoundSet()) { //render a range of keys
- itm = new CTextRendering::KeyTreeItem(
- QString::fromUtf8(vk->LowerBound().getText()),
- QString::fromUtf8(vk->UpperBound().getText()),
+ if (vk && vk->isBoundSet()) { // render a range of keys
+ tree.append(new CTextRendering::KeyTreeItem(
+ QString::fromUtf8(vk->getLowerBound().getText()),
+ QString::fromUtf8(vk->getUpperBound().getText()),
module,
settings
- );
- }
- else {
- itm = new CTextRendering::KeyTreeItem(
+ ));
+ } else {
+ tree.append(new CTextRendering::KeyTreeItem(
QString::fromUtf8(key->getText()),
QString::fromUtf8(key->getText()),
module,
settings
- );
+ ));
}
-
- Q_ASSERT(itm);
-
- tree.append( itm );
}
- }
- else if (module) {
- CTextRendering::KeyTreeItem* itm = new CTextRendering::KeyTreeItem(
- data.mid((pos == -1) ? 0 : pos + 1),
- module,
- settings
- );
- tree.append( itm );
+ } else if (module) {
+ tree.append(new CTextRendering::KeyTreeItem(data.mid((pos == -1)
+ ? 0
+ : pos + 1),
+ module,
+ settings));
}
- // qWarning("rendered the tree: %s", renderer.renderKeyTree(tree).latin1());
- //spanns containing rtl text need dir=rtl on their parent tag to be aligned properly
+ // qWarning("rendered the tree: %s", renderer.renderKeyTree(tree).latin1());
+ // spanns containing rtl text need dir=rtl on their parent tag to be aligned properly
QString lang = "en"; // default english
- if (module) {
+ if (module)
lang = module->language()->abbrev();
- }
-
- const QString RenderedText = renderer.renderKeyTree(tree);
return QString("<div class=\"crossrefinfo\" lang=\"%1\"><h3>%2</h3><div class=\"para\" dir=\"%3\">%4</div></div>")
.arg(lang)
.arg(tr("Cross references"))
.arg(module ? ((module->textDirection() == CSwordModuleInfo::LeftToRight) ? "ltr" : "rtl") : "")
- .arg(RenderedText);
+ .arg(renderer.renderKeyTree(tree));
}
/*!
- \fn CInfoDisplay::decodeFootnote( const QString& data )
+ \fn CInfoDisplay::decodeFootnote(const QString & data)
*/
-const QString CInfoDisplay::decodeFootnote( const QString& data ) {
+const QString CInfoDisplay::decodeFootnote(const QString & data) {
QStringList list = data.split("/");
Q_ASSERT(list.count() >= 3);
- if (!list.count()) {
+ if (!list.count())
return QString::null;
- }
FilterOptions filterOpts;
filterOpts.headings = false;
@@ -336,25 +320,23 @@ const QString CInfoDisplay::decodeFootnote( const QString& data ) {
list.pop_front();
const QString keyname = list.join("/");
- CSwordModuleInfo* module = CSwordBackend::instance()->findModuleByName(modulename);
- if (!module) {
+ CSwordModuleInfo * const module = CSwordBackend::instance()->findModuleByName(modulename);
+ if (!module)
return QString::null;
- }
- QSharedPointer<CSwordKey> key( CSwordKey::createInstance(module) );
+ QSharedPointer<CSwordKey> key(CSwordKey::createInstance(module));
key->setKey(keyname);
- key->renderedText(CSwordKey::ProcessEntryAttributesOnly); //force entryAttributes
+ key->renderedText(CSwordKey::ProcessEntryAttributesOnly); // force entryAttributes
- const char* note =
+ const char * const note =
module->module()->getEntryAttributes()
["Footnote"][swordFootnote.toLatin1().data()]["body"].c_str();
QString text = module->isUnicode() ? QString::fromUtf8(note) : QString(note);
- text = QString::fromUtf8(module->module()->RenderText(
+ text = QString::fromUtf8(module->module()->renderText(
module->isUnicode()
- ? (const char*)text.toUtf8()
- : (const char*)text.toLatin1()
- ));
+ ? static_cast<const char *>(text.toUtf8())
+ : static_cast<const char *>(text.toLatin1())));
return QString("<div class=\"footnoteinfo\" lang=\"%1\"><h3>%2</h3><p>%3</p></div>")
.arg(module->language()->abbrev())
@@ -362,22 +344,22 @@ const QString CInfoDisplay::decodeFootnote( const QString& data ) {
.arg(text);
}
-const QString CInfoDisplay::decodeStrongs( const QString& data ) {
+const QString CInfoDisplay::decodeStrongs(const QString & data) {
QStringList strongs = data.split("|");
QString ret;
QStringList::const_iterator end = strongs.end();
for (QStringList::const_iterator it = strongs.begin(); it != end; ++it) {
- CSwordModuleInfo* const module = CBTConfig::get
+ CSwordModuleInfo * const module = btConfig().getDefaultSwordModuleByType
(
((*it).left(1) == QString("H")) ?
- CBTConfig::standardHebrewStrongsLexicon :
- CBTConfig::standardGreekStrongsLexicon
+ "standardHebrewStrongsLexicon" :
+ "standardGreekStrongsLexicon"
);
QString text;
if (module) {
- QSharedPointer<CSwordKey> key( CSwordKey::createInstance(module) );
+ QSharedPointer<CSwordKey> key(CSwordKey::createInstance(module));
key->setKey((*it).mid(1)); // skip H or G (language sign), will have to change later if we have better modules
text = key->renderedText();
}
@@ -398,13 +380,13 @@ const QString CInfoDisplay::decodeStrongs( const QString& data ) {
return ret;
}
-const QString CInfoDisplay::decodeMorph( const QString& data ) {
+const QString CInfoDisplay::decodeMorph(const QString & data) {
QStringList morphs = data.split("|");
QString ret;
- foreach(QString morph, morphs) {
+ Q_FOREACH (QString morph, morphs) {
//qDebug() << "CInfoDisplay::decodeMorph, morph: " << morph;
- CSwordModuleInfo* module = 0;
+ CSwordModuleInfo * module = 0;
bool skipFirstChar = false;
QString value = "";
QString valueClass = "";
@@ -412,8 +394,8 @@ const QString CInfoDisplay::decodeMorph( const QString& data ) {
int valStart = morph.indexOf(':');
if (valStart > -1) {
valueClass = morph.mid(0, valStart);
- //qDebug() << "valueClass: " << valueClass;
- module = CSwordBackend::instance()->findModuleByName( valueClass );
+ // qDebug() << "valueClass: " << valueClass;
+ module = CSwordBackend::instance()->findModuleByName(valueClass);
}
value = morph.mid(valStart + 1); //works for prepended module and without (-1 +1 == 0).
@@ -425,51 +407,46 @@ const QString CInfoDisplay::decodeMorph( const QString& data ) {
if (value.size() > 1 && value.at(1).isDigit()) {
switch (value.at(0).toLatin1()) {
case 'G':
- module = CBTConfig::get
- (CBTConfig::standardGreekMorphLexicon);
+ module = btConfig().getDefaultSwordModuleByType("standardGreekMorphLexicon");
skipFirstChar = true;
break;
case 'H':
- module = CBTConfig::get
- (CBTConfig::standardHebrewMorphLexicon);
+ module = btConfig().getDefaultSwordModuleByType("standardHebrewMorphLexicon");
skipFirstChar = true;
break;
default:
skipFirstChar = false;
/// \todo we can't tell here if it's a greek or hebrew moprh code, that's a problem we have to solve
- // module = CBTConfig::get(CBTConfig::standardGreekMorphLexicon);
+ // module = getBtConfig().getDefaultSwordModuleByType("standardGreekMorphLexicon");
break;
}
}
//if it is still not set use the default
- if (!module) {
- module = CBTConfig::get
- (CBTConfig::standardGreekMorphLexicon);
- }
+ if (!module)
+ module = btConfig().getDefaultSwordModuleByType("standardGreekMorphLexicon");
}
QString text;
- //Q_ASSERT(module);
+ // Q_ASSERT(module);
if (module) {
- QSharedPointer<CSwordKey> key( CSwordKey::createInstance(module) );
+ QSharedPointer<CSwordKey> key(CSwordKey::createInstance(module));
- //skip H or G (language sign) if we have to skip it
+ // skip H or G (language sign) if we have to skip it
const bool isOk = key->setKey(skipFirstChar ? value.mid(1) : value);
- //Q_ASSERT(isOk);
- if (!isOk) { //try to use the other morph lexicon, because this one failed with the current morph code
- key->setModule(CBTConfig::get
- (CBTConfig::standardHebrewMorphLexicon));
+ // Q_ASSERT(isOk);
+ if (!isOk) { // try to use the other morph lexicon, because this one failed with the current morph code
+ key->setModule(btConfig().getDefaultSwordModuleByType("standardHebrewMorphLexicon")); /// \todo: what if the module doesn't exist?
key->setKey(skipFirstChar ? value.mid(1) : value);
}
text = key->renderedText();
}
- //if the module wasn't found just display an empty morph info
+ // if the module wasn't found just display an empty morph info
QString lang = "en"; // default to english
if (module)
lang = module->language()->abbrev();
- ret.append( QString("<div class=\"morphinfo\" lang=\"%1\"><h3>%2: %3</h3><p>%4</p></div>")
+ ret.append(QString("<div class=\"morphinfo\" lang=\"%1\"><h3>%2: %3</h3><p>%4</p></div>")
.arg(lang)
.arg(tr("Morphology"))
.arg(value)
@@ -480,26 +457,21 @@ const QString CInfoDisplay::decodeMorph( const QString& data ) {
return ret;
}
-const QString CInfoDisplay::getWordTranslation( const QString& data ) {
- CSwordModuleInfo* const module = CBTConfig::get
- (CBTConfig::standardLexicon);
- if (!module) {
+const QString CInfoDisplay::getWordTranslation(const QString & data) {
+ CSwordModuleInfo * const module = btConfig().getDefaultSwordModuleByType("standardLexicon");
+ if (!module)
return QString::null;
- }
- QSharedPointer<CSwordKey> key( CSwordKey::createInstance(module) );
+ QSharedPointer<CSwordKey> key(CSwordKey::createInstance(module));
key->setKey(data);
- if (key->key().toUpper() != data.toUpper()) { //key not present in the lexicon
+ if (key->key().toUpper() != data.toUpper()) //key not present in the lexicon
return QString::null;
- }
- QString ret = QString("<div class=\"translationinfo\" lang=\"%1\"><h3>%2: %3</h3><p>%4</p></div>")
+ return QString("<div class=\"translationinfo\" lang=\"%1\"><h3>%2: %3</h3><p>%4</p></div>")
.arg(module->language()->abbrev())
.arg(tr("Word lookup"))
.arg(data)
.arg(key->renderedText());
-
- return ret;
}
QSize CInfoDisplay::sizeHint() const {