Skip to content

Commit

Permalink
Added option for hotkey to toggle visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
medo64 committed Mar 14, 2021
1 parent 0128a08 commit b7e6d95
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 45 deletions.
5 changes: 5 additions & 0 deletions docs/man/qtext.1
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ Font size to use. Valid values are between \fB6\fP and \fB72\fP.
Determines hotkey used to show application.
Hotkey: Ctrl+Shift+Q

.TP
\fBHotkeyTogglesVisibility\fP
If true, pressing hotkey again will hide window instead of moving it to top.
HotkeyTogglesVisibility: false

.TP
\fBMinimizeToTray\fP
If true, minimizing application will actually move it to tray area instead.
Expand Down
9 changes: 9 additions & 0 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ void Settings::setHotkey(QKeySequence newHotkey) {
}


bool Settings::hotkeyTogglesVisibility() {
return Config::read("HotkeyTogglesVisibility", defaultHotkeyTogglesVisibility());
}

void Settings::setHotkeyTogglesVisibility(bool newHotkeyTogglesVisibility) {
Config::write("HotkeyTogglesVisibility", newHotkeyTogglesVisibility);
}


bool Settings::minimizeToTray() {
return Config::read("MinimizeToTray", defaultMinimizeToTray());
}
Expand Down
4 changes: 4 additions & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ class Settings {
return defaultHotkey;
}

static bool hotkeyTogglesVisibility();
static void setHotkeyTogglesVisibility(bool newHotkeyTogglesVisibility);
static bool defaultHotkeyTogglesVisibility() { return false; }

static bool minimizeToTray();
static void setMinimizeToTray(bool newMinimizeToTray);
static bool defaultMinimizeToTray() { return true; }
Expand Down
10 changes: 9 additions & 1 deletion src/ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ MainWindow::MainWindow(Storage* storage) : QMainWindow(nullptr), ui(new Ui::Main
//hotkey
_hotkey = new Hotkey(this);
_hotkey->registerHotkey(Settings::hotkey());
connect(_hotkey, &Hotkey::activated, this, &MainWindow::onTrayShow);
connect(_hotkey, &Hotkey::activated, this, &MainWindow::onHotkeyPress);

//single instance
connect(SingleInstance::instance(), &SingleInstance::newInstanceDetected, this, &MainWindow::onTrayShow);
Expand Down Expand Up @@ -946,6 +946,14 @@ void MainWindow::onTextStateChanged() {
ui->actionFontStrikethrough->setChecked(isSelectionFontStrikethrough);
}

void MainWindow::onHotkeyPress() {
if (this->isVisible() && Settings::hotkeyTogglesVisibility()) {
this->hide();
} else {
onTrayShow();
}
}

void MainWindow::onTrayActivate(QSystemTrayIcon::ActivationReason reason) {
if (reason == QSystemTrayIcon::DoubleClick) {
onTrayShow();
Expand Down
1 change: 1 addition & 0 deletions src/ui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class MainWindow : public QMainWindow {
void onTabChanged();
void onTabMoved(int from, int to);
void onTextStateChanged();
void onHotkeyPress();
void onTrayActivate(QSystemTrayIcon::ActivationReason reason);
void onTrayShow();
void onUpdatedFolder(FolderItem* folder);
Expand Down
7 changes: 7 additions & 0 deletions src/ui/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ SettingsDialog::SettingsDialog(QWidget* parent, Hotkey* hotkey) : QDialog(parent
_oldForceDarkMode = Settings::forceDarkMode();
_oldForcePlainCopyPaste = Settings::forcePlainCopyPaste();
_oldHotkey = Settings::hotkey();
_oldHotkeyTogglesVisibility = Settings::hotkeyTogglesVisibility();
_oldMinimizeToTray = Settings::minimizeToTray();
_oldShowInTaskbar = Settings::showInTaskbar();
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
Expand Down Expand Up @@ -79,6 +80,7 @@ void SettingsDialog::reset() {
ui->checkboxForceDarkMode->setChecked(_oldForceDarkMode);
ui->checkboxForcePlainCopyPaste->setChecked(_oldForcePlainCopyPaste);
ui->editHotkey->setNewKey(_oldHotkey);
ui->checkBoxHotkeyTogglesVisibility->setChecked(_oldHotkeyTogglesVisibility);
ui->checkboxMinimizeToTray->setChecked(_oldMinimizeToTray);
ui->checkboxShowInTaskbar->setChecked(_oldShowInTaskbar);
ui->checkboxShowMarkdown->setChecked(_oldShowMarkdown);
Expand All @@ -93,6 +95,7 @@ void SettingsDialog::restoreDefaults() {
ui->checkboxForceDarkMode->setChecked(Settings::defaultForceDarkMode());
ui->checkboxForcePlainCopyPaste->setChecked(Settings::defaultForcePlainCopyPaste());
ui->editHotkey->setNewKey(Settings::defaultHotkey());
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 Down Expand Up @@ -128,6 +131,10 @@ void SettingsDialog::accept() {
_changedHotkey = (newHotkey != 0) && (newHotkey != _oldHotkey);
if (_changedHotkey) { Settings::setHotkey(newHotkey); }

bool newHotkeyTogglesVisibility = (ui->checkBoxHotkeyTogglesVisibility->checkState() == Qt::Checked);
_changedHotkeyTogglesVisibility = newHotkeyTogglesVisibility != _oldHotkeyTogglesVisibility;
if (_changedHotkeyTogglesVisibility) { Settings::setHotkeyTogglesVisibility(newHotkeyTogglesVisibility); }

bool newMinimizeToTray = (ui->checkboxMinimizeToTray->checkState() == Qt::Checked);
_changedMinimizeToTray = newMinimizeToTray != _oldMinimizeToTray;
if (_changedMinimizeToTray) { Settings::setMinimizeToTray(newMinimizeToTray); }
Expand Down
3 changes: 3 additions & 0 deletions src/ui/settingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class SettingsDialog : public QDialog {
bool changedForceDarkMode() const { return _changedForceDarkMode; }
bool changedForcePlainCopyPaste() const { return _changedForcePlainCopyPaste; }
bool changedHotkey() const { return _changedHotkey; }
bool changedHotkeyTogglesVisibility() const { return _changedHotkeyTogglesVisibility; }
bool changedMinimizeToTray() const { return _changedMinimizeToTray; }
bool changedShowInTaskbar() const { return _changedShowInTaskbar; }
bool changedShowMarkdown() const { return _changedShowMarkdown; }
Expand All @@ -39,6 +40,7 @@ class SettingsDialog : public QDialog {
bool _changedForceDarkMode;
bool _changedForcePlainCopyPaste;
bool _changedHotkey;
bool _changedHotkeyTogglesVisibility;
bool _changedMinimizeToTray;
bool _changedShowInTaskbar;
bool _changedShowMarkdown;
Expand All @@ -50,6 +52,7 @@ class SettingsDialog : public QDialog {
bool _oldForceDarkMode;
bool _oldForcePlainCopyPaste;
QKeySequence _oldHotkey;
bool _oldHotkeyTogglesVisibility;
bool _oldMinimizeToTray;
bool _oldShowInTaskbar;
bool _oldShowMarkdown;
Expand Down
108 changes: 64 additions & 44 deletions src/ui/settingsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,33 @@
<x>0</x>
<y>0</y>
<width>450</width>
<height>182</height>
<height>225</height>
</rect>
</property>
<property name="windowTitle">
<string>Settings</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" alignment="Qt::AlignTop">
<item row="2" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Reset|QDialogButtonBox::RestoreDefaults</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="tabBehavior">
<attribute name="title">
<string>Behavior</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayoutLookAndFeel">
<item>
<widget class="QCheckBox" name="checkboxUseHtmlByDefault">
<property name="text">
<string>Use HTML by default</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkboxShowInTaskbar">
<property name="text">
Expand All @@ -52,31 +55,58 @@
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabLookAndFeel">
<attribute name="title">
<string>Look &amp;&amp; Feel</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QCheckBox" name="checkboxTabTextColorPerType">
<property name="toolTip">
<string>Different color is shown in tab depending if tab is plain text, Html, or Markdown.</string>
</property>
<layout class="QVBoxLayout" name="verticalLayoutLookAndFeel">
<item>
<widget class="QCheckBox" name="checkboxUseHtmlByDefault">
<property name="text">
<string>Color tab text per file type</string>
<string>Use HTML by default</string>
</property>
</widget>
</item>
<item row="1" column="0">
<item>
<widget class="QCheckBox" name="checkboxForcePlainCopyPaste">
<property name="text">
<string>Force plain copy/paste (even for Html files)</string>
</property>
</widget>
</item>
<item row="3" column="0">
<item>
<widget class="QCheckBox" name="checkboxForceDarkMode">
<property name="text">
<string>Force dark mode</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkboxTabTextColorPerType">
<property name="toolTip">
<string>Different color is shown in tab depending if tab is plain text, Html, or Markdown.</string>
</property>
<property name="text">
<string>Color tab text per file type</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand All @@ -89,13 +119,6 @@
</property>
</spacer>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="checkboxForceDarkMode">
<property name="text">
<string>Force dark mode</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabSystem">
Expand All @@ -112,10 +135,7 @@
</item>
<item>
<layout class="QGridLayout" name="gridSystem">
<item row="0" column="1">
<widget class="HotkeyEdit" name="editHotkey"/>
</item>
<item row="1" column="1">
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>0</number>
Expand All @@ -142,7 +162,10 @@
</item>
</layout>
</item>
<item row="1" column="0">
<item row="0" column="1">
<widget class="HotkeyEdit" name="editHotkey"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelDataPath">
<property name="text">
<string>Data directory:</string>
Expand All @@ -156,6 +179,13 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="checkBoxHotkeyTogglesVisibility">
<property name="text">
<string>Toggle visibility</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand All @@ -177,8 +207,8 @@
<attribute name="title">
<string>Experimental</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayoutSystem">
<item>
<widget class="QCheckBox" name="checkboxShowMarkdown">
<property name="toolTip">
<string>Controls if markdown will be shown as one of the file options</string>
Expand All @@ -188,7 +218,7 @@
</property>
</widget>
</item>
<item row="1" column="0">
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand All @@ -205,16 +235,6 @@
</widget>
</widget>
</item>
<item row="1" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Reset|QDialogButtonBox::RestoreDefaults</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
Expand Down

0 comments on commit b7e6d95

Please sign in to comment.