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 , m_numeric(false)
10{
11 setAlignment(Qt::AlignCenter);
12}
13
14void KeyEditor::setValue(int key) {
15 if (m_numeric) {
16 setText(QString::number(key));
17 } else {
18 setText(QKeySequence(key).toString(QKeySequence::NativeText));
19 }
20 m_key = key;
21 emit valueChanged(key);
22}
23
24QSize KeyEditor::sizeHint() const {
25 QSize hint = QLineEdit::sizeHint();
26 hint.setWidth(40);
27 return hint;
28}
29
30void KeyEditor::keyPressEvent(QKeyEvent* event) {
31 if (!m_numeric) {
32 setValue(event->key());
33 }
34 event->accept();
35}