Bibletime – a bible study tool
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cdisplayrendering.cpp 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //
  2. // C++ Implementation: cdisplayrendering
  3. //
  4. // Description:
  5. //
  6. //
  7. // Author: The BibleTime team <info@bibletime.info>, (C) 2004
  8. //
  9. // Copyright: See COPYING file that comes with this distribution
  10. //
  11. //
  12. //Backend includes
  13. #include "cdisplayrendering.h"
  14. #include "cdisplaytemplatemgr.h"
  15. #include "creferencemanager.h"
  16. #include "cswordkey.h"
  17. #include "cswordversekey.h"
  18. //Qt includes
  19. #include <tqstring.h>
  20. #include <tqregexp.h>
  21. namespace Rendering {
  22. CDisplayRendering::CDisplayRendering(CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions)
  23. : CHTMLExportRendering(CHTMLExportRendering::Settings(true), displayOptions, filterOptions) {}
  24. const TQString CDisplayRendering::entryLink( const KeyTreeItem& item, CSwordModuleInfo* module ) {
  25. TQString linkText;
  26. const bool isBible = module && (module->type() == CSwordModuleInfo::Bible);
  27. CSwordVerseKey vk(module); //only valid for bible modules, i.e. isBible == true
  28. vk.Headings(true);
  29. if (isBible) {
  30. vk = item.key();
  31. }
  32. if (isBible && (vk.Verse() == 0)) {
  33. return TQString::null; //Warning: return already here
  34. }
  35. switch (item.settings().keyRenderingFace) {
  36. case KeyTreeItem::Settings::NoKey: {
  37. linkText = TQString::null;
  38. break; //no key is valid for all modules
  39. }
  40. case KeyTreeItem::Settings::CompleteShort: {
  41. if (isBible) {
  42. linkText = TQString::fromUtf8(vk.getShortText());
  43. break;
  44. }
  45. //fall through for non-Bible modules
  46. }
  47. case KeyTreeItem::Settings::CompleteLong: {
  48. if (isBible) {
  49. linkText = vk.key();
  50. break;
  51. }
  52. //fall through for non-Bible modules
  53. }
  54. case KeyTreeItem::Settings::SimpleKey: {
  55. if (isBible) {
  56. linkText = TQString::number(vk.Verse());
  57. break;
  58. }
  59. //fall through for non-Bible modules
  60. }
  61. default: { //default behaviour to return the passed key
  62. linkText = item.key();
  63. break;
  64. }
  65. }
  66. if (linkText.isEmpty()) {
  67. return TQString("<a name=\"").append(keyToHTMLAnchor(item.key())).append("\" />");
  68. }
  69. else {
  70. return TQString("<a name=\"").append(keyToHTMLAnchor(item.key())).append("\" ")
  71. .append("href=\"")
  72. .append(CReferenceManager::encodeHyperlink(
  73. module->name(), item.key(), CReferenceManager::typeFromModule(module->type()))
  74. )
  75. .append("\">").append(linkText).append("</a>\n");
  76. }
  77. return TQString::null;
  78. }
  79. const TQString CDisplayRendering::keyToHTMLAnchor(const TQString& key) {
  80. TQString ret = key;
  81. ret = ret.stripWhiteSpace().remove(TQRegExp("[^A-Za-z0-9]+"));
  82. ret = ret.remove(TQRegExp("^\\d+|"));
  83. return ret;
  84. }
  85. const TQString CDisplayRendering::finishText( const TQString& oldText, KeyTree& tree ) {
  86. ListCSwordModuleInfo modules = tree.collectModules();
  87. //marking words is very slow, we have to find a better solution
  88. /*
  89. //mark all words by spans
  90. TQString text = oldText;
  91. TQRegExp re("(\\b)(?=\\w)"); //word begin marker
  92. int pos = text.find(re, 0);
  93. while (pos != -1) { //word begin found
  94. //qWarning("found word at %i in %i", pos, text.length());
  95. int endPos = pos + 1;
  96. if (!CToolClass::inHTMLTag(pos+1, text)) { //the re has a positive look ahead which matches one char before the word start
  97. //qWarning("matched %s", text.mid(pos+1, 4).latin1());
  98. //find end of word and put a marker around it
  99. endPos = text.find(TQRegExp("\\b|[,.:]"), pos+1);
  100. if ((endPos != -1) && !CToolClass::inHTMLTag(endPos, text) && (endPos - pos >= 3)) { //reuire wordslonger than 3 chars
  101. text.insert(endPos, "</span>");
  102. text.insert(pos, "<span class=\"word\">");
  103. endPos += 26;
  104. }
  105. }
  106. pos = text.find(re, endPos);
  107. }
  108. */
  109. const CLanguageMgr::Language* const lang =
  110. (modules.count() >= 1)
  111. ? modules.first()->language()
  112. : CPointers::languageMgr()->defaultLanguage();
  113. CDisplayTemplateMgr* tMgr = CPointers::displayTemplateManager();
  114. Q_ASSERT(modules.count() >= 1);
  115. CDisplayTemplateMgr::Settings settings;
  116. settings.modules = modules;
  117. settings.langAbbrev = ((modules.count() == 1) && lang->isValid())
  118. ? lang->abbrev()
  119. : TQString::null;
  120. settings.pageDirection = (modules.count() == 1)
  121. ? ((modules.first()->textDirection() == CSwordModuleInfo::LeftToRight) ? "ltr" : "rtl")
  122. : TQString::null;
  123. return tMgr->fillTemplate(CBTConfig::get
  124. (CBTConfig::displayStyle), oldText, settings);
  125. }
  126. }