diff options
Diffstat (limited to 'src/citra_qt/config/controller_config_util.cpp')
| -rw-r--r-- | src/citra_qt/config/controller_config_util.cpp | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/src/citra_qt/config/controller_config_util.cpp b/src/citra_qt/config/controller_config_util.cpp new file mode 100644 index 000000000..c5426570b --- /dev/null +++ b/src/citra_qt/config/controller_config_util.cpp | |||
| @@ -0,0 +1,121 @@ | |||
| 1 | #include <QPushButton> | ||
| 2 | #include <QStyle> | ||
| 3 | #include <QGridLayout> | ||
| 4 | #include <QKeyEvent> | ||
| 5 | #include <QHBoxLayout> | ||
| 6 | #include <QLabel> | ||
| 7 | |||
| 8 | #include "controller_config_util.hxx" | ||
| 9 | |||
| 10 | /* TODO(bunnei): ImplementMe | ||
| 11 | GStickConfig::GStickConfig(common::Config::Control leftid, common::Config::Control rightid, common::Config::Control upid, common::Config::Control downid, QObject* change_receiver, QWidget* parent) : QWidget(parent) | ||
| 12 | { | ||
| 13 | left = new GKeyConfigButton(leftid, style()->standardIcon(QStyle::SP_ArrowLeft), QString(), change_receiver, this); | ||
| 14 | right = new GKeyConfigButton(rightid, style()->standardIcon(QStyle::SP_ArrowRight), QString(), change_receiver, this); | ||
| 15 | up = new GKeyConfigButton(upid, style()->standardIcon(QStyle::SP_ArrowUp), QString(), change_receiver, this); | ||
| 16 | down = new GKeyConfigButton(downid, style()->standardIcon(QStyle::SP_ArrowDown), QString(), change_receiver, this); | ||
| 17 | clear = new QPushButton(tr("Clear"), this); | ||
| 18 | |||
| 19 | QGridLayout* layout = new QGridLayout(this); | ||
| 20 | layout->addWidget(left, 1, 0); | ||
| 21 | layout->addWidget(right, 1, 2); | ||
| 22 | layout->addWidget(up, 0, 1); | ||
| 23 | layout->addWidget(down, 2, 1); | ||
| 24 | layout->addWidget(clear, 1, 1); | ||
| 25 | |||
| 26 | setLayout(layout); | ||
| 27 | } | ||
| 28 | |||
| 29 | GKeyConfigButton::GKeyConfigButton(common::Config::Control id, const QIcon& icon, const QString& text, QObject* change_receiver, QWidget* parent) : QPushButton(icon, text, parent), id(id), inputGrabbed(false) | ||
| 30 | { | ||
| 31 | connect(this, SIGNAL(clicked()), this, SLOT(OnClicked())); | ||
| 32 | connect(this, SIGNAL(KeyAssigned(common::Config::Control, int, const QString&)), change_receiver, SLOT(OnKeyConfigChanged(common::Config::Control, int, const QString&))); | ||
| 33 | connect(change_receiver, SIGNAL(ActivePortChanged(const common::Config::ControllerPort&)), this, SLOT(OnActivePortChanged(const common::Config::ControllerPort&))); | ||
| 34 | } | ||
| 35 | |||
| 36 | GKeyConfigButton::GKeyConfigButton(common::Config::Control id, const QString& text, QObject* change_receiver, QWidget* parent) : QPushButton(text, parent), id(id), inputGrabbed(false) | ||
| 37 | { | ||
| 38 | connect(this, SIGNAL(clicked()), this, SLOT(OnClicked())); | ||
| 39 | connect(this, SIGNAL(KeyAssigned(common::Config::Control, int, const QString&)), change_receiver, SLOT(OnKeyConfigChanged(common::Config::Control, int, const QString&))); | ||
| 40 | connect(change_receiver, SIGNAL(ActivePortChanged(const common::Config::ControllerPort&)), this, SLOT(OnActivePortChanged(const common::Config::ControllerPort&))); | ||
| 41 | } | ||
| 42 | |||
| 43 | void GKeyConfigButton::OnActivePortChanged(const common::Config::ControllerPort& config) | ||
| 44 | { | ||
| 45 | // TODO: Doesn't use joypad struct if that's the input source... | ||
| 46 | QString text = QKeySequence(config.keys.key_code[id]).toString(); // has a nicer format | ||
| 47 | if (config.keys.key_code[id] == Qt::Key_Shift) text = tr("Shift"); | ||
| 48 | else if (config.keys.key_code[id] == Qt::Key_Control) text = tr("Control"); | ||
| 49 | else if (config.keys.key_code[id] == Qt::Key_Alt) text = tr("Alt"); | ||
| 50 | else if (config.keys.key_code[id] == Qt::Key_Meta) text = tr("Meta"); | ||
| 51 | setText(text); | ||
| 52 | } | ||
| 53 | |||
| 54 | void GKeyConfigButton::OnClicked() | ||
| 55 | { | ||
| 56 | grabKeyboard(); | ||
| 57 | grabMouse(); | ||
| 58 | inputGrabbed = true; | ||
| 59 | |||
| 60 | old_text = text(); | ||
| 61 | setText(tr("Input...")); | ||
| 62 | } | ||
| 63 | |||
| 64 | void GKeyConfigButton::keyPressEvent(QKeyEvent* event) | ||
| 65 | { | ||
| 66 | if (inputGrabbed) | ||
| 67 | { | ||
| 68 | releaseKeyboard(); | ||
| 69 | releaseMouse(); | ||
| 70 | setText(QString()); | ||
| 71 | |||
| 72 | // TODO: Doesn't capture "return" key | ||
| 73 | // TODO: This doesn't quite work well, yet... find a better way | ||
| 74 | QString text = QKeySequence(event->key()).toString(); // has a nicer format than event->text() | ||
| 75 | int key = event->key(); | ||
| 76 | if (event->modifiers() == Qt::ShiftModifier) { text = tr("Shift"); key = Qt::Key_Shift; } | ||
| 77 | else if (event->modifiers() == Qt::ControlModifier) { text = tr("Ctrl"); key = Qt::Key_Control; } | ||
| 78 | else if (event->modifiers() == Qt::AltModifier) { text = tr("Alt"); key = Qt::Key_Alt; } | ||
| 79 | else if (event->modifiers() == Qt::MetaModifier) { text = tr("Meta"); key = Qt::Key_Meta; } | ||
| 80 | |||
| 81 | setText(old_text); | ||
| 82 | emit KeyAssigned(id, key, text); | ||
| 83 | |||
| 84 | inputGrabbed = false; | ||
| 85 | |||
| 86 | // TODO: Keys like "return" cause another keyPressEvent to be generated after this one... | ||
| 87 | } | ||
| 88 | |||
| 89 | QPushButton::keyPressEvent(event); // TODO: Necessary? | ||
| 90 | } | ||
| 91 | |||
| 92 | void GKeyConfigButton::mousePressEvent(QMouseEvent* event) | ||
| 93 | { | ||
| 94 | // Abort key assignment | ||
| 95 | if (inputGrabbed) | ||
| 96 | { | ||
| 97 | releaseKeyboard(); | ||
| 98 | releaseMouse(); | ||
| 99 | setText(old_text); | ||
| 100 | inputGrabbed = false; | ||
| 101 | } | ||
| 102 | |||
| 103 | QAbstractButton::mousePressEvent(event); | ||
| 104 | } | ||
| 105 | |||
| 106 | GButtonConfigGroup::GButtonConfigGroup(const QString& name, common::Config::Control id, QObject* change_receiver, QWidget* parent) : QWidget(parent), id(id) | ||
| 107 | { | ||
| 108 | QHBoxLayout* layout = new QHBoxLayout(this); | ||
| 109 | |||
| 110 | QPushButton* clear_button = new QPushButton(tr("Clear")); | ||
| 111 | |||
| 112 | layout->addWidget(new QLabel(name, this)); | ||
| 113 | layout->addWidget(config_button = new GKeyConfigButton(id, QString(), change_receiver, this)); | ||
| 114 | layout->addWidget(clear_button); | ||
| 115 | |||
| 116 | // TODO: connect config_button, clear_button | ||
| 117 | |||
| 118 | setLayout(layout); | ||
| 119 | } | ||
| 120 | |||
| 121 | */ \ No newline at end of file | ||