2014-12-03 08:39:06 +00:00
|
|
|
/* Copyright (c) 2013-2014 Jeffrey Pfau
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2014-11-07 11:11:44 +00:00
|
|
|
#include "KeyEditor.h"
|
|
|
|
|
|
|
|
#include <QKeyEvent>
|
|
|
|
|
|
|
|
using namespace QGBA;
|
|
|
|
|
|
|
|
KeyEditor::KeyEditor(QWidget* parent)
|
|
|
|
: QLineEdit(parent)
|
2014-12-03 08:07:56 +00:00
|
|
|
, m_numeric(false)
|
2014-11-07 11:11:44 +00:00
|
|
|
{
|
|
|
|
setAlignment(Qt::AlignCenter);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KeyEditor::setValue(int key) {
|
2014-12-03 08:07:56 +00:00
|
|
|
if (m_numeric) {
|
|
|
|
setText(QString::number(key));
|
|
|
|
} else {
|
|
|
|
setText(QKeySequence(key).toString(QKeySequence::NativeText));
|
|
|
|
}
|
2014-11-07 11:11:44 +00:00
|
|
|
m_key = key;
|
|
|
|
emit valueChanged(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize KeyEditor::sizeHint() const {
|
|
|
|
QSize hint = QLineEdit::sizeHint();
|
|
|
|
hint.setWidth(40);
|
|
|
|
return hint;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KeyEditor::keyPressEvent(QKeyEvent* event) {
|
2014-12-03 08:07:56 +00:00
|
|
|
if (!m_numeric) {
|
|
|
|
setValue(event->key());
|
|
|
|
}
|
2014-11-07 11:11:44 +00:00
|
|
|
event->accept();
|
|
|
|
}
|