mirror of
https://github.com/zealdocs/zeal.git
synced 2024-11-27 11:44:56 +03:00
Allow disabling the tray icon
This commit is contained in:
parent
0579dd0c94
commit
81d99c0fdc
@ -10,7 +10,6 @@
|
||||
#include <QStandardPaths>
|
||||
#include <QMessageBox>
|
||||
#include <QStyleFactory>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QLocalSocket>
|
||||
#include <QDir>
|
||||
#include <QSettings>
|
||||
@ -63,7 +62,8 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
icon = QIcon::fromTheme("edit-find");
|
||||
#endif
|
||||
setWindowIcon(icon);
|
||||
createTrayIcon();
|
||||
if(settings.value("hidingBehavior", "systray").toString() == "systray")
|
||||
createTrayIcon();
|
||||
|
||||
QKeySequence keySequence;
|
||||
if(settings.value("hotkey").isNull()) {
|
||||
@ -74,9 +74,14 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
|
||||
// initialise key grabber
|
||||
connect(&nativeFilter, &ZealNativeEventFilter::gotHotKey, [&]() {
|
||||
if(isVisible()) hide();
|
||||
else {
|
||||
if(!isVisible() || !isActiveWindow()) {
|
||||
bringToFront(true);
|
||||
} else {
|
||||
if(trayIcon) {
|
||||
hide();
|
||||
} else {
|
||||
showMinimized();
|
||||
}
|
||||
}
|
||||
});
|
||||
qApp->eventDispatcher()->installNativeEventFilter(&nativeFilter);
|
||||
@ -290,10 +295,27 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
connect(settingsAction, &QAction::triggered, [=]() {
|
||||
settingsDialog.setHotKey(hotKey);
|
||||
settingsDialog.ui->minFontSize->setValue(settings.value("minFontSize").toInt());
|
||||
QString hiding = settings.value("hidingBehavior", "systray").toString();
|
||||
if(hiding == "systray") {
|
||||
settingsDialog.ui->radioSysTray->setChecked(true);
|
||||
} else {
|
||||
settingsDialog.ui->radioMinimize->setChecked(true);
|
||||
}
|
||||
nativeFilter.setEnabled(false);
|
||||
if(settingsDialog.exec()) {
|
||||
setHotKey(settingsDialog.hotKey());
|
||||
settings.setValue("minFontSize", QVariant(ui->webView->settings()->fontSize(QWebSettings::MinimumFontSize)));
|
||||
settings.setValue("hidingBehavior",
|
||||
settingsDialog.ui->radioSysTray->isChecked() ?
|
||||
"systray" : "minimize");
|
||||
if(settings.value("hidingBehavior").toString() == "systray") {
|
||||
createTrayIcon();
|
||||
} else if(trayIcon) {
|
||||
trayIcon->deleteLater();
|
||||
trayIconMenu->deleteLater();
|
||||
trayIcon = nullptr;
|
||||
trayIconMenu = nullptr;
|
||||
}
|
||||
} else {
|
||||
// cancelled - restore previous value
|
||||
ui->webView->settings()->setFontSize(QWebSettings::MinimumFontSize, settings.value("minFontSize").toInt());
|
||||
@ -360,10 +382,11 @@ MainWindow::~MainWindow()
|
||||
|
||||
void MainWindow::createTrayIcon()
|
||||
{
|
||||
auto trayIconMenu = new QMenu(this);
|
||||
if(trayIcon) return;
|
||||
trayIconMenu = new QMenu(this);
|
||||
auto quitAction = trayIconMenu->addAction("&Quit");
|
||||
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
|
||||
auto trayIcon = new QSystemTrayIcon(this);
|
||||
trayIcon = new QSystemTrayIcon(this);
|
||||
trayIcon->setContextMenu(trayIconMenu);
|
||||
trayIcon->setIcon(icon);
|
||||
trayIcon->setToolTip("Zeal");
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QDialog>
|
||||
#include <QSettings>
|
||||
#include <QSystemTrayIcon>
|
||||
#include "zeallistmodel.h"
|
||||
#include "zealsearchmodel.h"
|
||||
#include "zealnativeeventfilter.h"
|
||||
@ -41,6 +42,8 @@ private:
|
||||
ZealNativeEventFilter nativeFilter;
|
||||
ZealSettingsDialog settingsDialog;
|
||||
QNetworkAccessManager naManager;
|
||||
QSystemTrayIcon *trayIcon = nullptr;
|
||||
QMenu *trayIconMenu = nullptr;
|
||||
int naCount = 0;
|
||||
QMap<QString, QString> urls;
|
||||
protected:
|
||||
|
@ -17,7 +17,7 @@
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab_3">
|
||||
<attribute name="title">
|
||||
@ -26,30 +26,55 @@
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Hotkey</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<item row="2" column="1">
|
||||
<widget class="RazorShortcutButton" name="toolButton">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<item row="3" column="1">
|
||||
<widget class="QSpinBox" name="minFontSize"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Minimum font size</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Hiding behavior</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioSysTray">
|
||||
<property name="text">
|
||||
<string>System Tray</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioMinimize">
|
||||
<property name="text">
|
||||
<string>Minimize</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
|
Loading…
Reference in New Issue
Block a user