BibleTime
btmodelviewreaddisplay.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 <QWidget>
16 
17 #include "../../backend/btglobal.h"
18 
19 
20 class BtQmlInterface;
21 class BtQuickWidget;
22 class CDisplayWindow;
23 class CSwordKey;
24 class QMenu;
25 class QScrollBar;
26 
27 /**
28  * @page modelviewmain Details about the model/view read display
29  * <p>
30  * In the simplest form, the model/view read display uses BtModuleTextModel
31  * as the model and a <b>QML ListView</b> in Display.qml. BtModuleTextModel is a
32  * subclass of QAbstractItemList. The BtModuleTextModel creates entries for
33  * references that are being displayed in the ListView or those that are just
34  * above and below the displayed references. As the ListView is scrolled, the
35  * entries are automatically created and deleted. The entries represent verses,
36  * chapters, lexicon items, etc. depending upon the module type.
37  * </p>
38  * <p>
39  * - For more details about the model see @ref modelviewmodel.<br/>
40  * - For details about the view, see @ref modelviewdisplay.<br/>
41  * </p>
42  */
43 
44 /**
45  * @page modelviewdisplay Details about the QML view
46  * <p>
47  * The class BtModelViewReadDisplay contains the functionality to display a model
48  * of a module. It uses a set of widgets to do this. The hierarchy of contained
49  * widgets is:<br/>
50  * - BtQmlScrollView - Contains the scrolling functionality.<br/>
51  * - BtQuickWidget - Contains the functionality for displaying QML.<br/>
52  *
53  * Below the BtQuickWidget is the QML file, <b>DisplayView.qml</b>. It contains
54  * the ListView that displays the module entries. The QML instantiates
55  * another class, BtQmlInterface, that provides properties and functions
56  * that QML uses.
57  * </p>
58  */
59 
60 /** The view implementation for the Model/View read display.
61  */
63  Q_OBJECT
64 
65 public: // types:
66 
67  enum TextPart {
68  Document, /* All text */
69  SelectedText, /* Only the selected text */
73  };
74 
75 public: // methods:
76 
77  BtModelViewReadDisplay(CDisplayWindow * displayWindow,
78  QWidget * parent = nullptr);
79 
81 
87 
88  /** \brief Copies the currently selected text. */
89  void copySelectedText();
90 
91  /**
92  \brief Copies the given text specified by asking user for first and last
93  references.
94  */
95  void copyByReferences();
96 
97  /**
98  \brief Saves the given text with the specified format into the
99  applications clipboard.
100  */
101  void save(TextPart const part);
102 
103  void print(TextPart const,
104  DisplayOptions const & displayOptions,
105  FilterOptions const & filterOptions);
106 
107  void printAll(DisplayOptions const & displayOptions,
108  FilterOptions const & filterOptions)
109  { print(Document, displayOptions, filterOptions); }
110 
111  void printAnchorWithText(DisplayOptions const & displayOptions,
112  FilterOptions const & filterOptions)
113  { print(AnchorWithText, displayOptions, filterOptions); }
114 
115  /**
116  \brief Installs the popup which should be opened when the right mouse
117  button was pressed.
118  */
119  void installPopup(QMenu * const popup) { m_popup = popup; }
120 
121  /**
122  \param[in] format The format to use for the text.
123  \param[in] part The part of the text to return.
124  \returns the right text part in the specified format.
125  */
126  QString text(TextPart const part = Document);
127 
128  void reloadModules();
129 
130  void setDisplayFocus();
131 
132  void setDisplayOptions(const DisplayOptions &displayOptions);
133 
134  void highlightText(const QString& text, bool caseSensitive);
135 
136  void findText(bool const backward);
137 
138  QString getCurrentNodeInfo() const { return m_nodeInfo; }
139 
140  void pageDown();
141 
142  void pageUp();
143 
144  void scrollToKey(CSwordKey * key);
145 
146  void scroll(int pixels);
147 
148  void setFilterOptions(FilterOptions filterOptions);
149 
150  void setLemma(const QString& lemma);
151 
152  void setModules(QStringList const & modules);
153 
154  void settingsChanged();
155 
156  void updateReferenceText();
157 
158  BtQuickWidget * quickWidget() const noexcept { return m_quickWidget; }
159 
160  BtQmlInterface * qmlInterface() const noexcept { return m_qmlInterface; }
161 
162  /** \returns whether the display has an active anchor. */
163  bool hasActiveAnchor() const { return !m_activeAnchor.isEmpty(); }
164 
165 private Q_SLOTS:
166 
167  void setBibleReference (const QString& reference);
168  void slotSliderMoved(int value);
169  void slotSliderPressed();
170  void slotSliderReleased();
171 
172 private: /* Methods: */
173 
174  void copyAsPlainText(TextPart const part);
175  void contextMenuEvent(QContextMenuEvent * event) final override;
176 
177 private: // fields:
178 
180  QMenu * m_popup = nullptr;
181  QString m_activeAnchor; //< Holds the current anchor
182 
183  QString m_nodeInfo;
184 
187  QScrollBar * const m_scrollBar;
189 
190 };
void printAll(DisplayOptions const &displayOptions, FilterOptions const &filterOptions)
BtQmlInterface * qmlInterface() const noexcept
void findText(bool const backward)
void highlightText(const QString &text, bool caseSensitive)
BtQuickWidget * quickWidget() const noexcept
void copySelectedText()
Copies the currently selected text.
void scrollToKey(CSwordKey *key)
void setLemma(const QString &lemma)
void setModules(QStringList const &modules)
QString text(TextPart const part=Document)
void installPopup(QMenu *const popup)
Installs the popup which should be opened when the right mouse button was pressed.
void copyAsPlainText(TextPart const part)
void copyByReferences()
Copies the given text specified by asking user for first and last references.
void save(TextPart const part)
Saves the given text with the specified format into the applications clipboard.
void printAnchorWithText(DisplayOptions const &displayOptions, FilterOptions const &filterOptions)
BtQuickWidget *const m_quickWidget
BtQmlInterface *const m_qmlInterface
BtModelViewReadDisplay(CDisplayWindow *displayWindow, QWidget *parent=nullptr)
void setDisplayOptions(const DisplayOptions &displayOptions)
void print(TextPart const, DisplayOptions const &displayOptions, FilterOptions const &filterOptions)
void contextMenuEvent(QContextMenuEvent *event) final override
void setFilterOptions(FilterOptions filterOptions)
void setBibleReference(const QString &reference)
~BtModelViewReadDisplay() override
The base class for all display windows of BibleTime.