Browse Source

Better hotkey input

tags/v5.0.0
ArsenArsen 5 years ago
parent
commit
67c8f5c5cf
  1. 9
      KShare.pro
  2. 37
      hotkeyinputdialog.cpp
  3. 31
      hotkeyinputdialog.hpp
  4. 74
      hotkeyinputdialog.ui
  5. 2
      main.cpp
  6. 9
      settingsdialog.cpp

9
KShare.pro

@ -62,7 +62,8 @@ SOURCES += main.cpp\
aboutbox.cpp \
cropeditor/drawing/eraseritem.cpp \
cropeditor/drawing/rectitem.cpp \
cropeditor/drawing/ellipseitem.cpp
cropeditor/drawing/ellipseitem.cpp \
hotkeyinputdialog.cpp
HEADERS += mainwindow.hpp \
cropeditor/cropeditor.hpp \
@ -103,7 +104,8 @@ HEADERS += mainwindow.hpp \
aboutbox.hpp \
cropeditor/drawing/eraseritem.hpp \
cropeditor/drawing/rectitem.hpp \
cropeditor/drawing/ellipseitem.hpp
cropeditor/drawing/ellipseitem.hpp \
hotkeyinputdialog.hpp
LIBS += -lavcodec -lavformat -lavutil -lswscale -lavutil
@ -131,7 +133,8 @@ FORMS += mainwindow.ui \
cropeditor/settings/blurdialog.ui \
recording/encoders/encodersettingsdialog.ui \
settingsdialog.ui \
aboutbox.ui
aboutbox.ui \
hotkeyinputdialog.ui
DISTFILES += \
README.md \

37
hotkeyinputdialog.cpp

@ -0,0 +1,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 (!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");
}

31
hotkeyinputdialog.hpp

@ -0,0 +1,31 @@
#ifndef HOTKEYINPUTDIALOG_HPP
#define HOTKEYINPUTDIALOG_HPP
#include <QDialog>
namespace Ui {
class HotkeyInputDialog;
}
class HotkeyInputDialog : public QDialog {
Q_OBJECT
public:
explicit HotkeyInputDialog(QString hotkeyName, QKeySequence currentSeq, QWidget *parent = 0);
~HotkeyInputDialog();
signals:
void sequenceSelected(QKeySequence seq, QString name);
protected:
void keyPressEvent(QKeyEvent *e) override;
private slots:
void on_recordButton_clicked();
private:
bool recording = false;
Ui::HotkeyInputDialog *ui;
};
#endif // HOTKEYINPUTDIALOG_HPP

74
hotkeyinputdialog.ui

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>HotkeyInputDialog</class>
<widget class="QDialog" name="HotkeyInputDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>255</width>
<height>80</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLineEdit" name="keySeq"/>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="recordButton">
<property name="text">
<string>Record</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>HotkeyInputDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>HotkeyInputDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

2
main.cpp

@ -1,5 +1,6 @@
#include "mainwindow.hpp"
#include "screenshotutil.hpp"
#include "ui_mainwindow.h"
#include <QApplication>
#include <QCommandLineParser>
#include <QDebug>
@ -11,7 +12,6 @@ extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
}
#include "ui_mainwindow.h"
#include <QListWidget>
#include <notifications.hpp>
#include <platformbackend.hpp>

9
settingsdialog.cpp

@ -1,4 +1,5 @@
#include "settingsdialog.hpp"
#include "hotkeyinputdialog.hpp"
#include "mainwindow.hpp"
#include "ui_settingsdialog.h"
@ -111,10 +112,10 @@ void SettingsDialog::on_hotkeys_doubleClicked(const QModelIndex &) {
if (ui->hotkeys->selectedItems().length() == 1) {
QListWidgetItem *i = ui->hotkeys->selectedItems().at(0);
QString str = i->data(Qt::UserRole + 1).toString();
bool ok;
QString seq = QInputDialog::getText(MainWindow::inst(), "Hotkey Input", "Insert hotkey:", QLineEdit::Normal,
hotkeying::sequence(str), &ok);
if (ok && hotkeying::valid(seq)) hotkeying::hotkey(str, QKeySequence(seq), fncs.value(str));
HotkeyInputDialog *hotkey = new HotkeyInputDialog(str, hotkeying::sequence(str), this);
connect(hotkey, &HotkeyInputDialog::sequenceSelected,
[&](QKeySequence seq, QString name) { hotkeying::hotkey(name, seq, fncs.value(name)); });
hotkey->show();
}
}

Loading…
Cancel
Save