Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 83baef4

Browse files
committed
fix shortcut input
1 parent b088e41 commit 83baef4

File tree

8 files changed

+101
-63
lines changed

8 files changed

+101
-63
lines changed

stuff/config/qss/Blue/Blue.qss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,17 @@ QDialog #dialogButtonFrame QPushButton:focus:pressed {
16691669
width: 16;
16701670
margin-right: -1;
16711671
}
1672+
#ShortcutViewer {
1673+
font-size: 17px;
1674+
}
1675+
#ShortcutViewer QLineEdit {
1676+
color: black;
1677+
border-color: #b8bc7f;
1678+
background-color: white;
1679+
}
1680+
#ShortcutViewer QLineEdit:focus {
1681+
background-color: #abceff;
1682+
}
16721683
/* -----------------------------------------------------------------------------
16731684
New Project / Configure Project Window
16741685
----------------------------------------------------------------------------- */

stuff/config/qss/Dark/Dark.qss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,17 @@ QDialog #dialogButtonFrame QPushButton:focus:pressed {
16691669
width: 16;
16701670
margin-right: -1;
16711671
}
1672+
#ShortcutViewer {
1673+
font-size: 17px;
1674+
}
1675+
#ShortcutViewer QLineEdit {
1676+
color: black;
1677+
border-color: #b8bc7f;
1678+
background-color: white;
1679+
}
1680+
#ShortcutViewer QLineEdit:focus {
1681+
background-color: #abceff;
1682+
}
16721683
/* -----------------------------------------------------------------------------
16731684
New Project / Configure Project Window
16741685
----------------------------------------------------------------------------- */

stuff/config/qss/Default/Default.qss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,17 @@ QDialog #dialogButtonFrame QPushButton:focus:pressed {
16691669
width: 16;
16701670
margin-right: -1;
16711671
}
1672+
#ShortcutViewer {
1673+
font-size: 17px;
1674+
}
1675+
#ShortcutViewer QLineEdit {
1676+
color: black;
1677+
border-color: #b8bc7f;
1678+
background-color: white;
1679+
}
1680+
#ShortcutViewer QLineEdit:focus {
1681+
background-color: #abceff;
1682+
}
16721683
/* -----------------------------------------------------------------------------
16731684
New Project / Configure Project Window
16741685
----------------------------------------------------------------------------- */

stuff/config/qss/Default/less/layouts/popups.less

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ QDialog {
7777
}
7878
}
7979

80+
#ShortcutViewer {
81+
font-size: 17px;
82+
& QLineEdit{
83+
color:black;
84+
border-color: rgb(184, 188, 127);
85+
background-color: white;
86+
&:focus{
87+
background-color: rgb(171, 206, 255);
88+
}
89+
}
90+
}
91+
8092
/* -----------------------------------------------------------------------------
8193
New Project / Configure Project Window
8294
----------------------------------------------------------------------------- */

stuff/config/qss/Light/Light.qss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,17 @@ QDialog #dialogButtonFrame QPushButton:focus:pressed {
16691669
width: 16;
16701670
margin-right: -1;
16711671
}
1672+
#ShortcutViewer {
1673+
font-size: 17px;
1674+
}
1675+
#ShortcutViewer QLineEdit {
1676+
color: black;
1677+
border-color: #b8bc7f;
1678+
background-color: white;
1679+
}
1680+
#ShortcutViewer QLineEdit:focus {
1681+
background-color: #abceff;
1682+
}
16721683
/* -----------------------------------------------------------------------------
16731684
New Project / Configure Project Window
16741685
----------------------------------------------------------------------------- */

stuff/config/qss/Neutral/Neutral.qss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,17 @@ QDialog #dialogButtonFrame QPushButton:focus:pressed {
16691669
width: 16;
16701670
margin-right: -1;
16711671
}
1672+
#ShortcutViewer {
1673+
font-size: 17px;
1674+
}
1675+
#ShortcutViewer QLineEdit {
1676+
color: black;
1677+
border-color: #b8bc7f;
1678+
background-color: white;
1679+
}
1680+
#ShortcutViewer QLineEdit:focus {
1681+
background-color: #abceff;
1682+
}
16721683
/* -----------------------------------------------------------------------------
16731684
New Project / Configure Project Window
16741685
----------------------------------------------------------------------------- */

toonz/sources/toonz/shortcutpopup.cpp

Lines changed: 30 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,11 @@ class ShortcutItem final : public QTreeWidgetItem {
7272
// ShortcutViewer
7373
//-----------------------------------------------------------------------------
7474

75-
ShortcutViewer::ShortcutViewer(QWidget *parent) : QWidget(parent), m_action(0) {
75+
ShortcutViewer::ShortcutViewer(QWidget *parent)
76+
: QKeySequenceEdit(parent), m_action(0) {
77+
setObjectName("ShortcutViewer");
7678
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
79+
connect(this, SIGNAL(editingFinished()), this, SLOT(onEditingFinished()));
7780
}
7881

7982
//-----------------------------------------------------------------------------
@@ -82,95 +85,64 @@ ShortcutViewer::~ShortcutViewer() {}
8285

8386
//-----------------------------------------------------------------------------
8487

85-
void ShortcutViewer::paintEvent(QPaintEvent *) {
86-
QPainter p(this);
87-
// sfondo azzurro se il widget ha il focus (e quindi si accorge dei tasti
88-
// premuti)
89-
p.fillRect(1, 1, width() - 1, height() - 1,
90-
QBrush(hasFocus() ? QColor(171, 206, 255) : Qt::white));
91-
// bordo
92-
p.setPen(QColor(184, 188, 127));
93-
p.drawRect(0, 0, width() - 1, height() - 1);
94-
if (m_action) {
95-
// lo shortcut corrente
96-
p.setPen(Qt::black);
97-
p.drawText(10, 13, m_action->shortcut().toString());
98-
}
99-
}
100-
101-
//-----------------------------------------------------------------------------
102-
10388
void ShortcutViewer::setAction(QAction *action) {
10489
m_action = action;
105-
update();
90+
setKeySequence(m_action->shortcut());
10691
setFocus();
10792
}
10893

10994
//-----------------------------------------------------------------------------
11095

111-
bool ShortcutViewer::event(QEvent *event) {
112-
// quando si vuole assegnare una combinazione che gia' assegnata bisogna
113-
// evitare che lo shortcut relativo agisca.
114-
if (event->type() == QEvent::ShortcutOverride) {
115-
event->accept();
116-
return true;
117-
} else
118-
return QWidget::event(event);
119-
}
120-
121-
//-----------------------------------------------------------------------------
122-
12396
void ShortcutViewer::keyPressEvent(QKeyEvent *event) {
124-
int key = event->key();
125-
if (key == Qt::Key_Control || key == Qt::Key_Shift || key == Qt::Key_Alt) {
126-
event->ignore();
127-
return;
128-
}
97+
int key = event->key();
12998
Qt::KeyboardModifiers modifiers = event->modifiers();
130-
131-
// Tasti che non possono essere utilizzati come shortcut
132-
if ((modifiers | (Qt::CTRL | Qt::SHIFT | Qt::ALT)) !=
133-
(Qt::CTRL | Qt::SHIFT | Qt::ALT) ||
134-
key == Qt::Key_Home || key == Qt::Key_End || key == Qt::Key_PageDown ||
99+
if (key == Qt::Key_Home || key == Qt::Key_End || key == Qt::Key_PageDown ||
135100
key == Qt::Key_PageUp || key == Qt::Key_Escape || key == Qt::Key_Print ||
136101
key == Qt::Key_Pause || key == Qt::Key_ScrollLock) {
137-
if (key != Qt::Key_Plus && key != Qt::Key_Minus &&
138-
key != Qt::Key_Asterisk && key != Qt::Key_Slash) {
139-
event->ignore();
140-
return;
141-
} else
142-
modifiers = 0;
102+
event->ignore();
103+
return;
143104
}
144-
145105
// If "Use Numpad and Tab keys for Switching Styles" option is activated,
146106
// then prevent to assign such keys
147107
if (Preferences::instance()->isUseNumpadForSwitchingStylesEnabled() &&
148108
modifiers == 0 && (key >= Qt::Key_0 && key <= Qt::Key_9)) {
149109
event->ignore();
150110
return;
151111
}
112+
QKeySequenceEdit::keyPressEvent(event);
113+
}
114+
115+
//-----------------------------------------------------------------------------
116+
117+
void ShortcutViewer::onEditingFinished() {
118+
// limit to one shortcut key input
119+
QKeySequence keys = (keySequence().isEmpty())
120+
? QKeySequence()
121+
: QKeySequence(keySequence()[0]);
152122

153123
if (m_action) {
154-
CommandManager *cm = CommandManager::instance();
155-
QKeySequence keySequence(key + modifiers);
156-
std::string shortcutString = keySequence.toString().toStdString();
124+
CommandManager *cm = CommandManager::instance();
125+
std::string shortcutString = keys.toString().toStdString();
157126
QAction *oldAction =
158-
cm->getActionFromShortcut(keySequence.toString().toStdString());
127+
cm->getActionFromShortcut(keys.toString().toStdString());
159128
if (oldAction == m_action) return;
160129
if (oldAction) {
161130
QString msg = tr("%1 is already assigned to '%2'\nAssign to '%3'?")
162-
.arg(keySequence.toString())
131+
.arg(keys.toString())
163132
.arg(oldAction->iconText())
164133
.arg(m_action->iconText());
165134
int ret = DVGui::MsgBox(msg, tr("Yes"), tr("No"), 1);
166135
activateWindow();
167-
if (ret == 2 || ret == 0) return;
136+
if (ret == 2 || ret == 0) {
137+
setKeySequence(m_action->shortcut());
138+
setFocus();
139+
return;
140+
}
168141
}
169142
CommandManager::instance()->setShortcut(m_action, shortcutString);
170143
emit shortcutChanged();
171144
}
172-
event->accept();
173-
update();
145+
setKeySequence(keys);
174146
}
175147

176148
//-----------------------------------------------------------------------------
@@ -179,7 +151,7 @@ void ShortcutViewer::removeShortcut() {
179151
if (m_action) {
180152
CommandManager::instance()->setShortcut(m_action, "", false);
181153
emit shortcutChanged();
182-
update();
154+
clear();
183155
}
184156
}
185157

toonz/sources/toonz/shortcutpopup.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <QDialog>
77
#include <QTreeWidget>
88
#include <QComboBox>
9+
#include <QKeySequenceEdit>
910
#include "filebrowserpopup.h"
1011
#include "toonzqt/dvdialog.h"
1112

@@ -22,7 +23,7 @@ class ShortcutItem;
2223
// Per cancellarlo bisogna chiamare removeShortcut()
2324
//-----------------------------------------------------------------------------
2425

25-
class ShortcutViewer final : public QWidget {
26+
class ShortcutViewer final : public QKeySequenceEdit {
2627
Q_OBJECT
2728
QAction *m_action;
2829

@@ -31,15 +32,13 @@ class ShortcutViewer final : public QWidget {
3132
~ShortcutViewer();
3233

3334
protected:
34-
void paintEvent(QPaintEvent *) override;
35-
bool event(QEvent *event) override;
36-
void keyPressEvent(QKeyEvent *event) override;
3735
void enterEvent(QEvent *event) override;
3836
void leaveEvent(QEvent *event) override;
39-
37+
void keyPressEvent(QKeyEvent *event) override;
4038
public slots:
4139
void setAction(QAction *action);
4240
void removeShortcut();
41+
void onEditingFinished();
4342

4443
signals:
4544
void shortcutChanged();

0 commit comments

Comments
 (0)