Debian Codegraph @

src/gui/settingsDialog/TrayIconSettings.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2020 Damir Porobic <[email protected]>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "TrayIconSettings.h"
21
22 TrayIconSettings::TrayIconSettings(const QList<CaptureModes> &captureModes, const QSharedPointer<IConfig> &config) :
23 mConfig(config),
24 mUseTrayIconCheckBox(new QCheckBox(this)),
25 mMinimizeToTrayCheckBox(new QCheckBox(this)),
26 mCloseToTrayCheckBox(new QCheckBox(this)),
27 mTrayIconNotificationsCheckBox(new QCheckBox(this)),
28 mUsePlatformSpecificNotificationServiceCheckBox(new QCheckBox(this)),
29 mDefaultActionCaptureModeCombobox(new QComboBox(this)),
30 mStartMinimizedToTrayCheckBox(new QCheckBox(this)),
31 mDefaultActionShowEditorRadioButton(new QRadioButton(this)),
32 mDefaultActionCaptureRadioButton(new QRadioButton(this)),
33 mDefaultActionGroupBox(new QGroupBox(this)),
34 mDefaultActionLayout(new QGridLayout),
35 mLayout(new QGridLayout)
36 {
37 Q_ASSERT(mConfig != nullptr);
38
39 initGui();
40 populateDefaultActionCaptureModeCombobox(captureModes);
41
42 loadConfig();
43 }
44
45 void TrayIconSettings::saveSettings()
46 {
47 mConfig->setUseTrayIcon(mUseTrayIconCheckBox->isChecked());
48 mConfig->setMinimizeToTray(mMinimizeToTrayCheckBox->isChecked());
49 mConfig->setStartMinimizedToTray(mStartMinimizedToTrayCheckBox->isChecked());
50 mConfig->setCloseToTray(mCloseToTrayCheckBox->isChecked());
51 mConfig->setTrayIconNotificationsEnabled(mTrayIconNotificationsCheckBox->isChecked());
52 mConfig->setPlatformSpecificNotificationServiceEnabled(mUsePlatformSpecificNotificationServiceCheckBox->isChecked());
53 mConfig->setDefaultTrayIconActionMode(selectedTrayIconDefaultActionMode());
54 mConfig->setDefaultTrayIconCaptureMode(mDefaultActionCaptureModeCombobox->currentData().value<CaptureModes>());
55 }
56
57 void TrayIconSettings::initGui()
58 {
59 mUseTrayIconCheckBox->setText(tr("Use Tray Icon"));
60 mUseTrayIconCheckBox->setToolTip(tr("When enabled will add a Tray Icon to the TaskBar if the OS Window Manager supports it.\n"
61 "Change requires restart."));
62 mMinimizeToTrayCheckBox->setText(tr("Minimize to Tray"));
63 mStartMinimizedToTrayCheckBox->setText(tr("Start Minimized to Tray"));
64 mCloseToTrayCheckBox->setText(tr("Close to Tray"));
65 mTrayIconNotificationsCheckBox->setText(tr("Display Tray Icon notifications"));
66 mUsePlatformSpecificNotificationServiceCheckBox->setText(tr("Use platform specific notification service"));
67 mUsePlatformSpecificNotificationServiceCheckBox->setToolTip(tr("When enabled will use try to use platform specific notification\n"
68 "service when such exists. Change requires restart to take effect."));
69
70 connect(mUseTrayIconCheckBox, &QCheckBox::stateChanged, this, &TrayIconSettings::useTrayIconChanged);
71
72 mDefaultActionShowEditorRadioButton->setText(tr("Show Editor"));
73 mDefaultActionCaptureRadioButton->setText(tr("Capture") + QLatin1String(":"));
74
75 mDefaultActionLayout->addWidget(mDefaultActionShowEditorRadioButton, 0, 0, 1, 1);
76 mDefaultActionLayout->addWidget(mDefaultActionCaptureRadioButton, 1, 0, 1, 1);
77 mDefaultActionLayout->addWidget(mDefaultActionCaptureModeCombobox, 1, 1, 1, 1);
78 mDefaultActionLayout->setColumnStretch(2, 1);
79
80 mDefaultActionGroupBox->setTitle(tr("Default Tray Icon action"));
81 mDefaultActionGroupBox->setToolTip(tr("Default Action that is triggered by left clicking the tray icon."));
82 mDefaultActionGroupBox->setLayout(mDefaultActionLayout);
83
84 mLayout->setAlignment(Qt::AlignTop);
85 mLayout->setColumnMinimumWidth(0, 10);
86 mLayout->addWidget(mUseTrayIconCheckBox, 0, 0, 1, 4);
87 mLayout->setRowMinimumHeight(1, 5);
88 mLayout->addWidget(mStartMinimizedToTrayCheckBox, 2, 0, 1, 4);
89 mLayout->addWidget(mMinimizeToTrayCheckBox, 3, 0, 1, 4);
90 mLayout->addWidget(mCloseToTrayCheckBox, 4, 0, 1, 4);
91 mLayout->addWidget(mTrayIconNotificationsCheckBox, 5, 0, 1, 4);
92 mLayout->addWidget(mUsePlatformSpecificNotificationServiceCheckBox, 6, 0, 1, 4);
93 mLayout->addWidget(mDefaultActionGroupBox, 7, 0, 1, 4);
94
95 setTitle(tr("Tray Icon Settings"));
96 setLayout(mLayout);
97 }
98
99 void TrayIconSettings::loadConfig()
100 {
101 mUseTrayIconCheckBox->setChecked(mConfig->useTrayIcon());
102 mMinimizeToTrayCheckBox->setChecked(mConfig->minimizeToTray());
103 mStartMinimizedToTrayCheckBox->setChecked(mConfig->startMinimizedToTray());
104 mCloseToTrayCheckBox->setChecked(mConfig->closeToTray());
105 mTrayIconNotificationsCheckBox->setChecked(mConfig->trayIconNotificationsEnabled());
106 mUsePlatformSpecificNotificationServiceCheckBox->setChecked(mConfig->platformSpecificNotificationServiceEnabled());
107 mDefaultActionShowEditorRadioButton->setChecked(mConfig->defaultTrayIconActionMode() == TrayIconDefaultActionMode::ShowEditor);
108 mDefaultActionCaptureRadioButton->setChecked(mConfig->defaultTrayIconActionMode() == TrayIconDefaultActionMode::Capture);
109 mDefaultActionCaptureModeCombobox->setCurrentIndex(indexOfSelectedCaptureMode());
110
111 useTrayIconChanged();
112 }
113
114 int TrayIconSettings::indexOfSelectedCaptureMode() const
115 {
116 return mDefaultActionCaptureModeCombobox->findData(QVariant::fromValue(mConfig->defaultTrayIconCaptureMode()));
117 }
118
119 TrayIconDefaultActionMode TrayIconSettings::selectedTrayIconDefaultActionMode() const
120 {
121 return mDefaultActionShowEditorRadioButton->isChecked() ? TrayIconDefaultActionMode::ShowEditor : TrayIconDefaultActionMode::Capture;
122 }
123
124 void TrayIconSettings::populateDefaultActionCaptureModeCombobox(const QList<CaptureModes> &captureModes)
125 {
126 for (auto captureMode: captureModes) {
127 const auto label = EnumTranslator::instance()->toTranslatedString(captureMode);
128 mDefaultActionCaptureModeCombobox->addItem(label, static_cast<int>(captureMode));
129 }
130 }
131
132 void TrayIconSettings::useTrayIconChanged()
133 {
134 const auto trayIconEnabled = mUseTrayIconCheckBox->isChecked();
135 mMinimizeToTrayCheckBox->setEnabled(trayIconEnabled);
136 mCloseToTrayCheckBox->setEnabled(trayIconEnabled);
137 mTrayIconNotificationsCheckBox->setEnabled(trayIconEnabled);
138 mUsePlatformSpecificNotificationServiceCheckBox->setEnabled(trayIconEnabled);
139 mStartMinimizedToTrayCheckBox->setEnabled(trayIconEnabled);
140 mDefaultActionCaptureModeCombobox->setEnabled(trayIconEnabled);
141 mDefaultActionShowEditorRadioButton->setEnabled(trayIconEnabled);
142 mDefaultActionCaptureRadioButton->setEnabled(trayIconEnabled);
143 }