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-2026 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
23namespace {
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
36BtPrinter::BtPrinter(DisplayOptions const & displayOptions,
37 FilterOptions const & filterOptions)
38 : CDisplayRendering{displayOptions, mangleFilterOptions(filterOptions)}
39{}
40
41void BtPrinter::printKeyTree(KeyTree const & tree) {
42 QTextEdit htmlPage;
43 htmlPage.setHtml(renderKeyTree(tree));
44
45 QPrinter printer;
46 QPrintDialog printDialog(&printer);
47 if (printDialog.exec() == QDialog::Accepted)
48 htmlPage.print(&printer);
49}
50
51QString BtPrinter::entryLink(KeyTreeItem const & item,
52 CSwordModuleInfo const & module) const
53{
54 if (module.type() != CSwordModuleInfo::Bible)
55 return item.key();
56
57 CSwordVerseKey vk(&module);
58 vk.setKey(item.key());
59 switch (item.settings().keyRenderingFace) {
60 case KeyTreeItem::Settings::CompleteShort:
61 return vk.shortText();
62
63 case KeyTreeItem::Settings::CompleteLong:
64 return vk.key();
65
66 case KeyTreeItem::Settings::NoKey:
67 return QString();
68
69 case KeyTreeItem::Settings::SimpleKey: // fall through:
70 default:
71 return QString::number(vk.verse());
72 }
73}
74
75QString BtPrinter::renderEntry(KeyTreeItem const & i, CSwordKey * key) const {
76 Q_UNUSED(key)
77 BtPrinter::KeyTreeItem const * const printItem =
78 static_cast<BtPrinter::KeyTreeItem const *>(&i);
79
80 if (printItem->hasAlternativeContent()) {
81 auto ret =
82 QStringLiteral(
83 "<div class=\"entry\"><div class=\"rangeheading\">%1</div>")
84 .arg(printItem->getAlternativeContent());
85 if (!i.childList().empty())
86 for (auto const & item : i.childList())
87 ret.append(CDisplayRendering::renderEntry(item));
88 ret.append(QStringLiteral("</div>"));
89 return ret;
90 }
91 return CDisplayRendering::renderEntry(i);
92}
93
94QString BtPrinter::finishText(QString const & text, KeyTree const & tree) const
95{
96 BtConstModuleList const modules = collectModules(tree);
97 BT_ASSERT(!modules.empty());
98
100 //settings.modules = modules;
101 settings.pageCSS_ID = QStringLiteral("printer");
102 if (modules.count() == 1)
103 settings.langAbbrev = modules.first()->language()->abbrev();
104
105 if (modules.count() == 1)
106 settings.textDirection = modules.first()->textDirection();
107
110 text,
111 settings);
112}
#define BT_ASSERT(...)
Definition btassert.h:17
QList< CSwordModuleInfo const * > BtConstModuleList
BtPrinter(DisplayOptions const &displayOptions, FilterOptions const &filterOptions)
Definition btprinter.cpp:36
QString renderEntry(KeyTreeItem const &item, CSwordKey *const key=nullptr) const override
Definition btprinter.cpp:75
void printKeyTree(KeyTree const &)
Definition btprinter.cpp:41
QString entryLink(KeyTreeItem const &item, CSwordModuleInfo const &module) const override
Definition btprinter.cpp:51
QString finishText(QString const &text, KeyTree const &tree) const override
Definition btprinter.cpp:94
static QString activeTemplateName()
QString fillTemplate(const QString &name, QString content, const Settings &settings) const
Fills the template.
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
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 scriptureReferences
Definition btglobal.h:36
int strongNumbers
Definition btglobal.h:27