BibleTime
btprinter.cpp
Go to the documentation of this file.
1 /*********
2 *
3 * In the name of the Father, and of the Son, and of the Holy Spirit.
4 *
5 * This file is part of BibleTime's source code, https://bibletime.info/
6 *
7 * Copyright 1999-2021 by the BibleTime developers.
8 * The BibleTime source code is licensed under the GNU General Public License
9 * version 2.0.
10 *
11 **********/
12 
13 #include "btprinter.h"
14 
15 #include <QPrintDialog>
16 #include <QPrinter>
17 #include <QTextEdit>
18 #include "../backend/keys/cswordversekey.h"
19 #include "../backend/managers/cdisplaytemplatemgr.h"
20 #include "../util/btassert.h"
21 
22 
23 namespace {
24 
26  fo.footnotes = false;
27  fo.scriptureReferences = false;
28  fo.strongNumbers = false;
29  fo.morphTags = false;
30  fo.headings = false;
31  return fo;
32 }
33 
34 } // anonymous namespace
35 
36 BtPrinter::BtPrinter(DisplayOptions const & displayOptions,
37  FilterOptions const & filterOptions,
38  QObject * const parent)
39  : QObject{parent}
40  , CDisplayRendering{displayOptions, mangleFilterOptions(filterOptions)}
41 {}
42 
43 void BtPrinter::printKeyTree(KeyTree const & tree) {
44  QTextEdit htmlPage;
45  htmlPage.setHtml(renderKeyTree(tree));
46 
47  QPrinter printer;
48  QPrintDialog printDialog(&printer);
49  if (printDialog.exec() == QDialog::Accepted)
50  htmlPage.print(&printer);
51 }
52 
53 QString BtPrinter::entryLink(KeyTreeItem const & item,
54  CSwordModuleInfo const & module) const
55 {
56  if (module.type() != CSwordModuleInfo::Bible)
57  return item.key();
58 
59  CSwordVerseKey vk(&module);
60  vk.setKey(item.key());
61  switch (item.settings().keyRenderingFace) {
62  case KeyTreeItem::Settings::CompleteShort:
63  return vk.shortText();
64 
65  case KeyTreeItem::Settings::CompleteLong:
66  return vk.key();
67 
68  case KeyTreeItem::Settings::NoKey:
69  return QString();
70 
71  case KeyTreeItem::Settings::SimpleKey: // fall through:
72  default:
73  return QString::number(vk.verse());
74  }
75 }
76 
77 QString BtPrinter::renderEntry(KeyTreeItem const & i, CSwordKey * key) const {
78  Q_UNUSED(key)
79  BtPrinter::KeyTreeItem const * const printItem =
80  static_cast<BtPrinter::KeyTreeItem const *>(&i);
81 
82  if (printItem->hasAlternativeContent()) {
83  auto ret =
84  QStringLiteral(
85  "<div class=\"entry\"><div class=\"rangeheading\">%1</div>")
86  .arg(printItem->getAlternativeContent());
87  if (!i.childList().empty())
88  for (auto const & item : i.childList())
89  ret.append(CDisplayRendering::renderEntry(item));
90  ret.append(QStringLiteral("</div>"));
91  return ret;
92  }
93  return CDisplayRendering::renderEntry(i);
94 }
95 
96 QString BtPrinter::finishText(QString const & text, KeyTree const & tree) const
97 {
98  BtConstModuleList const modules = collectModules(tree);
99  BT_ASSERT(!modules.empty());
100 
102  //settings.modules = modules;
103  settings.pageCSS_ID = QStringLiteral("printer");
104  if (modules.count() == 1)
105  settings.langAbbrev = modules.first()->language()->abbrev();
106 
107  if (modules.count() == 1)
108  settings.textDirection = modules.first()->textDirection();
109 
112  text,
113  settings);
114 }
#define BT_ASSERT(...)
Definition: btassert.h:17
QList< CSwordModuleInfo const * > BtConstModuleList
Definition: btmodulelist.h:21
QString renderEntry(KeyTreeItem const &item, CSwordKey *const key=nullptr) const override
Definition: btprinter.cpp:77
void printKeyTree(KeyTree const &)
Definition: btprinter.cpp:43
BtPrinter(DisplayOptions const &displayOptions, FilterOptions const &filterOptions, QObject *const parent=nullptr)
Definition: btprinter.cpp:36
QString entryLink(KeyTreeItem const &item, CSwordModuleInfo const &module) const override
Definition: btprinter.cpp:53
QString finishText(QString const &text, KeyTree const &tree) const override
Definition: btprinter.cpp:96
QString fillTemplate(const QString &name, const QString &content, const Settings &settings) const
Fills the template.
static QString activeTemplateName()
static CDisplayTemplateMgr * instance()
ModuleType type() const
CSwordKey implementation for Sword's VerseKey.
QString key() const final override
bool setKey(const QString &key) final override
int verse() const
QString shortText() const
KeyTree & childList() const noexcept
QString const & getAlternativeContent() const
Settings const & settings() const
std::list< KeyTreeItem > KeyTree
QString renderKeyTree(KeyTree const &tree) const
static BtConstModuleList collectModules(KeyTree const &tree)
FilterOptions mangleFilterOptions(FilterOptions fo)
Definition: btprinter.cpp:25
CSwordModuleInfo::TextDirection textDirection
int morphTags
Definition: btglobal.h:29
int footnotes
Definition: btglobal.h:26
int scriptureReferences
Definition: btglobal.h:36
int headings
Definition: btglobal.h:28
int strongNumbers
Definition: btglobal.h:27