Skip to content

Commit

Permalink
Added option for URLs following
Browse files Browse the repository at this point in the history
  • Loading branch information
medo64 committed Mar 14, 2021
1 parent b7e6d95 commit 843c547
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 26 deletions.
6 changes: 6 additions & 0 deletions docs/man/qtext.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
46 changes: 25 additions & 21 deletions src/storage/fileitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,33 +455,37 @@ bool FileItem::eventFilter(QObject* obj, QEvent* event) {
if (obj == viewport()) {
switch (event->type()) {
case QEvent::MouseButtonDblClick: {
QMouseEvent* e = static_cast<QMouseEvent*>(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<QMouseEvent*>(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<QMouseEvent*>(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<QMouseEvent*>(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;
Expand Down
13 changes: 10 additions & 3 deletions src/ui/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand All @@ -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); }
Expand All @@ -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); }

Expand Down
3 changes: 3 additions & 0 deletions src/ui/settingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -37,6 +38,7 @@ class SettingsDialog : public QDialog {
bool _changedAlwaysOnTop;
bool _changedAutostart;
bool _changedDataPath;
bool _changedFollowUrls;
bool _changedForceDarkMode;
bool _changedForcePlainCopyPaste;
bool _changedHotkey;
Expand All @@ -49,6 +51,7 @@ class SettingsDialog : public QDialog {
bool _oldAlwaysOnTop;
bool _oldAutostart;
QString _oldDataPath;
bool _oldFollowUrls;
bool _oldForceDarkMode;
bool _oldForcePlainCopyPaste;
QKeySequence _oldHotkey;
Expand Down
28 changes: 26 additions & 2 deletions src/ui/settingsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<item row="1" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>2</number>
<number>3</number>
</property>
<widget class="QWidget" name="tabBehavior">
<attribute name="title">
Expand Down Expand Up @@ -55,6 +55,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkboxFollowUrls">
<property name="text">
<string>Follow URLs (double-click)</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
Expand Down Expand Up @@ -180,7 +187,7 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="checkBoxHotkeyTogglesVisibility">
<widget class="QCheckBox" name="checkboxHotkeyTogglesVisibility">
<property name="text">
<string>Toggle visibility</string>
</property>
Expand Down Expand Up @@ -244,6 +251,23 @@
<header>ui/hotkeyedit.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>tabWidget</tabstop>
<tabstop>checkboxAutostart</tabstop>
<tabstop>editHotkey</tabstop>
<tabstop>checkboxHotkeyTogglesVisibility</tabstop>
<tabstop>editDataPath</tabstop>
<tabstop>buttonDataPath</tabstop>
<tabstop>checkboxForcePlainCopyPaste</tabstop>
<tabstop>checkboxForceDarkMode</tabstop>
<tabstop>checkboxTabTextColorPerType</tabstop>
<tabstop>checkboxShowInTaskbar</tabstop>
<tabstop>checkboxFollowUrls</tabstop>
<tabstop>checkboxUseHtmlByDefault</tabstop>
<tabstop>checkboxMinimizeToTray</tabstop>
<tabstop>checkboxAlwaysOnTop</tabstop>
<tabstop>checkboxShowMarkdown</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
Expand Down

0 comments on commit 843c547

Please sign in to comment.