From 843c5470345a587a7ccb87d9a7cdb64d94a2a8b7 Mon Sep 17 00:00:00 2001 From: Josip Medved Date: Sat, 13 Mar 2021 23:11:45 -0800 Subject: [PATCH] Added option for URLs following --- docs/man/qtext.1 | 6 +++++ src/settings.cpp | 9 ++++++++ src/settings.h | 4 ++++ src/storage/fileitem.cpp | 46 +++++++++++++++++++++------------------ src/ui/settingsdialog.cpp | 13 ++++++++--- src/ui/settingsdialog.h | 3 +++ src/ui/settingsdialog.ui | 28 ++++++++++++++++++++++-- 7 files changed, 83 insertions(+), 26 deletions(-) diff --git a/docs/man/qtext.1 b/docs/man/qtext.1 index 65e57fa..4569b86 100644 --- a/docs/man/qtext.1 +++ b/docs/man/qtext.1 @@ -272,10 +272,16 @@ Which file type is preselected when creating new file. Valid values are \fBPlain\fP, \fBMarkdown\fP, and \fBHtml\fP. DefaultFileType: Plain +.TP +\fBFollowUrls\fP +If true, URLs will be clickable. + FollowUrls: true + .TP \fBFontName\fP Font name to use. On Windows default is \fBCalibri\fP and on Linux default is \fBDejaVu Sans\fP. + FontName: Calibri FontName: DejaVu Sans .TP diff --git a/src/settings.cpp b/src/settings.cpp index 97a41e6..1348006 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -110,6 +110,15 @@ void Settings::setDeletionStyle(DeletionStyle newDeletionStyle) { } +bool Settings::followUrls() { + return Config::read("FollowUrls", defaultFollowUrls()); +} + +void Settings::setFollowUrls(bool newFollowUrls) { + Config::write("FollowUrls", newFollowUrls); +} + + QFont Settings::font() { QFont font(Settings::fontName(), Settings::fontSize()); return font; diff --git a/src/settings.h b/src/settings.h index 4a29e8d..73ed2a6 100644 --- a/src/settings.h +++ b/src/settings.h @@ -43,6 +43,10 @@ class Settings { static void setDeletionStyle(DeletionStyle newDeletionStyle); static DeletionStyle defaultDeletionStyle() { return DeletionStyle::Delete; } + static bool followUrls(); + static void setFollowUrls(bool newFollowUrls); + static bool defaultFollowUrls() { return true; } + static QFont font(); static void setFont(QFont newFont); diff --git a/src/storage/fileitem.cpp b/src/storage/fileitem.cpp index 17c4c83..1aca5c6 100644 --- a/src/storage/fileitem.cpp +++ b/src/storage/fileitem.cpp @@ -455,33 +455,37 @@ bool FileItem::eventFilter(QObject* obj, QEvent* event) { if (obj == viewport()) { switch (event->type()) { case QEvent::MouseButtonDblClick: { - QMouseEvent* e = static_cast(event); - if ((e->buttons() == Qt::LeftButton)) { - QString anchor = findAnchorAt(e->pos()); - if (!anchor.isEmpty()) { - qDebug().noquote().nospace() << "[FileItem] URL executing (" << anchor << ")"; - QApplication::setOverrideCursor(Qt::WaitCursor); - Helpers::openUrl(anchor); - QApplication::restoreOverrideCursor(); - return true; + if (Settings::followUrls()) { + QMouseEvent* e = static_cast(event); + if ((e->buttons() == Qt::LeftButton)) { + QString anchor = findAnchorAt(e->pos()); + if (!anchor.isEmpty()) { + qDebug().noquote().nospace() << "[FileItem] URL executing (" << anchor << ")"; + QApplication::setOverrideCursor(Qt::WaitCursor); + Helpers::openUrl(anchor); + QApplication::restoreOverrideCursor(); + return true; + } } } } break; case QEvent::MouseMove: { - QMouseEvent* e = static_cast(event); - QString anchor = findAnchorAt(e->pos()); - if ((e->buttons() == Qt::NoButton)) { - if (!anchor.isEmpty()) { - if (!customCursorSet) { - qDebug().noquote().nospace() << "[FileItem] URL detected (" << anchor << ")"; - viewport()->setCursor(Qt::PointingHandCursor); - customCursorSet = true; + if (Settings::followUrls()) { + QMouseEvent* e = static_cast(event); + QString anchor = findAnchorAt(e->pos()); + if ((e->buttons() == Qt::NoButton)) { + if (!anchor.isEmpty()) { + if (!customCursorSet) { + qDebug().noquote().nospace() << "[FileItem] URL detected (" << anchor << ")"; + viewport()->setCursor(Qt::PointingHandCursor); + customCursorSet = true; + } + } else if (customCursorSet) { + qDebug().noquote().nospace() << "[FileItem] URL gone"; + viewport()->setCursor(Qt::IBeamCursor); + customCursorSet = false; } - } else if (customCursorSet) { - qDebug().noquote().nospace() << "[FileItem] URL gone"; - viewport()->setCursor(Qt::IBeamCursor); - customCursorSet = false; } } } break; diff --git a/src/ui/settingsdialog.cpp b/src/ui/settingsdialog.cpp index 09e408a..e9cecc8 100644 --- a/src/ui/settingsdialog.cpp +++ b/src/ui/settingsdialog.cpp @@ -18,6 +18,7 @@ SettingsDialog::SettingsDialog(QWidget* parent, Hotkey* hotkey) : QDialog(parent _oldAlwaysOnTop = Settings::alwaysOnTop(); _oldAutostart = Setup::autostart(); _oldDataPath = Settings::dataPath(); + _oldFollowUrls = Settings::followUrls(); _oldForceDarkMode = Settings::forceDarkMode(); _oldForcePlainCopyPaste = Settings::forcePlainCopyPaste(); _oldHotkey = Settings::hotkey(); @@ -77,10 +78,11 @@ void SettingsDialog::reset() { ui->checkboxAlwaysOnTop->setChecked(_oldAlwaysOnTop); ui->checkboxAutostart->setChecked(_oldAutostart); ui->editDataPath->setText(QDir::toNativeSeparators(Settings::dataPath())); + ui->checkboxFollowUrls->setChecked(_oldFollowUrls); ui->checkboxForceDarkMode->setChecked(_oldForceDarkMode); ui->checkboxForcePlainCopyPaste->setChecked(_oldForcePlainCopyPaste); ui->editHotkey->setNewKey(_oldHotkey); - ui->checkBoxHotkeyTogglesVisibility->setChecked(_oldHotkeyTogglesVisibility); + ui->checkboxHotkeyTogglesVisibility->setChecked(_oldHotkeyTogglesVisibility); ui->checkboxMinimizeToTray->setChecked(_oldMinimizeToTray); ui->checkboxShowInTaskbar->setChecked(_oldShowInTaskbar); ui->checkboxShowMarkdown->setChecked(_oldShowMarkdown); @@ -92,10 +94,11 @@ void SettingsDialog::restoreDefaults() { ui->checkboxAlwaysOnTop->setChecked(Settings::defaultAlwaysOnTop()); ui->checkboxAutostart->setChecked(true); ui->editDataPath->setText(QDir::toNativeSeparators(Settings::defaultDataPath())); + ui->checkboxFollowUrls->setChecked(Settings::defaultFollowUrls()); ui->checkboxForceDarkMode->setChecked(Settings::defaultForceDarkMode()); ui->checkboxForcePlainCopyPaste->setChecked(Settings::defaultForcePlainCopyPaste()); ui->editHotkey->setNewKey(Settings::defaultHotkey()); - ui->checkBoxHotkeyTogglesVisibility->setChecked(Settings::defaultHotkeyTogglesVisibility()); + ui->checkboxHotkeyTogglesVisibility->setChecked(Settings::defaultHotkeyTogglesVisibility()); ui->checkboxMinimizeToTray->setChecked(Settings::defaultMinimizeToTray()); ui->checkboxShowInTaskbar->setChecked(Settings::defaultShowInTaskbar()); #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) @@ -119,6 +122,10 @@ void SettingsDialog::accept() { _changedDataPath = newDataDirectory != _oldDataPath; if (_changedDataPath) { Settings::setDataPath(newDataDirectory); } + bool newFollowUrls = (ui->checkboxFollowUrls->checkState() == Qt::Checked); + _changedFollowUrls = newFollowUrls != _oldFollowUrls; + if (_changedFollowUrls) { Settings::setFollowUrls(newFollowUrls); } + bool newForceDarkMode = (ui->checkboxForceDarkMode->checkState() == Qt::Checked); _changedForceDarkMode = newForceDarkMode != _oldForceDarkMode; if (_changedForceDarkMode) { Settings::setForceDarkMode(newForceDarkMode); } @@ -131,7 +138,7 @@ void SettingsDialog::accept() { _changedHotkey = (newHotkey != 0) && (newHotkey != _oldHotkey); if (_changedHotkey) { Settings::setHotkey(newHotkey); } - bool newHotkeyTogglesVisibility = (ui->checkBoxHotkeyTogglesVisibility->checkState() == Qt::Checked); + bool newHotkeyTogglesVisibility = (ui->checkboxHotkeyTogglesVisibility->checkState() == Qt::Checked); _changedHotkeyTogglesVisibility = newHotkeyTogglesVisibility != _oldHotkeyTogglesVisibility; if (_changedHotkeyTogglesVisibility) { Settings::setHotkeyTogglesVisibility(newHotkeyTogglesVisibility); } diff --git a/src/ui/settingsdialog.h b/src/ui/settingsdialog.h index 3f8b66d..5349a39 100644 --- a/src/ui/settingsdialog.h +++ b/src/ui/settingsdialog.h @@ -16,6 +16,7 @@ class SettingsDialog : public QDialog { bool changedAlwaysOnTop() const { return _changedAlwaysOnTop; } bool changedAutostart() const { return _changedAutostart; } bool changedDataPath() const { return _changedDataPath; } + bool changedFollowUrls() const { return _changedFollowUrls; } bool changedForceDarkMode() const { return _changedForceDarkMode; } bool changedForcePlainCopyPaste() const { return _changedForcePlainCopyPaste; } bool changedHotkey() const { return _changedHotkey; } @@ -37,6 +38,7 @@ class SettingsDialog : public QDialog { bool _changedAlwaysOnTop; bool _changedAutostart; bool _changedDataPath; + bool _changedFollowUrls; bool _changedForceDarkMode; bool _changedForcePlainCopyPaste; bool _changedHotkey; @@ -49,6 +51,7 @@ class SettingsDialog : public QDialog { bool _oldAlwaysOnTop; bool _oldAutostart; QString _oldDataPath; + bool _oldFollowUrls; bool _oldForceDarkMode; bool _oldForcePlainCopyPaste; QKeySequence _oldHotkey; diff --git a/src/ui/settingsdialog.ui b/src/ui/settingsdialog.ui index 64f7591..8ed2e6b 100644 --- a/src/ui/settingsdialog.ui +++ b/src/ui/settingsdialog.ui @@ -27,7 +27,7 @@ - 2 + 3 @@ -55,6 +55,13 @@ + + + + Follow URLs (double-click) + + + @@ -180,7 +187,7 @@ - + Toggle visibility @@ -244,6 +251,23 @@
ui/hotkeyedit.h
+ + tabWidget + checkboxAutostart + editHotkey + checkboxHotkeyTogglesVisibility + editDataPath + buttonDataPath + checkboxForcePlainCopyPaste + checkboxForceDarkMode + checkboxTabTextColorPerType + checkboxShowInTaskbar + checkboxFollowUrls + checkboxUseHtmlByDefault + checkboxMinimizeToTray + checkboxAlwaysOnTop + checkboxShowMarkdown +