Debian Codegraph @

src/gui/settingsDialog/HotKeySettings.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2019 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 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 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 "HotKeySettings.h"
21
22 HotKeySettings::HotKeySettings(const QList<CaptureModes> &captureModes, const QSharedPointer<IPlatformChecker> &platformChecker, const QSharedPointer<IConfig> &config) :
23 mConfig(config),
24 mPlatformChecker(platformChecker),
25 mCaptureModes(captureModes),
26 mEnableGlobalHotKeysCheckBox(new QCheckBox(this)),
27 mRectAreaLabel(new QLabel(this)),
28 mLastRectAreaLabel(new QLabel(this)),
29 mFullScreenLabel(new QLabel(this)),
30 mCurrentScreenLabel(new QLabel(this)),
31 mActiveWindowLabel(new QLabel(this)),
32 mWindowUnderCursorLabel(new QLabel(this)),
33 mPortalLabel(new QLabel(this)),
34 mRectAreaClearPushButton(new QPushButton(this)),
35 mLastRectAreaClearPushButton(new QPushButton(this)),
36 mFullScreenClearPushButton(new QPushButton(this)),
37 mCurrentScreenClearPushButton(new QPushButton(this)),
38 mActiveWindowClearPushButton(new QPushButton(this)),
39 mWindowUnderCursorClearPushButton(new QPushButton(this)),
40 mPortalClearPushButton(new QPushButton(this)),
41 mLayout(new QGridLayout(this))
42 {
43 Q_ASSERT(mConfig != nullptr);
44
45 initGui();
46 loadConfig();
47 }
48
49 HotKeySettings::~HotKeySettings()
50 {
51 delete mEnableGlobalHotKeysCheckBox;
52 delete mRectAreaLabel;
53 delete mLastRectAreaLabel;
54 delete mFullScreenLabel;
55 delete mCurrentScreenLabel;
56 delete mActiveWindowLabel;
57 delete mWindowUnderCursorLabel;
58 delete mPortalLabel;
59 delete mRectAreaKeySequenceLineEdit;
60 delete mLastRectAreaKeySequenceLineEdit;
61 delete mFullScreenKeySequenceLineEdit;
62 delete mCurrentScreenKeySequenceLineEdit;
63 delete mActiveWindowKeySequenceLineEdit;
64 delete mWindowUnderCursorKeySequenceLineEdit;
65 delete mPortalKeySequenceLineEdit;
66 delete mRectAreaClearPushButton;
67 delete mLastRectAreaClearPushButton;
68 delete mFullScreenClearPushButton;
69 delete mCurrentScreenClearPushButton;
70 delete mActiveWindowClearPushButton;
71 delete mWindowUnderCursorClearPushButton;
72 delete mPortalClearPushButton;
73 delete mLayout;
74 }
75
76 void HotKeySettings::saveSettings()
77 {
78 mConfig->setGlobalHotKeysEnabled(mEnableGlobalHotKeysCheckBox->isChecked());
79 mConfig->setRectAreaHotKey(mRectAreaKeySequenceLineEdit->value());
80 mConfig->setLastRectAreaHotKey(mLastRectAreaKeySequenceLineEdit->value());
81 mConfig->setFullScreenHotKey(mFullScreenKeySequenceLineEdit->value());
82 mConfig->setCurrentScreenHotKey(mCurrentScreenKeySequenceLineEdit->value());
83 mConfig->setActiveWindowHotKey(mActiveWindowKeySequenceLineEdit->value());
84 mConfig->setWindowUnderCursorHotKey(mWindowUnderCursorKeySequenceLineEdit->value());
85 mConfig->setPortalHotKey(mPortalKeySequenceLineEdit->value());
86 }
87
88 void HotKeySettings::initGui()
89 {
90 auto allowedKeys = HotKeyMap::instance()->getAllKeys();
91 mRectAreaKeySequenceLineEdit = new KeySequenceLineEdit(this, allowedKeys, mPlatformChecker);
92 mLastRectAreaKeySequenceLineEdit = new KeySequenceLineEdit(this, allowedKeys, mPlatformChecker);
93 mFullScreenKeySequenceLineEdit = new KeySequenceLineEdit(this, allowedKeys, mPlatformChecker);
94 mCurrentScreenKeySequenceLineEdit = new KeySequenceLineEdit(this, allowedKeys, mPlatformChecker);
95 mActiveWindowKeySequenceLineEdit = new KeySequenceLineEdit(this, allowedKeys, mPlatformChecker);
96 mWindowUnderCursorKeySequenceLineEdit = new KeySequenceLineEdit(this, allowedKeys, mPlatformChecker);
97 mPortalKeySequenceLineEdit = new KeySequenceLineEdit(this, allowedKeys, mPlatformChecker);
98
99 mEnableGlobalHotKeysCheckBox->setText(tr("Enable Global HotKeys"));
100 mEnableGlobalHotKeysCheckBox->setToolTip(tr("HotKeys are currently supported only for Windows and X11.\n"
101 "Disabling this option makes also the action shortcuts ksnip only."));
102 connect(mEnableGlobalHotKeysCheckBox, &QCheckBox::stateChanged, this, &HotKeySettings::globalHotKeysStateChanged);
103
104 mRectAreaLabel->setText(tr("Capture Rect Area") + QLatin1String(":"));
105 mLastRectAreaLabel->setText(tr("Capture Last Rect Area") + QLatin1String(":"));
106 mFullScreenLabel->setText(tr("Capture Full Screen") + QLatin1String(":"));
107 mCurrentScreenLabel->setText(tr("Capture current Screen") + QLatin1String(":"));
108 mActiveWindowLabel->setText(tr("Capture active Window") + QLatin1String(":"));
109 mWindowUnderCursorLabel->setText(tr("Capture Window under Cursor") + QLatin1String(":"));
110 mPortalLabel->setText(tr("Capture using Portal") + QLatin1String(":"));
111
112 auto clearText = tr("Clear");
113 mRectAreaClearPushButton->setText(clearText);
114 connect(mRectAreaClearPushButton, &QPushButton::clicked, mRectAreaKeySequenceLineEdit, &KeySequenceLineEdit::clear);
115
116 mLastRectAreaClearPushButton->setText(clearText);
117 connect(mLastRectAreaClearPushButton, &QPushButton::clicked, mLastRectAreaKeySequenceLineEdit, &KeySequenceLineEdit::clear);
118
119 mFullScreenClearPushButton->setText(clearText);
120 connect(mFullScreenClearPushButton, &QPushButton::clicked, mFullScreenKeySequenceLineEdit, &KeySequenceLineEdit::clear);
121
122 mCurrentScreenClearPushButton->setText(clearText);
123 connect(mCurrentScreenClearPushButton, &QPushButton::clicked, mCurrentScreenKeySequenceLineEdit, &KeySequenceLineEdit::clear);
124
125 mActiveWindowClearPushButton->setText(clearText);
126 connect(mActiveWindowClearPushButton, &QPushButton::clicked, mActiveWindowKeySequenceLineEdit, &KeySequenceLineEdit::clear);
127
128 mWindowUnderCursorClearPushButton->setText(clearText);
129 connect(mWindowUnderCursorClearPushButton, &QPushButton::clicked, mWindowUnderCursorKeySequenceLineEdit, &KeySequenceLineEdit::clear);
130
131 mPortalClearPushButton->setText(clearText);
132 connect(mPortalClearPushButton, &QPushButton::clicked, mPortalKeySequenceLineEdit, &KeySequenceLineEdit::clear);
133
134 mLayout->setAlignment(Qt::AlignTop);
135 mLayout->setColumnStretch(1, 1);
136 mLayout->addWidget(mEnableGlobalHotKeysCheckBox, 0, 0, 1, 3);
137
138 mLayout->addWidget(mRectAreaLabel, 1, 0, 1, 1);
139 mLayout->addWidget(mRectAreaKeySequenceLineEdit, 1, 1, 1, 1);
140 mLayout->addWidget(mRectAreaClearPushButton, 1, 2, 1, 1);
141
142 mLayout->addWidget(mLastRectAreaLabel, 2, 0,1,1);
143 mLayout->addWidget(mLastRectAreaKeySequenceLineEdit, 2, 1, 1, 1);
144 mLayout->addWidget(mLastRectAreaClearPushButton, 2, 2, 1, 1);
145
146 mLayout->addWidget(mFullScreenLabel, 3, 0, 1, 1);
147 mLayout->addWidget(mFullScreenKeySequenceLineEdit, 3, 1, 1, 1);
148 mLayout->addWidget(mFullScreenClearPushButton, 3, 2, 1, 1);
149
150 mLayout->addWidget(mCurrentScreenLabel, 4, 0, 1, 1);
151 mLayout->addWidget(mCurrentScreenKeySequenceLineEdit, 4, 1, 1, 1);
152 mLayout->addWidget(mCurrentScreenClearPushButton, 4, 2, 1, 1);
153
154 mLayout->addWidget(mActiveWindowLabel, 5, 0, 1, 1);
155 mLayout->addWidget(mActiveWindowKeySequenceLineEdit, 5, 1, 1, 1);
156 mLayout->addWidget(mActiveWindowClearPushButton, 5, 2, 1, 1);
157
158 mLayout->addWidget(mWindowUnderCursorLabel, 6, 0, 1, 1);
159 mLayout->addWidget(mWindowUnderCursorKeySequenceLineEdit, 6, 1, 1, 1);
160 mLayout->addWidget(mWindowUnderCursorClearPushButton, 6, 2, 1, 1);
161
162 mLayout->addWidget(mPortalLabel, 7, 0, 1, 1);
163 mLayout->addWidget(mPortalKeySequenceLineEdit, 7, 1, 1, 1);
164 mLayout->addWidget(mPortalClearPushButton, 7, 2, 1, 1);
165
166 setTitle(tr("Global HotKeys"));
167 setLayout(mLayout);
168 }
169
170 void HotKeySettings::loadConfig()
171 {
172 mEnableGlobalHotKeysCheckBox->setChecked(mConfig->globalHotKeysEnabled());
173 mEnableGlobalHotKeysCheckBox->setEnabled(!mConfig->isGlobalHotKeysEnabledReadOnly());
174 mRectAreaKeySequenceLineEdit->setValue(mConfig->rectAreaHotKey());
175 mLastRectAreaKeySequenceLineEdit->setValue(mConfig->lastRectAreaHotKey());
176 mFullScreenKeySequenceLineEdit->setValue(mConfig->fullScreenHotKey());
177 mCurrentScreenKeySequenceLineEdit->setValue(mConfig->currentScreenHotKey());
178 mActiveWindowKeySequenceLineEdit->setValue(mConfig->activeWindowHotKey());
179 mWindowUnderCursorKeySequenceLineEdit->setValue(mConfig->windowUnderCursorHotKey());
180 mPortalKeySequenceLineEdit->setValue(mConfig->portalHotKey());
181 globalHotKeysStateChanged();
182 }
183
184 void HotKeySettings::globalHotKeysStateChanged()
185 {
186 auto hotKeysEnabled = mEnableGlobalHotKeysCheckBox->isChecked() && mEnableGlobalHotKeysCheckBox->isEnabled();
187 auto isRectAreaSupported = mCaptureModes.contains(CaptureModes::RectArea);
188 auto isLastRectAreaSupported = mCaptureModes.contains(CaptureModes::LastRectArea);
189 auto isFullScreenSupported = mCaptureModes.contains(CaptureModes::FullScreen);
190 auto isCurrentScreenSupported = mCaptureModes.contains(CaptureModes::CurrentScreen);
191 auto isActiveWindowSupported = mCaptureModes.contains(CaptureModes::ActiveWindow);
192 auto isWindowUnderCursorSupported = mCaptureModes.contains(CaptureModes::WindowUnderCursor);
193 auto isPortalSupported = mCaptureModes.contains(CaptureModes::Portal);
194
195 mRectAreaLabel->setEnabled(hotKeysEnabled && isRectAreaSupported);
196 mRectAreaKeySequenceLineEdit->setEnabled(hotKeysEnabled && isRectAreaSupported);
197 mRectAreaClearPushButton->setEnabled(hotKeysEnabled && isRectAreaSupported);
198
199 mLastRectAreaLabel->setEnabled(hotKeysEnabled && isLastRectAreaSupported);
200 mLastRectAreaKeySequenceLineEdit->setEnabled(hotKeysEnabled && isLastRectAreaSupported);
201 mLastRectAreaClearPushButton->setEnabled(hotKeysEnabled && isLastRectAreaSupported);
202
203 mFullScreenLabel->setEnabled(hotKeysEnabled && isFullScreenSupported);
204 mFullScreenKeySequenceLineEdit->setEnabled(hotKeysEnabled && isFullScreenSupported);
205 mFullScreenClearPushButton->setEnabled(hotKeysEnabled && isFullScreenSupported);
206
207 mCurrentScreenLabel->setEnabled(hotKeysEnabled && isCurrentScreenSupported);
208 mCurrentScreenKeySequenceLineEdit->setEnabled(hotKeysEnabled && isCurrentScreenSupported);
209 mCurrentScreenClearPushButton->setEnabled(hotKeysEnabled && isCurrentScreenSupported);
210
211 mActiveWindowLabel->setEnabled(hotKeysEnabled && isActiveWindowSupported);
212 mActiveWindowKeySequenceLineEdit->setEnabled(hotKeysEnabled && isActiveWindowSupported);
213 mActiveWindowClearPushButton->setEnabled(hotKeysEnabled && isActiveWindowSupported);
214
215 mWindowUnderCursorLabel->setEnabled(hotKeysEnabled && isWindowUnderCursorSupported);
216 mWindowUnderCursorKeySequenceLineEdit->setEnabled(hotKeysEnabled && isWindowUnderCursorSupported);
217 mWindowUnderCursorClearPushButton->setEnabled(hotKeysEnabled && isWindowUnderCursorSupported);
218
219 mPortalLabel->setEnabled(hotKeysEnabled && isPortalSupported);
220 mPortalKeySequenceLineEdit->setEnabled(hotKeysEnabled && isPortalSupported);
221 mPortalClearPushButton->setEnabled(hotKeysEnabled && isPortalSupported);
222 }