Wed, 26 Dec 2018 23:01:45 +0200
reimplented shortcuts in the config dialog using model/view programming
1433
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
1 | /* |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
3 | * Copyright (C) 2013 - 2018 Teemu Piippo |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
4 | * |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
9 | * |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
14 | * |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
17 | */ |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
18 | |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
19 | #include <QKeySequenceEdit> |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
20 | #include <QPushButton> |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
21 | #include <QHBoxLayout> |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
22 | #include "extendedkeysequenceeditor.h" |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
23 | |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
24 | /* |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
25 | * Constructs a new extended key sequence editor. |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
26 | */ |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
27 | ExtendedKeySequenceEditor::ExtendedKeySequenceEditor( |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
28 | const QKeySequence& initialSequence, |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
29 | const QKeySequence& defaultSequence, |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
30 | QWidget* parent) : |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
31 | QWidget {parent}, |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
32 | defaultSequence {defaultSequence}, |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
33 | editor {new QKeySequenceEdit {initialSequence, this}}, |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
34 | clearButton {new QPushButton {"×", this}}, |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
35 | resetButton {new QPushButton {"↺", this}}, |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
36 | layout {new QHBoxLayout {this}} |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
37 | { |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
38 | layout->addWidget(editor, 1); |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
39 | layout->addWidget(clearButton, 0); |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
40 | layout->addWidget(resetButton, 0); |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
41 | layout->setContentsMargins({}); |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
42 | setLayout(layout); |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
43 | |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
44 | // Set up focus proxies so that the actual editing widget gets focused when focus |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
45 | // is applied to this widget. |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
46 | setFocusProxy(editor); |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
47 | clearButton->setFocusProxy(editor); |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
48 | resetButton->setFocusProxy(editor); |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
49 | |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
50 | connect(clearButton, &QPushButton::clicked, editor, &QKeySequenceEdit::clear); |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
51 | connect(resetButton, &QPushButton::clicked, [this]() |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
52 | { |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
53 | editor->setKeySequence(this->defaultSequence); |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
54 | }); |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
55 | } |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
56 | |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
57 | /* |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
58 | * Destroys an extended key sequence editor. |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
59 | */ |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
60 | ExtendedKeySequenceEditor::~ExtendedKeySequenceEditor() |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
61 | { |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
62 | delete editor; |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
63 | delete clearButton; |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
64 | delete resetButton; |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
65 | delete layout; |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
66 | } |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
67 | |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
68 | /* |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
69 | * Returns the current key sequence in the editor. |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
70 | */ |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
71 | QKeySequence ExtendedKeySequenceEditor::keySequence() const |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
72 | { |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
73 | return editor->keySequence(); |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
74 | } |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
75 | |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
76 | /* |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
77 | * Changes the key sequence in the editor. |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
78 | */ |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
79 | void ExtendedKeySequenceEditor::setKeySequence(const QKeySequence& newSequence) |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
80 | { |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
81 | editor->setKeySequence(newSequence); |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
82 | } |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
83 | |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
84 | /* |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
85 | * Clears the key sequence. |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
86 | */ |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
87 | void ExtendedKeySequenceEditor::clear() |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
88 | { |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
89 | editor->clear(); |
bd3a9e237ef5
reimplented shortcuts in the config dialog using model/view programming
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
90 | } |