blob: ae718e6de984d2fe014dcb155f23584e83a1b1c6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
/*********
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
#include "btprinter.h"
#include "bibletime.h"
#include <QPrintDialog>
#include <QPrinter>
#include <QTextEdit>
#include "../util/btassert.h"
#include "backend/config/btconfig.h"
#include "backend/keys/cswordversekey.h"
#include "backend/managers/cdisplaytemplatemgr.h"
namespace {
inline FilterOptions mangleFilterOptions(FilterOptions fo) {
fo.footnotes = false;
fo.scriptureReferences = false;
fo.strongNumbers = false;
fo.morphTags = false;
fo.headings = false;
return fo;
}
} // anonymous namespace
BtPrinter::BtPrinter(DisplayOptions const & displayOptions,
FilterOptions const & filterOptions,
QObject * const parent)
: QObject{parent}
, CDisplayRendering{displayOptions, mangleFilterOptions(filterOptions)}
{}
void BtPrinter::printKeyTree(KeyTree const & tree) {
QTextEdit htmlPage;
htmlPage.setHtml(renderKeyTree(tree));
QPrinter printer;
QPrintDialog printDialog(&printer);
if (printDialog.exec() == QDialog::Accepted)
htmlPage.print(&printer);
}
QString BtPrinter::entryLink(KeyTreeItem const & item,
CSwordModuleInfo const * module)
{
BT_ASSERT(module);
if (module->type() != CSwordModuleInfo::Bible)
return item.key();
CSwordVerseKey vk(module);
vk.setKey(item.key());
switch (item.settings().keyRenderingFace) {
case KeyTreeItem::Settings::CompleteShort:
return QString::fromUtf8(vk.getShortText());
case KeyTreeItem::Settings::CompleteLong:
return vk.key();
case KeyTreeItem::Settings::NoKey:
return QString::null;
case KeyTreeItem::Settings::SimpleKey: // fall through:
default:
return QString::number(vk.getVerse());
}
}
QString BtPrinter::renderEntry(KeyTreeItem const & i, CSwordKey * key) {
Q_UNUSED(key);
BT_ASSERT(dynamic_cast<BtPrinter::KeyTreeItem const *>(&i));
BtPrinter::KeyTreeItem const * const printItem =
static_cast<BtPrinter::KeyTreeItem const *>(&i);
if (printItem->hasAlternativeContent()) {
QString ret =
QString::fromLatin1("<div class=\"entry\"><div class=\""
"rangeheading\">%1</div>").arg(
printItem->getAlternativeContent());
if (!i.childList()->isEmpty())
Q_FOREACH (const KeyTreeItem * const c, *i.childList())
ret.append(CDisplayRendering::renderEntry(*c));
ret.append("</div>");
return ret;
}
return CDisplayRendering::renderEntry(i);
}
QString BtPrinter::finishText(QString const & text, KeyTree const & tree) {
BtConstModuleList const modules = collectModules(tree);
BT_ASSERT(!modules.empty());
CLanguageMgr::Language const * const lang = modules.first()->language();
BT_ASSERT(lang);
CDisplayTemplateMgr::Settings settings;
//settings.modules = modules;
settings.pageCSS_ID = "printer";
if (modules.count() == 1 && lang->isValid())
settings.langAbbrev = lang->abbrev();
if (modules.count() == 1)
settings.textDirection = modules.first()->textDirection();
return CDisplayTemplateMgr::instance()->fillTemplate(
CDisplayTemplateMgr::activeTemplateName(),
text,
settings);
}
|