Skip to content

Commit ae91c52

Browse files
Remove + as trigger to change hotkey
1 parent 40048d1 commit ae91c52

File tree

4 files changed

+50
-62
lines changed

4 files changed

+50
-62
lines changed

src/GUI/ActionHotkeyWidget.cpp

Lines changed: 42 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,61 @@
11
#include <QVBoxLayout>
22
#include <QKeyEvent>
33
#include <QDebug>
4+
#include <QStyle>
45
#include "ActionHotkeyWidget.hpp"
56
#include "ImageManager.hpp"
67

78
ActionHotkeyWidget::ActionHotkeyWidget(const QString& actionName,
8-
const QString& hotkeyStr,
9+
const QString& key,
910
const QString& iconName,
1011
QWidget* parent)
1112
: QWidget{parent}
12-
, hotkey{hotkeyStr}
13+
, hotkey{key}
1314
, actionNameLabel{actionName}
14-
, hotkeyLabel{hotkey}
15-
, newHotkeyButton{"+"}
15+
, btnHotkey{hotkey}
1616
, signalTimer{}
1717
, timerMseconds{1300}
1818
{
1919
// Object name for css
20-
hotkeyLabel.setObjectName("HotkeyLabel");
21-
hotkeyLabel.setEnabled(false);
22-
hotkeyLabel.setMinimumSize(ImageManager::DecodeMissingWebpIcon().size().width() + 15, // Checked for letter W
23-
ImageManager::DecodeMissingWebpIcon().size().height());
20+
btnHotkey.setObjectName("btnHotkey");
21+
btnHotkey.setProperty("unique", false);
22+
btnHotkey.setMinimumSize(ImageManager::DecodeMissingWebpIcon().size().width() + 15, // Checked for letter W
23+
ImageManager::DecodeMissingWebpIcon().size().height());
2424

25-
connect(&newHotkeyButton, &QPushButton::pressed, this, &ActionHotkeyWidget::OnNewHotkeyPressed);
25+
connect(&btnHotkey, &QPushButton::pressed, this, &ActionHotkeyWidget::ChangeHotkeyClick);
2626

2727
// Signal timer settings
2828
signalTimer.setSingleShot(true);
2929
connect(&signalTimer, &QTimer::timeout, this, &ActionHotkeyWidget::SignalRepeatNewHotkey);
3030

31-
QLabel* imageLb = new QLabel();
32-
imageLb->setPixmap(QPixmap::fromImage(ImageManager::DecodeWebpIcon(iconName)));
33-
34-
// Hotkey label
35-
hotkeyLabel.setAlignment(Qt::AlignCenter);
36-
37-
// TODO: doesn't work
38-
hotkeyLabel.setWindowOpacity(0.7);
39-
40-
// Square button size
41-
newHotkeyButton.setFixedSize(newHotkeyButton.sizeHint().height(), newHotkeyButton.sizeHint().height());
31+
QLabel* lblImage = new QLabel();
32+
lblImage->setPixmap(QPixmap::fromImage(ImageManager::DecodeWebpIcon(iconName)));
4233

4334
QHBoxLayout* ltMainBlock = new QHBoxLayout{this};
4435
ltMainBlock->setAlignment(Qt::AlignTop);
45-
ltMainBlock->addWidget(imageLb);
36+
ltMainBlock->addWidget(lblImage);
4637
ltMainBlock->addWidget(&actionNameLabel);
4738
// Move action name label to left
4839
ltMainBlock->setStretch(1, 1);
49-
ltMainBlock->addWidget(&hotkeyLabel);
50-
ltMainBlock->addWidget(&newHotkeyButton);
40+
ltMainBlock->addWidget(&btnHotkey);
5141
setLayout(ltMainBlock);
5242
}
5343

54-
QString ActionHotkeyWidget::GetActionName() const
55-
{
56-
return actionNameLabel.text();
57-
}
44+
QString ActionHotkeyWidget::GetActionName() const { return actionNameLabel.text(); }
5845

59-
QString ActionHotkeyWidget::GetHotkey() const
60-
{
61-
return hotkeyLabel.text();
62-
}
46+
QString ActionHotkeyWidget::GetHotkey() const { return btnHotkey.text(); }
6347

64-
void ActionHotkeyWidget::HighlightKey(bool collision)
48+
void ActionHotkeyWidget::HighlightKey(bool isKeysMoreThanTwo)
6549
{
66-
if (collision)
67-
hotkeyLabel.setEnabled(true);
50+
if (isKeysMoreThanTwo)
51+
btnHotkey.setProperty("unique", false);
6852
else
69-
hotkeyLabel.setDisabled(true);
53+
btnHotkey.setProperty("unique", true);
54+
55+
btnHotkey.style()->unpolish(&btnHotkey);
56+
btnHotkey.style()->polish(&btnHotkey);
57+
58+
btnHotkey.update();
7059
}
7160

7261
void ActionHotkeyWidget::keyPressEvent(QKeyEvent* event)
@@ -83,61 +72,61 @@ void ActionHotkeyWidget::keyPressEvent(QKeyEvent* event)
8372
{
8473
// Set new text
8574
hotkey = QKeySequence(key).toString();
86-
hotkeyLabel.setEnabled(false);
8775

8876
// If the key is correct -> disconnect the input error reset signal
89-
disconnect(this, &ActionHotkeyWidget::SignalRepeatNewHotkey, this, &ActionHotkeyWidget::OnNewHotkeyPressed);
77+
disconnect(this, &ActionHotkeyWidget::SignalRepeatNewHotkey, this, &ActionHotkeyWidget::ChangeHotkeyClick);
9078

9179
// Return focus to parent
9280
parentWidget()->setFocus();
9381
}
9482
else
9583
{
96-
if (KEYBOARD_KEYS.contains(key))
97-
hotkeyLabel.setText(tr("This key doesn't allowed!"));
84+
if (!KEYBOARD_KEYS.contains(key))
85+
btnHotkey.setText(tr("It isn't latin key!"));
9886
else
99-
hotkeyLabel.setText(tr("It isn't latin key!"));
87+
btnHotkey.setText(tr("This key doesn't allowed!"));
10088

10189
// Start the signal timer with a delay of n seconds
10290
if (signalTimer.isActive())
10391
signalTimer.stop();
10492

10593
signalTimer.start(timerMseconds);
106-
hotkeyLabel.setEnabled(true);
10794
}
95+
96+
btnHotkey.setProperty("unique", true);
10897
QWidget::keyPressEvent(event);
10998
}
11099

111100
void ActionHotkeyWidget::focusOutEvent(QFocusEvent* event)
112101
{
113102
// Unset decoration
114-
QFont fnt(hotkeyLabel.font());
103+
QFont fnt(btnHotkey.font());
115104
fnt.setItalic(false);
116-
hotkeyLabel.setFont(fnt);
117-
hotkeyLabel.setText(hotkey);
105+
btnHotkey.setFont(fnt);
106+
btnHotkey.setText(hotkey);
118107

119108
emit HotkeyChanged(hotkey);
120-
if (!hotkeyLabel.isEnabled())
121-
hotkeyLabel.setEnabled(false);
109+
if (btnHotkey.property("unique").Bool)
110+
btnHotkey.setProperty("unique", false);
122111

123112
// Stop timer
124113
signalTimer.stop();
125114

126115
QWidget::focusOutEvent(event);
127116
}
128117

129-
void ActionHotkeyWidget::OnNewHotkeyPressed()
118+
void ActionHotkeyWidget::ChangeHotkeyClick()
130119
{
131120
// Reconnect the input error reset signal
132-
disconnect(this, &ActionHotkeyWidget::SignalRepeatNewHotkey, this, &ActionHotkeyWidget::OnNewHotkeyPressed);
133-
connect(this, &ActionHotkeyWidget::SignalRepeatNewHotkey, this, &ActionHotkeyWidget::OnNewHotkeyPressed);
121+
disconnect(this, &ActionHotkeyWidget::SignalRepeatNewHotkey, this, &ActionHotkeyWidget::ChangeHotkeyClick);
122+
connect(this, &ActionHotkeyWidget::SignalRepeatNewHotkey, this, &ActionHotkeyWidget::ChangeHotkeyClick);
134123

135124
// Decorate
136-
hotkeyLabel.setText(tr("Press latin key..."));
137-
hotkeyLabel.setEnabled(false);
138-
QFont f(hotkeyLabel.font());
125+
btnHotkey.setText(tr("Press latin key..."));
126+
btnHotkey.setProperty("unique", true);
127+
QFont f(btnHotkey.font());
139128
f.setItalic(true);
140-
hotkeyLabel.setFont(f);
129+
btnHotkey.setFont(f);
141130

142131
// Set focus on hotkey element
143132
setFocus();

src/GUI/ActionHotkeyWidget.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ class ActionHotkeyWidget : public QWidget
1010
private: // Data
1111
QString hotkey;
1212
QLabel actionNameLabel;
13-
QLabel hotkeyLabel;
13+
QPushButton btnHotkey;
1414
QLabel image;
15-
QPushButton newHotkeyButton;
1615
QTimer signalTimer;
1716
int timerMseconds;
1817

@@ -26,11 +25,11 @@ class ActionHotkeyWidget : public QWidget
2625
QWidget* parent = nullptr);
2726
QString GetActionName() const;
2827
QString GetHotkey() const;
29-
void HighlightKey(bool collision);
28+
void HighlightKey(bool isKeysLessThanTwo);
3029

3130
signals:
3231
void SignalRepeatNewHotkey();
3332
void HotkeyChanged(QString hotkey);
3433
private slots:
35-
void OnNewHotkeyPressed();
34+
void ChangeHotkeyClick();
3635
};

src/GUI/Theme/Styles.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,15 +288,15 @@ QDialog QLabel#right
288288
border: none;
289289
} */
290290

291-
QLabel#HotkeyLabel:disabled
291+
QPushButton[unique="true"]#btnHotkey
292292
{
293293
font-weight: bold;
294294
padding-left: 30px;
295295
padding-right: 30px;
296296
background-color: #128d2d;
297297
}
298298

299-
QLabel#HotkeyLabel:enabled
299+
QPushButton[unique="false"]#btnHotkey
300300
{
301301
font-weight: bold;
302302
padding-left: 30px;

src/GUI/Translations/ru.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
<translation type="vanished">Это не латинская клавиша!</translation>
99
</message>
1010
<message>
11-
<location filename="../ActionHotkeyWidget.cpp" line="97"/>
11+
<location filename="../ActionHotkeyWidget.cpp" line="87"/>
1212
<source>This key doesn&apos;t allowed!</source>
1313
<translation>Эта клавиша не разрешена!</translation>
1414
</message>
1515
<message>
16-
<location filename="../ActionHotkeyWidget.cpp" line="99"/>
16+
<location filename="../ActionHotkeyWidget.cpp" line="85"/>
1717
<source>It isn&apos;t latin key!</source>
1818
<translation>Эта не латинская клавиша!</translation>
1919
</message>
2020
<message>
21-
<location filename="../ActionHotkeyWidget.cpp" line="136"/>
21+
<location filename="../ActionHotkeyWidget.cpp" line="125"/>
2222
<source>Press latin key...</source>
2323
<translation>Нажмите латинскую клавишу...</translation>
2424
</message>

0 commit comments

Comments
 (0)