src/widgets/extendedkeysequenceeditor.cpp

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

mercurial