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, http://www.bibletime.info/.
6 *
7 * Copyright 1999-2016 by the BibleTime developers.
8 * The BibleTime source code is licensed under the GNU General Public License version 2.0.
9 *
10 **********/
11 
12 #ifndef CTEXTRENDERING_H
13 #define CTEXTRENDERING_H
14 
15 #include <QList>
16 #include <QSharedPointer>
17 #include <QString>
18 
19 #include "../drivers/btmodulelist.h"
20 
21 
22 class CSwordKey;
23 
24 namespace Rendering {
25 
26 /**
27  * CTextRendering is BibleTime's place where the actual rendering takes place.
28  * It provides several methods to convert an abstract tree of items
29  * into a string of html.
30  *
31  * See the implementations @ref CHTMLExportRendering and especially @ref CDisplayRendering.
32  * @short Text rendering based on trees
33  * @author The BibleTime team
34 */
35 class CTextRendering {
36 
37     public: /* Types: */
38 
39         class KeyTreeItem;
40 
41         class KeyTreeSharedPointer: public QSharedPointer<KeyTreeItem> {
42             public:
KeyTreeSharedPointer(KeyTreeItem * i)43                 inline KeyTreeSharedPointer(KeyTreeItem * i)
44                     : QSharedPointer<KeyTreeItem>(i) {}
45 
46                 inline operator const KeyTreeItem * () const { return data(); }
47         };
48 
49         using KeyTree = QList<KeyTreeSharedPointer>;
50 
51         class KeyTreeItem {
52 
53             public: /* Types: */
54 
55                 struct Settings {
56 
57                     enum KeyRenderingFace {
58                         NoKey, //< means no key shown at all
59                         SimpleKey, //< means only versenumber or only lexicon entry name
60                         CompleteShort, //< means key like "Gen 1:1"
61                         CompleteLong, //< means "Genesis 1:1"
62                         ExpandedShort, // means "KJV:Gen 1:1"
63                         ExpandedLong   // means "Genesis 1:1 (KJV)"
64                     };
65 
66                     Settings(const bool highlight = false,
67                              KeyRenderingFace keyRendering = SimpleKey)
highlightSettings68                         : highlight(highlight)
69                         , keyRenderingFace(keyRendering)
70                     {}
71 
72                     bool highlight;
73                     KeyRenderingFace keyRenderingFace;
74 
75                 }; /* struct Settings */
76 
77             public: /* Methods: */
78 
79                 KeyTreeItem(const QString &key,
80                             const CSwordModuleInfo *module,
81                             const Settings &settings);
82 
83                 KeyTreeItem(const QString &key,
84                             const BtConstModuleList &modules,
85                             const Settings &settings);
86 
87                 KeyTreeItem(const QString &startKey,
88                             const QString &stopKey,
89                             const CSwordModuleInfo *module,
90                             const Settings &settings);
91 
92                 KeyTreeItem(const QString &content, const Settings &settings);
93 
94                 KeyTreeItem(const KeyTreeItem &i);
95 
getAlternativeContent()96                 inline const QString &getAlternativeContent() const {
97                     return m_alternativeContent;
98                 }
99 
setAlternativeContent(const QString & newContent)100                 inline void setAlternativeContent(const QString& newContent) {
101                     m_alternativeContent = newContent;
102                 }
103 
hasAlternativeContent()104                 inline bool hasAlternativeContent() const {
105                     return !m_alternativeContent.isNull();
106                 }
107 
modules()108                 inline const BtConstModuleList& modules() const {
109                     return m_moduleList;
110                 }
111 
key()112                 inline const QString& key() const {
113                     return m_key;
114                 }
115 
settings()116                 inline const Settings& settings() const {
117                     return m_settings;
118                 }
119 
childList()120                 inline KeyTree* childList() const {
121                     return &m_childList;
122                 }
123 
setMappedKey(CSwordKey const * key)124                 inline void setMappedKey(CSwordKey const * key) const {
125                     m_mappedKey = key;
126                 }
127 
mappedKey()128                 inline CSwordKey const * mappedKey() const {
129                     return m_mappedKey;
130                 }
131 
132             protected: /* Methods: */
133 
134                 KeyTreeItem();
135 
136             private: /* Fields: */
137 
138                 Settings m_settings;
139                 BtConstModuleList m_moduleList;
140                 QString m_key;
141                 mutable CSwordKey const * m_mappedKey;
142                 mutable KeyTree m_childList;
143 
144                 QString m_stopKey;
145                 QString m_alternativeContent;
146 
147         }; /* class KeyTreeItem */
148 
149     public: /* Methods: */
150 
~CTextRendering()151         virtual ~CTextRendering() {};
152 
153         const QString renderKeyTree(const KeyTree &tree);
154 
155         const QString renderKeyRange(
156                 const QString &start,
157                 const QString &stop,
158                 const BtConstModuleList &modules,
159                 const QString &hightlightKey = QString::null,
160                 const KeyTreeItem::Settings &settings = KeyTreeItem::Settings());
161 
162         const QString renderSingleKey(
163                 const QString &key,
164                 const BtConstModuleList &modules,
165                 const KeyTreeItem::Settings &settings = KeyTreeItem::Settings());
166 
167     protected: /* Methods: */
168 
169         BtConstModuleList collectModules(const KeyTree &tree) const;
170         virtual QString renderEntry(const KeyTreeItem &item, CSwordKey * key = nullptr) = 0;
171         virtual QString finishText(const QString &text, const KeyTree &tree) = 0;
172         virtual void initRendering() = 0;
173 
174 }; /* class CTextRendering */
175 
176 } /* namespace Rendering */
177 
178 #endif
179