2017-06-27 12:46:35 +02:00
|
|
|
#include "hotkeyinputdialog.hpp"
|
|
|
|
#include "ui_hotkeyinputdialog.h"
|
|
|
|
#include <QKeyEvent>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPushButton>
|
|
|
|
|
|
|
|
HotkeyInputDialog::HotkeyInputDialog(QString hotkeyName, QKeySequence currentSeq, QWidget *parent)
|
|
|
|
: QDialog(parent), ui(new Ui::HotkeyInputDialog) {
|
|
|
|
ui->setupUi(this);
|
|
|
|
ui->keySeq->setText(currentSeq.toString());
|
|
|
|
setWindowTitle(hotkeyName);
|
|
|
|
connect(this, &QDialog::accepted, [&] {
|
|
|
|
QKeySequence s(ui->keySeq->text());
|
2017-06-29 16:33:28 +02:00
|
|
|
if (ui->keySeq->text().isEmpty() || !s.toString().isEmpty()) emit sequenceSelected(s, windowTitle());
|
2017-06-27 12:46:35 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
HotkeyInputDialog::~HotkeyInputDialog() {
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HotkeyInputDialog::keyPressEvent(QKeyEvent *e) {
|
|
|
|
if (e->key() == Qt::Key_Shift || e->key() == Qt::Key_Control || e->key() == Qt::Key_Alt || e->key() == Qt::Key_AltGr
|
2017-07-23 16:56:28 +02:00
|
|
|
|| e->key() == Qt::Key_Context1 || e->key() == Qt::Key_Context2 || e->key() == Qt::Key_Context3
|
|
|
|
|| e->key() == Qt::Key_Context4 || e->key() == Qt::Key_Meta)
|
2017-06-27 12:46:35 +02:00
|
|
|
return;
|
|
|
|
if (recording) {
|
|
|
|
QKeySequence seq(e->modifiers() + e->key());
|
|
|
|
ui->keySeq->setText(seq.toString());
|
|
|
|
recording = false;
|
2017-07-29 17:22:17 +02:00
|
|
|
ui->recordButton->setText(tr("Record"));
|
2017-06-27 12:46:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HotkeyInputDialog::on_recordButton_clicked() {
|
|
|
|
recording = !recording;
|
2017-07-29 17:22:17 +02:00
|
|
|
ui->recordButton->setText(recording ? tr("Stop recording") : tr("Record"));
|
2017-11-23 20:33:49 +01:00
|
|
|
if (recording)
|
|
|
|
grabKeyboard();
|
|
|
|
else
|
|
|
|
releaseKeyboard();
|
2017-06-27 12:46:35 +02:00
|
|
|
}
|