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.

cprinter.cpp 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*********
  2. *
  3. * This file is part of BibleTime's source code, http://www.bibletime.info/.
  4. *
  5. * Copyright 1999-2006 by the BibleTime developers.
  6. * The BibleTime source code is licensed under the GNU General Public License version 2.0.
  7. *
  8. **********/
  9. #include "cprinter.h"
  10. //BibleTime includes
  11. #include "backend/cdisplaytemplatemgr.h"
  12. #include "backend/cswordversekey.h"
  13. //KDE includes
  14. #include <tdehtml_part.h>
  15. #include <tdehtmlview.h>
  16. /* Class: CPrinter */
  17. namespace Printing {
  18. CPrinter::CPrinter(TQObject *, CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions)
  19. : TQObject(0),
  20. CDisplayRendering(displayOptions, filterOptions),
  21. m_htmlPart(new TDEHTMLPart(0, 0, this)) {
  22. //override the filteroptions set in the c-tor of CDisplayRendering
  23. m_filterOptions.footnotes = false;
  24. m_filterOptions.scriptureReferences = false;
  25. m_filterOptions.strongNumbers = false;
  26. m_filterOptions.morphTags = false;
  27. m_filterOptions.headings = false;
  28. m_htmlPart->setJScriptEnabled(false);
  29. m_htmlPart->setJavaEnabled(false);
  30. m_htmlPart->setMetaRefreshEnabled(false);
  31. m_htmlPart->setPluginsEnabled(false);
  32. m_htmlPart->view()->resize(500,500);
  33. m_htmlPart->view()->hide();
  34. }
  35. CPrinter::~CPrinter() {
  36. delete m_htmlPart;
  37. m_htmlPart = 0;
  38. }
  39. void CPrinter::printKeyTree( KeyTree& tree ) {
  40. m_htmlPart->begin();
  41. m_htmlPart->write(renderKeyTree(tree));
  42. m_htmlPart->end();
  43. m_htmlPart->view()->layout();
  44. m_htmlPart->view()->print();
  45. }
  46. const TQString CPrinter::entryLink(const KeyTreeItem& item, CSwordModuleInfo* module) {
  47. Q_ASSERT(module);
  48. if (module->type() == CSwordModuleInfo::Bible) {
  49. CSwordVerseKey vk(module);
  50. vk = item.key();
  51. switch (item.settings().keyRenderingFace) {
  52. case KeyTreeItem::Settings::CompleteShort:
  53. return TQString::fromUtf8(vk.getShortText());
  54. case KeyTreeItem::Settings::CompleteLong:
  55. return vk.key();
  56. case KeyTreeItem::Settings::NoKey:
  57. return TQString();
  58. case KeyTreeItem::Settings::SimpleKey: //fall through
  59. default:
  60. return TQString::number(vk.Verse());
  61. }
  62. }
  63. return item.key();
  64. }
  65. const TQString CPrinter::renderEntry( const KeyTreeItem& i, CSwordKey* ) {
  66. const CPrinter::KeyTreeItem* printItem = dynamic_cast<const CPrinter::KeyTreeItem*>(&i);
  67. Q_ASSERT(printItem);
  68. if (printItem && printItem->hasAlternativeContent()) {
  69. TQString ret = TQString::fromLatin1("<div class=\"entry\"><div class=\"rangeheading\">%1</div>").arg(printItem->getAlternativeContent());
  70. if (i.hasChildItems()) {
  71. KeyTree const * tree = i.childList();
  72. for ( KeyTreeItem* c = tree->first(); c; c = tree->next() ) {
  73. ret.append( CDisplayRendering::renderEntry( *c ) );
  74. }
  75. }
  76. ret.append("</div>");
  77. return ret;
  78. }
  79. return CDisplayRendering::renderEntry(i);
  80. }
  81. const TQString CPrinter::finishText(const TQString& text, KeyTree& tree) {
  82. ListCSwordModuleInfo modules = tree.collectModules();
  83. Q_ASSERT(modules.count() > 0);
  84. const CLanguageMgr::Language* const lang = modules.first()->language();
  85. Q_ASSERT(lang);
  86. CDisplayTemplateMgr::Settings settings;
  87. //settings.modules = modules;
  88. settings.pageCSS_ID = "printer";
  89. settings.langAbbrev = (lang && (modules.count() == 1) && lang->isValid())
  90. ? lang->abbrev()
  91. : "unknown";
  92. settings.pageDirection = (modules.count() == 1)
  93. ? ((modules.first()->textDirection() == CSwordModuleInfo::LeftToRight) ? "ltr" : "rtl")
  94. : TQString();
  95. CDisplayTemplateMgr* tMgr = CPointers::displayTemplateManager();
  96. return tMgr->fillTemplate(CBTConfig::get(CBTConfig::displayStyle), text, settings);
  97. }
  98. } //end of namespace
  99. #include "cprinter.moc"