all repos — mgba @ 1c1fbfe163964cb9a6744b134bda71464dd232f4

mGBA Game Boy Advance Emulator

src/platform/qt/KeyEditor.cpp (view raw)

 1/* Copyright (c) 2013-2014 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6#include "KeyEditor.h"
 7
 8#include <QKeyEvent>
 9
10using namespace QGBA;
11
12KeyEditor::KeyEditor(QWidget* parent)
13	: QLineEdit(parent)
14	, m_numeric(false)
15{
16	setAlignment(Qt::AlignCenter);
17}
18
19void KeyEditor::setValue(int key) {
20	if (m_numeric) {
21		setText(QString::number(key));
22	} else {
23		setText(QKeySequence(key).toString(QKeySequence::NativeText));
24	}
25	m_key = key;
26	emit valueChanged(key);
27}
28
29QSize KeyEditor::sizeHint() const {
30	QSize hint = QLineEdit::sizeHint();
31	hint.setWidth(40);
32	return hint;
33}
34
35void KeyEditor::keyPressEvent(QKeyEvent* event) {
36	if (!m_numeric) {
37		setValue(event->key());
38	}
39	event->accept();
40}