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