15 #include <QApplication>
18 #include <QRegularExpression>
19 #include <QRegularExpressionMatch>
20 #include <QTimerEvent>
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/models/btmoduletextmodel.h"
30 #include "../../../backend/rendering/btinforendering.h"
31 #include "../../../backend/rendering/cplaintextexportrendering.h"
32 #include "../../../backend/rendering/ctextrendering.h"
33 #include "../../../backend/rendering/btinforendering.h"
34 #include "../../../util/btassert.h"
35 #include "../../bibletime.h"
36 #include "../../cinfodisplay.h"
37 #include "../../edittextwizard/btedittextwizard.h"
53 default:
return false;
96 auto const moduleType = keyModule->
type();
109 return static_cast<int>(key.
offset() / 4u);
122 constexpr
static double const millimetersPerInch = 25.4;
123 return QGuiApplication::screens().first()->physicalDotsPerInchX()
124 / millimetersPerInch;
128 int const startIndex,
130 QString
const & selectedText)
151 auto *
const module =
159 static auto const reFlags =
160 QRegularExpression::CaseInsensitiveOption
161 | QRegularExpression::DotMatchesEverythingOption
162 | QRegularExpression::DontCaptureOption
163 | QRegularExpression::UseUnicodePropertiesOption;
164 static QRegularExpression
const reBefore(
165 QStringLiteral(
"^.*?<body(\\s[^>]*?)?>"), reFlags);
166 static QRegularExpression
const reAfter(
167 QStringLiteral(
"</body>.*?$"), reFlags);
168 if (
auto const m = reBefore.match(
rawText); m.hasMatch())
169 rawText.remove(0, m.capturedLength());
170 if (
auto const m = reAfter.match(
rawText); m.hasMatch())
171 rawText.chop(m.capturedLength());
180 if (wiz.exec() == QDialog::Accepted)
189 if (QGuiApplication::keyboardModifiers() & Qt::ShiftModifier)
196 static QRegularExpression
const rx(
197 QStringLiteral(R
"PCRE(sword://lemmamorph/([a-s]+)=([GH][0-9]+))PCRE"));
198 if (
auto const match = rx.match(url); match.hasMatch())
199 return match.captured(2);
204 static QRegularExpression
const rx(
205 QStringLiteral(R
"PCRE((sword://Bible/.*)\|\|(.*)=(.*))PCRE"));
206 if (
auto const match = rx.match(url); match.hasMatch())
207 return match.captured(1);
213 static QRegularExpression
const rx(
215 R
"PCRE(sword://(bible|lexicon)/(.*)/(.*)(\|\|))PCRE"),
216 QRegularExpression::CaseInsensitiveOption);
217 if (
auto const match = rx.match(url); match.hasMatch())
218 return QStringLiteral(
"href=sword://%1/%2/%3")
219 .arg(match.capturedView(1),
220 match.capturedView(2),
221 match.capturedView(3));
223 static QRegularExpression
const rx(
224 QStringLiteral(R
"PCRE(sword://(bible|lexicon)/(.*)/(.*))PCRE"),
225 QRegularExpression::CaseInsensitiveOption);
226 if (
auto const match = rx.match(url); match.hasMatch())
227 return QStringLiteral(
"href=sword://%1/%2/%3")
228 .arg(match.capturedView(1),
229 match.capturedView(2),
230 match.capturedView(3));
232 static QRegularExpression
const rx(
233 QStringLiteral(R
"PCRE(sword://footnote/(.*)=(.*))PCRE"),
234 QRegularExpression::CaseInsensitiveOption);
235 if (
auto const match = rx.match(url); match.hasMatch())
236 return QStringLiteral(
"note=%1").arg(match.capturedView(1));
238 static QRegularExpression
const rx(
239 QStringLiteral(R
"PCRE(sword://lemmamorph/(.*)=(.*)/(.*))PCRE"),
240 QRegularExpression::CaseInsensitiveOption);
241 if (
auto const match = rx.match(url); match.hasMatch())
242 return QStringLiteral(
"%1=%2").arg(match.capturedView(1),
243 match.capturedView(2));
282 if (
auto const *
const m =
285 if (
auto const lang = m->language()) {
287 if (fontPair.first) {
288 newFonts.append(fontPair.second);
293 newFonts.append(
btConfig().getDefaultFont());
300 static QRegularExpression
const rx(
301 QStringLiteral(R
"PCRE(sword://Bible/(.*)/(.*)\|\|(.*)=(.*))PCRE"));
302 if (
auto const match = rx.match(link); match.hasMatch())
334 static QRegularExpression
const rx(
335 QStringLiteral(R
"PCRE(sword://Bible/(.*)/(.*)\|\|(.*)=(.*))PCRE"));
337 if (
auto const match = rx.match(
m_activeLink); match.hasMatch()) {
338 moduleName = match.captured(1);
339 keyName = match.captured(2);
353 if (column >= 0 && column <
m_fonts.count())
355 return QApplication::font();
386 auto *
const module =
389 return module->isWritable();
402 for (
int i=index1; i<=index2; ++i) {
404 key->setKey(keyName);
405 text.append(QStringLiteral(
"%1\n%2\n\n")
406 .arg(keyName, key->strippedText()));
408 QClipboard *clipboard = QGuiApplication::clipboard();
409 clipboard->setText(text);
440 QGuiApplication::clipboard()->setText(
445 QApplication::setOverrideCursor(Qt::WaitCursor);
449 QApplication::restoreOverrideCursor();
453 auto const timerId =
event->timerId();
459 if (!infoList.isEmpty())
462 QObject::timerEvent(event);
467 QApplication::setOverrideCursor(Qt::WaitCursor);
471 auto const countHighlightsInItem =
472 [
this](
int const index) {
475 .toString().count(QStringLiteral(
"\"highlightwords"));
478 auto const num = countHighlightsInItem(
m_findState->index);
483 }
else if (
auto index =
m_findState->index; index > 0) {
486 for (
int i = 0; i < 1000; ++i, --index) {
487 if (
auto const num2 = countHighlightsInItem(index)) {
505 for (
int i = 0; i < 1000; ++i, ++index) {
506 if (countHighlightsInItem(index)) {
517 QApplication::restoreOverrideCursor();
BtConfig & btConfig()
This is a shortchand for BtConfig::getInstance().
InfoDisplay::CInfoDisplay * infoDisplay() const noexcept
static BibleTime * instance() 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)
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
void setFilterOptions(FilterOptions filterOptions)
CSwordVerseKey indexToVerseKey(int index) const
QString indexToKeyName(int index) const
void setTextFilter(BtModuleTextFilter *textFilter)
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)
Q_INVOKABLE void setBibleKey(const QString &link)
void setBibleReference(const QString &reference)
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
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)
static void copyVerseRange(CSwordVerseKey const &key1, CSwordVerseKey const &key2)
void timerEvent(QTimerEvent *event) final override
void setHighlightWords(const QString &words, bool caseSensitivy)
void setFilterOptions(FilterOptions filterOptions)
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)
BtTextFilter m_textFilter
void contextMenuColumnChanged()
QFont font(int column) const
QColor getBackgroundHighlightColor() const
Q_INVOKABLE void setSelection(int column, int startIndex, int endIndex, QString const &selectedText)
bool hasSelectedText() const noexcept
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.
virtual CSwordKey * copy() const =0
CSwordModuleInfo const * module() const
virtual QString key() const =0
CSwordKey implementation for Sword's TreeKey.
bool setKey(const QString &key) final override
CSwordKey implementation for Sword's VerseKey.
QString key() const final override
bool setKey(const QString &key) final override
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)