First tray attempt, seems to be working

This commit is contained in:
Blue 2022-08-15 19:40:07 +03:00
parent 7192286aeb
commit 7e9eed2075
Signed by: blue
GPG key ID: 9B203B252A63EE38
13 changed files with 201 additions and 7 deletions

View file

@ -28,6 +28,23 @@ PageGeneral::PageGeneral(QWidget* parent):
QSettings settings;
m_ui->downloadsPathInput->setText(settings.value("downloadsPath").toString());
if (QSystemTrayIcon::isSystemTrayAvailable()) {
bool tray = settings.value("tray", false).toBool();
m_ui->trayInput->setChecked(tray);
if (tray) {
m_ui->hideTrayInput->setChecked(settings.value("hideTray", false).toBool());
} else {
m_ui->hideTrayInput->setEnabled(false);
}
connect(m_ui->trayInput, &QCheckBox::stateChanged, this, &PageGeneral::onTrayChecked);
connect(m_ui->hideTrayInput, &QCheckBox::stateChanged, this, &PageGeneral::onHideTrayChecked);
} else {
m_ui->trayInput->setEnabled(false);
m_ui->hideTrayInput->setEnabled(false);
m_ui->trayInput->setToolTip(tr("Tray is not available for your system")); //TODO translate
}
connect(m_ui->downloadsPathButton, &QPushButton::clicked, this, &PageGeneral::onBrowseButtonClicked);
}
@ -76,3 +93,19 @@ void PageGeneral::onDialogDestroyed()
{
dialog = nullptr;
}
void PageGeneral::onTrayChecked(int state)
{
bool enabled = state == Qt::Checked;
emit variableModified("tray", enabled);
m_ui->hideTrayInput->setEnabled(enabled);
if (!enabled) {
m_ui->hideTrayInput->setEnabled(false);
}
}
void PageGeneral::onHideTrayChecked(int state)
{
bool enabled = state == Qt::Checked;
emit variableModified("hideTray", enabled);
}

View file

@ -24,6 +24,7 @@
#include <QVariant>
#include <QSettings>
#include <QFileDialog>
#include <QSystemTrayIcon>
namespace Ui
{
@ -47,6 +48,8 @@ private slots:
void onBrowseButtonClicked();
void onDialogAccepted();
void onDialogDestroyed();
void onTrayChecked(int state);
void onHideTrayChecked(int state);
private:
QScopedPointer<Ui::PageGeneral> m_ui;

View file

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>477</width>
<height>310</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
@ -39,6 +39,34 @@
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="trayLabel">
<property name="text">
<string>Tray icon</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="trayInput">
<property name="text">
<string>Mimimize Squawk to tray when closing main window</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="hideTrayLabel">
<property name="text">
<string>Hide tray icon</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="hideTrayInput">
<property name="text">
<string>Hide tray icon when Squawk main window is visible</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>

View file

@ -57,6 +57,7 @@ void Settings::onVariableModified(const QString& key, const QVariant& value)
void Settings::apply()
{
QSettings settings;
bool trayChanged = false;
for (const std::pair<const QString, QVariant>& pair: modifiedSettings) {
if (pair.first == "style") {
Shared::Global::setStyle(pair.second.toString());
@ -73,8 +74,18 @@ void Settings::apply()
emit changeDownloadsPath(path);
}
}
} else if (pair.first == "tray" || pair.first == "hideTray") {
bool oldValue = settings.value(pair.first, false).toBool();
bool newValue = pair.second.toBool();
if (oldValue != newValue) {
trayChanged = true;
settings.setValue(pair.first, pair.second);
}
}
}
if (trayChanged) {
emit changeTray(settings.value("tray", false).toBool(), settings.value("hideTray", false).toBool());
}
modifiedSettings.clear();

View file

@ -45,6 +45,7 @@ public:
signals:
void changeDownloadsPath(const QString& path);
void changeTray(bool enable, bool hide);
public slots:
void apply();