BibleTime
btqmlinterface.h
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-2025 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#pragma once
14
15#include <optional>
16#include <QFont>
17#include <QList>
18#include <QObject>
19#include <QQmlEngine>
20#include <QString>
21#include "../../../backend/models/btmoduletextmodel.h"
22
23
24class CSwordKey;
26class CSwordVerseKey;
27class RoleItemModel;
28
29/**
30 * /brief This class provides communications between QML and c++.
31 *
32 * It is instantiated by usage within the QML files. It provides
33 * properties and functions written in c++ and usable by QML.
34 */
35
36class BtQmlInterface : public QObject {
37
38 Q_OBJECT
39 QML_ELEMENT
40 QML_SINGLETON
47 Q_PROPERTY(QFont font0 READ getFont0 NOTIFY fontChanged)
48 Q_PROPERTY(QFont font1 READ getFont1 NOTIFY fontChanged)
49 Q_PROPERTY(QFont font2 READ getFont2 NOTIFY fontChanged)
50 Q_PROPERTY(QFont font3 READ getFont3 NOTIFY fontChanged)
51 Q_PROPERTY(QFont font4 READ getFont4 NOTIFY fontChanged)
52 Q_PROPERTY(QFont font5 READ getFont5 NOTIFY fontChanged)
53 Q_PROPERTY(QFont font6 READ getFont6 NOTIFY fontChanged)
54 Q_PROPERTY(QFont font7 READ getFont7 NOTIFY fontChanged)
55 Q_PROPERTY(QFont font8 READ getFont8 NOTIFY fontChanged)
56 Q_PROPERTY(QFont font9 READ getFont9 NOTIFY fontChanged)
58 Q_PROPERTY(int numModules READ getNumModules NOTIFY numModulesChanged)
59 Q_PROPERTY(double pixelsPerMM READ getPixelsPerMM NOTIFY pixelsPerMMChanged)
60 Q_PROPERTY(QVariant textModel READ getTextModel NOTIFY textModelChanged)
61
62public: /* Types: */
63
64 struct Selection {
65 int column;
68 QString selectedText;
69
70 friend bool operator==(Selection const & lhs, Selection const & rhs) {
71 return lhs.column == rhs.column
72 && lhs.startIndex == rhs.startIndex
73 && lhs.endIndex == rhs.endIndex
74 && lhs.selectedText == rhs.selectedText;
75 }
76
77 friend bool operator!=(Selection const & lhs, Selection const & rhs) {
78 return lhs.column != rhs.column
79 || lhs.startIndex != rhs.startIndex
80 || lhs.endIndex != rhs.endIndex
81 || lhs.selectedText != rhs.selectedText;
82 }
83 };
84
85public:
86 void cancelMagTimer();
87 Q_INVOKABLE void changeReference(int i);
88 Q_INVOKABLE void dragHandler(int index);
89 Q_INVOKABLE bool moduleIsWritable(int column);
90 Q_INVOKABLE void openEditor(int row, int column);
91 void setMagReferenceByUrl(const QString& url);
92 Q_INVOKABLE QString rawText(int row, int column);
93 Q_INVOKABLE void setRawText(int row, int column, const QString& text);
94 Q_INVOKABLE void setBibleKey(const QString& link);
95 Q_INVOKABLE int indexToVerse(int index);
96 Q_INVOKABLE void setHoveredLink(QString const & link);
97
98 BtQmlInterface(QObject * parent = nullptr);
99 ~BtQmlInterface() override;
100
101 void findText(bool backward);
102
103 QString const & activeLink() const noexcept { return m_activeLink; }
104 QColor getBackgroundColor() const;
105 QColor getBackgroundHighlightColor() const;
106 QColor getForegroundColor() const;
108 void changeColorTheme();
109 void copyRange(int index1, int index2) const;
110 static void copyVerseRange(CSwordVerseKey const & key1,
111 CSwordVerseKey const & key2);
112 QString getBibleUrlFromLink(const QString& url);
113 int getContextMenuIndex() const;
114 int getContextMenuColumn() const;
115 int getCurrentModelIndex() const;
116 QFont getFont0() const;
117 QFont getFont1() const;
118 QFont getFont2() const;
119 QFont getFont3() const;
120 QFont getFont4() const;
121 QFont getFont5() const;
122 QFont getFont6() const;
123 QFont getFont7() const;
124 QFont getFont8() const;
125 QFont getFont9() const;
127 QString getLemmaFromLink(const QString& url);
128 int getNumModules() const;
129 double getPixelsPerMM() const;
130
131 Q_INVOKABLE void setSelection(int column,
132 int startIndex,
133 int endIndex,
134 QString const & selectedText);
135 Q_INVOKABLE void clearSelection() noexcept;
136 QString getSelectedText() const;
137
138 std::optional<Selection> const & selection() const noexcept
139 { return m_selection; }
140
141 QVariant getTextModel();
142 bool isBibleOrCommentary();
144 BtModuleTextModel const * textModel() const;
145 void scrollToSwordKey(CSwordKey * key);
146 void setContextMenuIndex(int index);
147 void setContextMenuColumn(int index);
148 void setHighlightWords(const QString& words, bool caseSensitivy);
149 void setModules(const QStringList &modules);
150 void settingsChanged();
151
152Q_SIGNALS:
163 void positionItemOnScreen(int index);
164 void setBibleReference(const QString& reference);
167 void updateReference(const QString& reference);
168 void dragOccuring(const QString& moduleName, const QString& keyName);
169 void activeLinkChanged(QString newActiveLink);
170 void selectionChanged(std::optional<Selection> newSelection);
171
172protected: // Methods:
173
174 void timerEvent(QTimerEvent * event) final override;
175
176private:
177 QFont font(int column) const;
179 QString getReferenceFromUrl(const QString& url);
180
181public: // Fields:
182
183 static int typeId;
184
185private: // Fields:
186
187 bool m_firstHref = false;
191
192 QList<QFont> m_fonts;
194 QStringList m_moduleNames;
199 std::optional<FindState> m_findState;
200 std::optional<Selection> m_selection;
201};
Model that represents the entire text of a given module.
void pixelsPerMMChanged()
Q_INVOKABLE void setRawText(int row, int column, const QString &text)
void scrollToSwordKey(CSwordKey *key)
QString getBibleUrlFromLink(const QString &url)
void backgroundColorChanged()
void contextMenuIndexChanged()
Q_INVOKABLE bool moduleIsWritable(int column)
void dragOccuring(const QString &moduleName, const QString &keyName)
int backgroundHighlightColorIndex
QList< QFont > m_fonts
int getContextMenuColumn() const
void textModelChanged()
QFont getFont3() const
QString const & activeLink() const noexcept
void setContextMenuColumn(int index)
Q_INVOKABLE void changeReference(int i)
void selectionChanged(std::optional< Selection > newSelection)
Q_INVOKABLE void setBibleKey(const QString &link)
void setBibleReference(const QString &reference)
void activeLinkChanged(QString newActiveLink)
void textChanged()
QFont getFont6() const
int getContextMenuIndex() const
void setMagReferenceByUrl(const QString &url)
QFont getFont2() const
void backgroundHighlightColorChanged()
CSwordKey * getMouseClickedKey() const
int m_backgroundHighlightColorIndex
std::optional< Selection > m_selection
QFont getFont0() const
int getCurrentModelIndex() const
QML_SINGLETONQColor backgroundColor
QColor getBackgroundColor() const
QFont getFont8() const
QColor getForegroundColor() const
Q_INVOKABLE int indexToVerse(int index)
void setContextMenuIndex(int index)
std::optional< FindState > m_findState
void fontChanged()
static int typeId
BtModuleTextModel * textModel()
int getBackgroundHighlightColorIndex() const
int getNumModules() const
std::optional< Selection > const & selection() const noexcept
~BtQmlInterface() override
Q_INVOKABLE void setHoveredLink(QString const &link)
QString getSelectedText() const
void updateReference(const QString &reference)
void foregroundColorChanged()
void setModules(const QStringList &modules)
QFont getFont9() const
static void copyVerseRange(CSwordVerseKey const &key1, CSwordVerseKey const &key2)
void timerEvent(QTimerEvent *event) final override
void setHighlightWords(const QString &words, bool caseSensitivy)
QFont getFont7() const
CSwordKey * m_swordKey
QString getReferenceFromUrl(const QString &url)
QFont getFont5() const
Q_INVOKABLE void openEditor(int row, int column)
void positionItemOnScreen(int index)
void currentModelIndexChanged()
void findText(bool backward)
QFont getFont4() const
void contextMenuColumnChanged()
QVariant getTextModel()
QFont font(int column) const
QColor backgroundHighlightColor
QColor getBackgroundHighlightColor() const
Q_INVOKABLE void setSelection(int column, int startIndex, int endIndex, QString const &selectedText)
void numModulesChanged()
double getPixelsPerMM() const
Q_INVOKABLE void dragHandler(int index)
BtModuleTextModel *const m_moduleTextModel
Q_INVOKABLE QString rawText(int row, int column)
void backgroundHighlightColorIndexChanged()
Q_INVOKABLE void clearSelection() noexcept
QFont getFont1() const
void copyRange(int index1, int index2) const
QStringList m_moduleNames
QString getLemmaFromLink(const QString &url)
CSwordKey implementation for Sword's VerseKey.
friend bool operator==(Selection const &lhs, Selection const &rhs)
friend bool operator!=(Selection const &lhs, Selection const &rhs)