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-2021 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 "bttextfilter.h"
23 
24 
25 class CSwordKey;
26 class CSwordModuleInfo;
27 
28 class 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 
37 class BtQmlInterface : public QObject {
38 
39  Q_OBJECT
40  QML_ELEMENT
41  QML_SINGLETON
42  Q_PROPERTY(QColor backgroundColor READ getBackgroundColor NOTIFY backgroundColorChanged)
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)
58  Q_PROPERTY(QColor foregroundColor READ getForegroundColor NOTIFY foregroundColorChanged)
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 
63 public: /* Types: */
64 
65  struct Selection {
66  int column;
68  int endIndex;
69  QString selectedText;
70  };
71 
72 public:
73  void cancelMagTimer();
74  Q_INVOKABLE void changeReference(int i);
75  Q_INVOKABLE void dragHandler(int index);
76  QString getRawText(int row, int column);
77  Q_INVOKABLE bool moduleIsWritable(int column);
78  Q_INVOKABLE void openEditor(int row, int column);
79  void setMagReferenceByUrl(const QString& url);
80  Q_INVOKABLE QString rawText(int row, int column);
81  Q_INVOKABLE void setRawText(int row, int column, const QString& text);
82  Q_INVOKABLE void setBibleKey(const QString& link);
83  Q_INVOKABLE int indexToVerse(int index);
84  Q_INVOKABLE void setHoveredLink(QString const & link);
85 
86  BtQmlInterface(QObject * parent = nullptr);
87  ~BtQmlInterface() override;
88 
89  void findText(bool backward);
90 
91  QString const & activeLink() const noexcept { return m_activeLink; }
92  QColor getBackgroundColor() const;
93  QColor getBackgroundHighlightColor() const;
94  QColor getForegroundColor() const;
96  void changeColorTheme();
97  void copyRange(int index1, int index2) const;
98  static void copyVerseRange(CSwordVerseKey const & key1,
99  CSwordVerseKey const & key2);
100  QString getBibleUrlFromLink(const QString& url);
101  int getContextMenuIndex() const;
102  int getContextMenuColumn() const;
103  int getCurrentModelIndex() const;
104  QFont getFont0() const;
105  QFont getFont1() const;
106  QFont getFont2() const;
107  QFont getFont3() const;
108  QFont getFont4() const;
109  QFont getFont5() const;
110  QFont getFont6() const;
111  QFont getFont7() const;
112  QFont getFont8() const;
113  QFont getFont9() const;
114  CSwordKey* getMouseClickedKey() const;
115  QString getLemmaFromLink(const QString& url);
116  int getNumModules() const;
117  double getPixelsPerMM() const;
118 
119  Q_INVOKABLE void setSelection(int column,
120  int startIndex,
121  int endIndex,
122  QString const & selectedText);
123  Q_INVOKABLE void clearSelection() noexcept;
124  bool hasSelectedText() const noexcept;
125  QString getSelectedText() const;
126 
127  std::optional<Selection> const & selection() const noexcept
128  { return m_selection; }
129 
130  QVariant getTextModel();
131  bool isBibleOrCommentary();
133  BtModuleTextModel const * textModel() const;
134  void scrollToSwordKey(CSwordKey * key);
135  void setContextMenuIndex(int index);
136  void setContextMenuColumn(int index);
137  void setFilterOptions(FilterOptions filterOptions);
138  void setHighlightWords(const QString& words, bool caseSensitivy);
139  void setModules(const QStringList &modules);
140  void settingsChanged();
141 
142 Q_SIGNALS:
149  void fontChanged();
153  void positionItemOnScreen(int index);
154  void setBibleReference(const QString& reference);
155  void textChanged();
157  void updateReference(const QString& reference);
158  void dragOccuring(const QString& moduleName, const QString& keyName);
159 
160 protected: // Methods:
161 
162  void timerEvent(QTimerEvent * event) final override;
163 
164 private:
165  QFont font(int column) const;
166  void getFontsFromSettings();
167  QString getReferenceFromUrl(const QString& url);
168 
169 public: // Fields:
170 
171  static int typeId;
172 
173 private: // Fields:
174 
175  bool m_firstHref = false;
176  int m_linkTimerId = 0;
178  CSwordKey * m_swordKey = nullptr;
179 
182  QStringList m_moduleNames;
184  QString m_timeoutUrl;
187  QString m_activeLink;
188  std::optional<FindState> m_findState;
189  std::optional<Selection> m_selection;
190 };
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
QColor foregroundColor
int getContextMenuColumn() const
void textModelChanged()
QFont getFont3() const
void setContextMenuColumn(int index)
Q_INVOKABLE void changeReference(int i)
Q_INVOKABLE void setBibleKey(const QString &link)
QVariant textModel
void setBibleReference(const QString &reference)
void textChanged()
QFont getFont6() const
int getContextMenuIndex() const
QString m_timeoutUrl
QString m_activeLink
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)
std::optional< Selection > const & selection() const noexcept
void setContextMenuIndex(int index)
std::optional< FindState > m_findState
void fontChanged()
static int typeId
int getBackgroundHighlightColorIndex() const
int getNumModules() const
~BtQmlInterface() override
QString getRawText(int row, int column)
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
void setFilterOptions(FilterOptions filterOptions)
CSwordKey * m_swordKey
QString const & activeLink() const noexcept
bool isBibleOrCommentary()
QString getReferenceFromUrl(const QString &url)
BtModuleTextModel * textModel()
QFont getFont5() const
Q_INVOKABLE void openEditor(int row, int column)
void positionItemOnScreen(int index)
void currentModelIndexChanged()
void findText(bool backward)
QFont getFont4() const
BtTextFilter m_textFilter
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)
bool hasSelectedText() const noexcept
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()
void getFontsFromSettings()
Q_INVOKABLE void clearSelection() noexcept
BtQmlInterface(QObject *parent=nullptr)
QFont getFont1() const
void copyRange(int index1, int index2) const
QStringList m_moduleNames
QString getLemmaFromLink(const QString &url)
This filter provides a method for modifying text generated by BtModuleTextModel.
Definition: bttextfilter.h:31
CSwordKey implementation for Sword's VerseKey.