15#include <QApplication>
18#include <QRegularExpression>
19#include <QRegularExpressionMatch>
22#include "../../../backend/config/btconfig.h"
23#include "../../../backend/drivers/cswordbookmoduleinfo.h"
24#include "../../../backend/drivers/cswordlexiconmoduleinfo.h"
25#include "../../../backend/drivers/cswordmoduleinfo.h"
26#include "../../../backend/keys/cswordkey.h"
27#include "../../../backend/managers/colormanager.h"
28#include "../../../backend/managers/cswordbackend.h"
29#include "../../../backend/rendering/btinforendering.h"
30#include "../../../backend/rendering/cplaintextexportrendering.h"
31#include "../../../backend/rendering/ctextrendering.h"
32#include "../../../backend/rendering/btinforendering.h"
33#include "../../../util/btassert.h"
34#include "../../bibletime.h"
35#include "../../btmoduleindexdialog.h"
36#include "../../cinfodisplay.h"
37#include "../../edittextwizard/btedittextwizard.h"
53 default:
return false;
92 auto const moduleType = keyModule->
type();
105 return static_cast<int>(key.
offset() / 4u);
118 constexpr static double const millimetersPerInch = 25.4;
119 return QGuiApplication::screens().first()->physicalDotsPerInchX()
120 / millimetersPerInch;
124 int const startIndex,
126 QString
const & selectedText)
132 Selection newSelection{column, startIndex, endIndex, selectedText};
152 if (wiz.exec() == QDialog::Accepted)
161 if (QGuiApplication::keyboardModifiers() & Qt::ShiftModifier)
172 static QRegularExpression
const rx(
173 QStringLiteral(R
"PCRE(sword://lemmamorph/([a-s]+)=([GH][0-9]+))PCRE"));
174 if (
auto const match = rx.match(url); match.hasMatch())
175 return match.captured(2);
180 static QRegularExpression
const rx(
181 QStringLiteral(R
"PCRE((sword://Bible/.*)\|\|(.*)=(.*))PCRE"));
182 if (
auto const match = rx.match(url); match.hasMatch())
183 return match.captured(1);
189 static QRegularExpression
const rx(
191 R
"PCRE(sword://(bible|lexicon)/(.*)/(.*)(\|\|))PCRE"),
192 QRegularExpression::CaseInsensitiveOption);
193 if (
auto const match = rx.match(url); match.hasMatch())
194 return QStringLiteral(
"href=sword://%1/%2/%3")
195 .arg(match.capturedView(1),
196 match.capturedView(2),
197 match.capturedView(3));
199 static QRegularExpression
const rx(
200 QStringLiteral(R
"PCRE(sword://(bible|lexicon)/(.*)/(.*))PCRE"),
201 QRegularExpression::CaseInsensitiveOption);
202 if (
auto const match = rx.match(url); match.hasMatch())
203 return QStringLiteral(
"href=sword://%1/%2/%3")
204 .arg(match.capturedView(1),
205 match.capturedView(2),
206 match.capturedView(3));
208 static QRegularExpression
const rx(
209 QStringLiteral(R
"PCRE(sword://footnote/(.*)=(.*))PCRE"),
210 QRegularExpression::CaseInsensitiveOption);
211 if (
auto const match = rx.match(url); match.hasMatch())
212 return QStringLiteral(
"note=%1").arg(match.capturedView(1));
214 static QRegularExpression
const rx(
215 QStringLiteral(R
"PCRE(sword://lemmamorph/(.*)=(.*)/(.*))PCRE"),
216 QRegularExpression::CaseInsensitiveOption);
217 if (
auto const match = rx.match(url); match.hasMatch())
218 return QStringLiteral(
"%1=%2").arg(match.capturedView(1),
219 match.capturedView(2));
234 if (
auto *
const module =
238 if (module->hasIndex()) {
239 module->deleteIndex();
269 if (
auto const *
const m =
272 if (
auto const lang = m->language()) {
274 if (fontPair.first) {
275 newFonts.append(fontPair.second);
280 newFonts.append(
btConfig().getDefaultFont());
287 static QRegularExpression
const rx(
288 QStringLiteral(R
"PCRE(sword://Bible/(.*)/(.*)\|\|(.*)=(.*))PCRE"));
289 if (
auto const match = rx.match(link); match.hasMatch())
321 static QRegularExpression
const rx(
322 QStringLiteral(R
"PCRE(sword://Bible/(.*)/(.*)\|\|(.*)=(.*))PCRE"));
324 if (
auto const match = rx.match(
m_activeLink); match.hasMatch()) {
325 moduleName = match.captured(1);
326 keyName = match.captured(2);
340 if (column >= 0 && column <
m_fonts.count())
342 return QApplication::font();
373 auto *
const module =
374 CSwordBackend::instance().findModuleByName(moduleName);
376 return module->isWritable();
389 for (
int i=index1; i<=index2; ++i) {
391 key->setKey(keyName);
392 text.append(QStringLiteral(
"%1\n%2\n\n")
393 .arg(keyName, key->strippedText()));
395 QClipboard *clipboard = QGuiApplication::clipboard();
396 clipboard->setText(text);
427 QGuiApplication::clipboard()->setText(
432 QApplication::setOverrideCursor(Qt::WaitCursor);
436 QApplication::restoreOverrideCursor();
440 auto const timerId =
event->timerId();
446 if (!infoList.isEmpty())
449 QObject::timerEvent(event);
454 QApplication::setOverrideCursor(Qt::WaitCursor);
458 auto const countHighlightsInItem =
459 [
this](
int const index) {
462 .toString().count(QStringLiteral(
"\"highlightwords"));
465 auto const num = countHighlightsInItem(
m_findState->index);
470 }
else if (
auto index =
m_findState->index; index > 0) {
473 for (
int i = 0; i < 1000; ++i, --index) {
474 if (
auto const num2 = countHighlightsInItem(index)) {
492 for (
int i = 0; i < 1000; ++i, ++index) {
493 if (countHighlightsInItem(index)) {
504 QApplication::restoreOverrideCursor();
BtConfig & btConfig()
This is a shortchand for BtConfig::getInstance().
static BibleTime * instance() noexcept
InfoDisplay::CInfoDisplay * infoDisplay() const noexcept
QPair< bool, QFont > FontSettingsPair
FontSettingsPair getFontForLanguage(Language const &language)
Get font for a language.
The Edit Text wizard for editing the personal commentary.
void setFont(const QFont &font)
void setText(const QString &text)
void setTitle(const QString &text)
static bool indexAllModules(QList< CSwordModuleInfo * > const &modules)
Model that represents the entire text of a given module.
CSwordKey * indexToKey(int index, int moduleNum) const
int rowCount(const QModelIndex &parent=QModelIndex()) const override
int firstEntryIndex() const noexcept
int verseKeyToIndex(const CSwordVerseKey &key) const
void setModules(const QStringList &modules)
void setHighlightWords(const QString &highlightWords, bool caseSensitive)
int keyToIndex(CSwordKey const &key) const
int indexToVerse(int index) const
QString indexToKeyName(int index) const
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
void setFindState(std::optional< FindState > findState)
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 getContextMenuColumn() const
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)
int getContextMenuIndex() const
void setMagReferenceByUrl(const QString &url)
void backgroundHighlightColorChanged()
CSwordKey * getMouseClickedKey() const
int m_backgroundHighlightColorIndex
std::optional< Selection > m_selection
int getCurrentModelIndex() const
QColor getBackgroundColor() const
QColor getForegroundColor() const
Q_INVOKABLE int indexToVerse(int index)
void setContextMenuIndex(int index)
std::optional< FindState > m_findState
int getBackgroundHighlightColorIndex() const
int getNumModules() const
~BtQmlInterface() override
Q_INVOKABLE void setHoveredLink(QString const &link)
QString getSelectedText() const
void updateReference(const QString &reference)
void foregroundColorChanged()
void setModules(const QStringList &modules)
static void copyVerseRange(CSwordVerseKey const &key1, CSwordVerseKey const &key2)
void timerEvent(QTimerEvent *event) final override
void setHighlightWords(const QString &words, bool caseSensitivy)
bool isBibleOrCommentary()
QString getReferenceFromUrl(const QString &url)
Q_INVOKABLE void openEditor(int row, int column)
void positionItemOnScreen(int index)
void currentModelIndexChanged()
void findText(bool backward)
void contextMenuColumnChanged()
QFont font(int column) const
QColor getBackgroundHighlightColor() const
Q_INVOKABLE void setSelection(int column, int startIndex, int endIndex, QString const &selectedText)
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)
void copyRange(int index1, int index2) const
QStringList m_moduleNames
QString getLemmaFromLink(const QString &url)
CSwordModuleInfo * findModuleByName(const QString &name) const
Searches for a module with the given name.
static CSwordBackend & instance() noexcept
Class for generic book support.
CSwordModuleInfo const * module() const
virtual CSwordKey * copy() const =0
virtual QString key() const =0
CSwordKey implementation for Sword's TreeKey.
bool setKey(const QString &key) final override
CSwordKey implementation for Sword's VerseKey.
void setInfo(const QString &renderedData, const QString &lang=QString())
Text rendering as plain text.
QString renderKeyRange(CSwordVerseKey const &lowerBound, CSwordVerseKey const &upperBound, const BtConstModuleList &modules, const QString &hightlightKey=QString(), const KeyTreeItem::Settings &settings=KeyTreeItem::Settings())
void setFilterOptions(FilterOptions const &filterOptions) noexcept
void setDisplayOptions(DisplayOptions const &displayOptions) noexcept
QString getForegroundColor()
QString getBackgroundColor()
QString getBackgroundHighlightColor()
ListInfoData detectInfo(QString const &data)