diff --git a/MacroBinds.pro b/MacroBinds.pro index 5718156..bd9d41d 100644 --- a/MacroBinds.pro +++ b/MacroBinds.pro @@ -17,6 +17,7 @@ SOURCES += \ Widgets/qprocesslistitem.cpp \ Widgets/qratiobutton.cpp \ WindowFinder/windowfinder.cpp \ + keystrokeeditorwindow.cpp \ main.cpp \ qmacrobindswindow.cpp \ qmacrokeysmanager.cpp \ @@ -32,12 +33,14 @@ HEADERS += \ Widgets/qratiobutton.h \ WindowFinder/win32/windowfinderkeymap.h \ WindowFinder/windowfinder.h \ + keystrokeeditorwindow.h \ qmacrobindswindow.h \ qmacrokeysmanager.h \ windowfinderdialogue.h FORMS += \ Widgets/applicationinfowidget.ui \ + keystrokeeditorwindow.ui \ qmacrobindswindow.ui \ windowfinderdialogue.ui diff --git a/Widgets/qdialbutton.h b/Widgets/qdialbutton.h index ecd8d8c..55729ab 100644 --- a/Widgets/qdialbutton.h +++ b/Widgets/qdialbutton.h @@ -10,6 +10,8 @@ class QDialButton : public QRatioButton public: QDialButton(const quint8 &row, const quint8 &column, QWidget *parent = nullptr); + + virtual Type type() const override { return QRatioButton::Type::DIAL; } }; #endif // QDIALBUTTON_H diff --git a/Widgets/qmacrobutton.h b/Widgets/qmacrobutton.h index 83735a6..ddcb460 100644 --- a/Widgets/qmacrobutton.h +++ b/Widgets/qmacrobutton.h @@ -10,6 +10,8 @@ class QMacroButton : public QRatioButton public: QMacroButton(const quint8 &row, const quint8 &column, QWidget *parent = nullptr); + + virtual Type type() const override { return QRatioButton::Type::PUSH_BUTTON; } }; #endif // QMACROBUTTON_H diff --git a/Widgets/qratiobutton.h b/Widgets/qratiobutton.h index 74d08cf..c2ddead 100644 --- a/Widgets/qratiobutton.h +++ b/Widgets/qratiobutton.h @@ -8,10 +8,18 @@ class QRatioButton : public QPushButton Q_OBJECT public: + enum class Type : quint8 { + INVALID, + PUSH_BUTTON, + DIAL + }; + QRatioButton(const quint8 &row, const quint8 &column, QWidget *parent = nullptr); virtual int heightForWidth(int w) const; + virtual Type type() const { return Type::INVALID; } + private: void onButtonPressSignal(); diff --git a/keystrokeeditorwindow.cpp b/keystrokeeditorwindow.cpp new file mode 100644 index 0000000..54da754 --- /dev/null +++ b/keystrokeeditorwindow.cpp @@ -0,0 +1,77 @@ +#include "keystrokeeditorwindow.h" +#include "ui_keystrokeeditorwindow.h" + +#include "QtImprovements/qsettingsplus.h" + +KeystrokeEditorWindow::KeystrokeEditorWindow(const quint8 &row, const quint8 &column, const bool &dial, QWidget *parent) + : QDialog(parent) + , ui(new Ui::KeystrokeEditorWindow) + , row(row) + , column(column) +{ + ui->setupUi(this); + + if (!dial) { + ui->labelRotateLeft->setVisible(false); + ui->kseRotateLeft->setVisible(false); + ui->kseRotateLeft->setEnabled(false); + ui->labelRotateRight->setVisible(false); + ui->kseRotateRight->setVisible(false); + ui->kseRotateRight->setEnabled(false); + } else { + ui->kseRotateLeft->setEnabled(true); + ui->kseRotateRight->setEnabled(true); + } + + QSettings settings = QSettingsPlus::createQSettings(); + settings.beginGroup("ButtonMacros"); + const QString &keyPress = QString("KeyPress-%1-%2").arg(this->row).arg(this->column); + ui->kseKeyPress->setKeySequence(settings.value(keyPress).toString()); + const QString &keyRotateLeft = QString("RotateLeft-%1-%2").arg(this->row).arg(this->column); + ui->kseRotateLeft->setKeySequence(settings.value(keyRotateLeft).toString()); + const QString &keyRotateRight = QString("RotateRight-%1-%2").arg(this->row).arg(this->column); + ui->kseRotateRight->setKeySequence(settings.value(keyRotateRight).toString()); + + QObject::connect(ui->kseKeyPress, + &QKeySequenceEdit::editingFinished, + this, + &KeystrokeEditorWindow::saveNewKeyPressMacro); + QObject::connect(ui->kseRotateLeft, + &QKeySequenceEdit::editingFinished, + this, + &KeystrokeEditorWindow::saveNewRotateLeftMacro); + QObject::connect(ui->kseRotateRight, + &QKeySequenceEdit::editingFinished, + this, + &KeystrokeEditorWindow::saveNewRotateRightMacro); +} + +KeystrokeEditorWindow::~KeystrokeEditorWindow() +{ + delete ui; +} + + +void KeystrokeEditorWindow::saveNewKeyPressMacro() +{ + QSettings settings = QSettingsPlus::createQSettings(); + settings.beginGroup("ButtonMacros"); + const QString &key = QString("KeyPress-%1-%2").arg(this->row).arg(this->column); + settings.setValue(key, ui->kseKeyPress->keySequence()); +} + +void KeystrokeEditorWindow::saveNewRotateLeftMacro() +{ + QSettings settings = QSettingsPlus::createQSettings(); + settings.beginGroup("ButtonMacros"); + const QString &key = QString("RotateLeft-%1-%2").arg(this->row).arg(this->column); + settings.setValue(key, ui->kseRotateLeft->keySequence()); +} + +void KeystrokeEditorWindow::saveNewRotateRightMacro() +{ + QSettings settings = QSettingsPlus::createQSettings(); + settings.beginGroup("ButtonMacros"); + const QString &key = QString("RotateRight-%1-%2").arg(this->row).arg(this->column); + settings.setValue(key, ui->kseRotateRight->keySequence()); +} diff --git a/keystrokeeditorwindow.h b/keystrokeeditorwindow.h new file mode 100644 index 0000000..92598ac --- /dev/null +++ b/keystrokeeditorwindow.h @@ -0,0 +1,30 @@ +#ifndef KEYSTROKEEDITORWINDOW_H +#define KEYSTROKEEDITORWINDOW_H + +#include + +namespace Ui { +class KeystrokeEditorWindow; +} + +class KeystrokeEditorWindow : public QDialog +{ + Q_OBJECT + +public: + explicit KeystrokeEditorWindow(const quint8 &row, const quint8 &column, const bool &dial, QWidget *parent = nullptr); + ~KeystrokeEditorWindow(); + +private slots: + void saveNewKeyPressMacro(); + void saveNewRotateLeftMacro(); + void saveNewRotateRightMacro(); + +private: + Ui::KeystrokeEditorWindow *ui; + + quint8 row = 0; + quint8 column = 0; +}; + +#endif // KEYSTROKEEDITORWINDOW_H diff --git a/keystrokeeditorwindow.ui b/keystrokeeditorwindow.ui new file mode 100644 index 0000000..61d3764 --- /dev/null +++ b/keystrokeeditorwindow.ui @@ -0,0 +1,97 @@ + + + KeystrokeEditorWindow + + + + 0 + 0 + 477 + 373 + + + + Dialog + + + + + + Qt::Orientation::Horizontal + + + + + + + + + + + + + Key Press: + + + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter + + + + + + + false + + + + + + + Rotate Left: + + + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter + + + + + + + Rotate Right + + + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter + + + + + + + false + + + + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + + + + + + + + + + diff --git a/qmacrobindswindow.cpp b/qmacrobindswindow.cpp index f9ebc39..47db77c 100644 --- a/qmacrobindswindow.cpp +++ b/qmacrobindswindow.cpp @@ -14,7 +14,7 @@ #include #include -#include +#include "keystrokeeditorwindow.h" QMacroBindsWindow::QMacroBindsWindow(QWidget *parent) @@ -114,7 +114,12 @@ void QMacroBindsWindow::newButtonState(const quint8 &row, const quint8 &column, if (column < this->vButtonWidgets[row].size()) { this->vButtonWidgets[row][column]->setCheckable(true); this->vButtonWidgets[row][column]->setChecked(state); - WindowFinder::sendInputToFrontmostWindow(QKeySequence(tr("Shift+Z")), state ? KeyEventType::PRESS : KeyEventType::RELEASE); + + QSettings settings = QSettingsPlus::createQSettings(); + settings.beginGroup("ButtonMacros"); + const QString &key = QString("KeyPress-%1-%2").arg(row).arg(column); + QKeySequence sequence(settings.value(key).toString()); + WindowFinder::sendInputToFrontmostWindow(sequence, state ? KeyEventType::PRESS : KeyEventType::RELEASE); } } } @@ -123,15 +128,20 @@ void QMacroBindsWindow::newEncoderRotation(const quint8 &column, const EncoderRo { const QVector &encoderButtons = this->vButtonWidgets.last(); if (column < encoderButtons.size()) { - WindowFinder::sendInputToFrontmostWindow(direction == EncoderRotation::CCW ? QKeySequence(tr("Shift+Y")) : QKeySequence(tr("Shift+A")), KeyEventType::PRESS_AND_RELEASE); + QSettings settings = QSettingsPlus::createQSettings(); + settings.beginGroup("ButtonMacros"); + const QString &key = QString("%3-%1-%2").arg(this->vButtonWidgets.size() - 1).arg(column).arg(direction == EncoderRotation::CCW ? "RotateLeft" : "RotateRight"); + QKeySequence sequence(settings.value(key).toString()); + WindowFinder::sendInputToFrontmostWindow(sequence, KeyEventType::PRESS_AND_RELEASE); } } void QMacroBindsWindow::showKeyBindingWindow(const quint8 &row, const quint8 &column) { - this->vButtonWidgets[row][column]->setCheckable(false); - qDebug() << row << ":" << column; + QRatioButton *button = qobject_cast(this->vButtonWidgets[row][column]); + this->diagKeystrokeEditor = new KeystrokeEditorWindow(row, column, button->type() == QRatioButton::Type::DIAL ? true : false, this); + this->diagKeystrokeEditor->show(); } diff --git a/qmacrobindswindow.h b/qmacrobindswindow.h index d3bfa16..b9976e9 100644 --- a/qmacrobindswindow.h +++ b/qmacrobindswindow.h @@ -39,6 +39,7 @@ private: Ui::QMacroBindsWindow *ui; class WindowFinderDialogue *diagWindowFinder = nullptr; + class KeystrokeEditorWindow *diagKeystrokeEditor = nullptr; class QMacroKeysManager *mkmMacroKeys = nullptr; QVector> vButtonWidgets;