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.

cbookdisplay.cpp 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //
  2. // C++ Implementation: cbookdisplay
  3. //
  4. // Description:
  5. //
  6. //
  7. // Author: The BibleTime team <info@bibletime.info>, (C) 2004-2007
  8. //
  9. // Copyright: See COPYING file that comes with this distribution
  10. //
  11. //
  12. //Backend
  13. #include "cbookdisplay.h"
  14. #include "cdisplayrendering.h"
  15. #include "cswordbookmoduleinfo.h"
  16. #include "cswordtreekey.h"
  17. //Util
  18. #include "util/scoped_resource.h"
  19. namespace Rendering {
  20. /** Returns the rendered text using the modules in the list and using the key parameter. The displayoptions and filter options are used, too. */
  21. const TQString CBookDisplay::text( const ListCSwordModuleInfo& modules, const TQString& keyName, const CSwordBackend::DisplayOptions displayOptions, const CSwordBackend::FilterOptions filterOptions ) {
  22. CSwordBookModuleInfo* book = dynamic_cast<CSwordBookModuleInfo*>(modules.first());
  23. Q_ASSERT(book);
  24. CSwordBackend::DisplayOptions dOpts = displayOptions;
  25. dOpts.lineBreaks = true; //books should render with blocks, not with inlined sections
  26. CDisplayRendering render(dOpts, filterOptions);
  27. CDisplayRendering::KeyTree tree;
  28. CDisplayRendering::KeyTreeItem::Settings itemSettings;
  29. // the number of levels which should be display together, 1 means display no entries together
  30. int displayLevel = book->config( CSwordModuleInfo::DisplayLevel ).toInt();
  31. util::scoped_ptr<CSwordTreeKey> key (
  32. dynamic_cast<CSwordTreeKey*>( CSwordKey::createInstance(book) )
  33. );
  34. key->key(keyName); //set the key to position we'd like to get
  35. const unsigned long offset = key->getOffset();
  36. // standard of DisplayLevel, display nothing together
  37. // if the current key is the root entry don't display anything together!
  38. if ((displayLevel <= 1) || (key->key().isEmpty() || (key->key() == "/") )) {
  39. tree.append( new CDisplayRendering::KeyTreeItem( key->key(), modules, itemSettings ) );
  40. const TQString renderedText = render.renderKeyTree(tree);
  41. key->setOffset( offset );
  42. return renderedText;
  43. };
  44. /**
  45. * Check whether displaying displayLevel levels together is possible.
  46. * For this count the childs and parents
  47. * of the required position
  48. */
  49. int possibleLevels = 1; //we start with the default value of displayLevel, which means no entries together
  50. while( key->parent() && (key->key() != "/") && !key->key().isEmpty() ) {//add parents
  51. ++possibleLevels;
  52. };
  53. // key->key(keyName); //set the key to the start position
  54. key->setOffset( offset );
  55. while( key->firstChild( )) { //add childs
  56. ++possibleLevels;
  57. };
  58. if (possibleLevels < displayLevel) { //too few levels available!
  59. //display current level, we could also decide to display the available levels together
  60. tree.append( new CDisplayRendering::KeyTreeItem( key->key(), modules, itemSettings ) );
  61. const TQString renderedText = render.renderKeyTree(tree);
  62. key->setOffset( offset );
  63. return renderedText;
  64. };
  65. if ((displayLevel > 2) && (displayLevel == possibleLevels)) { //fix not to diplay the whole module
  66. --displayLevel;
  67. }
  68. // at this point we're sure that we can display the required levels toogether
  69. // at the moment we're at the lowest level, so we only have to go up!
  70. for (int currentLevel = 1; currentLevel < displayLevel; ++currentLevel) { //we start again with 1 == standard of displayLevel
  71. if ( !key->parent() ) { //something went wrong although we checked before! Be safe and return entry's text
  72. tree.append( new CDisplayRendering::KeyTreeItem( key->key(), modules, itemSettings ) );
  73. const TQString renderedText = render.renderKeyTree(tree);
  74. key->setOffset( offset );
  75. return renderedText;
  76. };
  77. };
  78. // no we can display all sub levels together! We checked before that this is possible!
  79. itemSettings.highlight = (key->key() == keyName);
  80. tree.append( new CDisplayRendering::KeyTreeItem( key->key(), modules, itemSettings ) );
  81. //const bool hasToplevelText = !key->strippedText().isEmpty();
  82. key->firstChild(); //go to the first sibling on the same level
  83. setupRenderTree(key.get(), &tree, keyName);
  84. const TQString renderedText = render.renderKeyTree(tree);
  85. key->setOffset( offset ); //restore key
  86. return renderedText;
  87. }
  88. void CBookDisplay::setupRenderTree(CSwordTreeKey * swordTree, CTextRendering::KeyTree * renderTree, const TQString& highlightKey) {
  89. // const TQString key = swordTree->getFullName();
  90. const TQString key = swordTree->key();
  91. const unsigned long offset = swordTree->getOffset();
  92. CTextRendering::KeyTreeItem::Settings settings;
  93. settings.highlight = (key == highlightKey);
  94. CTextRendering::KeyTreeItem* item = new CTextRendering::KeyTreeItem(key, swordTree->module(0), settings );
  95. renderTree->append( item );
  96. if (swordTree->hasChildren()) { //print tree for the child items
  97. swordTree->firstChild();
  98. setupRenderTree(swordTree, item->childList(), highlightKey);
  99. swordTree->setOffset( offset ); //go back where we came from
  100. }
  101. if (swordTree->nextSibling()) { //print tree for next entry on the same depth
  102. setupRenderTree(swordTree, renderTree, highlightKey);
  103. swordTree->setOffset( offset ); //return to the value we had at the beginning of this block!
  104. }
  105. }
  106. };