src/platform/qt/KeyEditor.cpp (view raw)
1#include "KeyEditor.h"
2
3#include <QKeyEvent>
4
5using namespace QGBA;
6
7KeyEditor::KeyEditor(QWidget* parent)
8 : QLineEdit(parent)
9{
10 setAlignment(Qt::AlignCenter);
11}
12
13void KeyEditor::setValue(int key) {
14 setText(QKeySequence(key).toString(QKeySequence::NativeText));
15 m_key = key;
16 emit valueChanged(key);
17}
18
19QSize KeyEditor::sizeHint() const {
20 QSize hint = QLineEdit::sizeHint();
21 hint.setWidth(40);
22 return hint;
23}
24
25void KeyEditor::keyPressEvent(QKeyEvent* event) {
26 setValue(event->key());
27 event->accept();
28}