forked from ArsenArsen/KShare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hotkeyinputdialog.cpp
37 lines (33 loc) · 1.31 KB
/
hotkeyinputdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#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());
if (ui->keySeq->text().isEmpty() || !s.toString().isEmpty()) emit sequenceSelected(s, windowTitle());
});
}
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
|| e->key() == Qt::Key_Context1 || e->key() == Qt::Key_Context2 || e->key() == Qt::Key_Context3 || e->key() == Qt::Key_Context4)
return;
if (recording) {
QKeySequence seq(e->modifiers() + e->key());
ui->keySeq->setText(seq.toString());
recording = false;
ui->recordButton->setText("Record");
}
}
void HotkeyInputDialog::on_recordButton_clicked() {
recording = !recording;
ui->recordButton->setText(recording ? "Stop recording" : "Record");
}