edit Shortcut in manager directly
This commit is contained in:
parent
ae224728c0
commit
bd226279b5
|
@ -91,6 +91,7 @@ public:
|
|||
|
||||
// triggered from the view when the name was changed
|
||||
void nameWasChanged();
|
||||
void keyWasChanged();
|
||||
|
||||
Config::ButtonConfig& getConfig();
|
||||
private:
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <QValidator>
|
||||
|
||||
class KeysequenceValidator : public QValidator {
|
||||
public:
|
||||
explicit KeysequenceValidator(QObject * parent = nullptr);
|
||||
~KeysequenceValidator();
|
||||
|
||||
virtual State validate(QString& str, [[maybe_unused]] int& pos) const override;
|
||||
};
|
|
@ -32,6 +32,7 @@ SOURCES += \
|
|||
src/buttonmanager.cpp \
|
||||
src/buttonmanageritems.cpp \
|
||||
src/addnewwhat.cpp \
|
||||
src/keysequencevalidator.cpp \
|
||||
Log/Log.cpp
|
||||
|
||||
HEADERS += \
|
||||
|
@ -47,6 +48,7 @@ HEADERS += \
|
|||
include/buttonmanager.h \
|
||||
include/buttonmanageritems.h \
|
||||
include/addnewwhat.h \
|
||||
include/keysequencevalidator.h \
|
||||
miniaudio/miniaudio.h \
|
||||
Log/Log.h
|
||||
|
||||
|
|
|
@ -16,12 +16,14 @@ ButtonManager::ButtonManager(Config& conf, MainWindow* parent) : QDialog(parent)
|
|||
loadConfig();
|
||||
|
||||
QStringList labels;
|
||||
labels.push_back("Row");
|
||||
labels.push_back("Button");
|
||||
labels.push_back("Sample");
|
||||
labels.push_back("File");
|
||||
labels.push_back("Name");
|
||||
labels.push_back("Samples");
|
||||
labels.push_back("Shortcut");
|
||||
|
||||
ui->buttonTreeWidget->setHeaderLabels(labels);
|
||||
ui->buttonTreeWidget->setColumnWidth(0, 420);
|
||||
ui->buttonTreeWidget->header()->setStretchLastSection(false);
|
||||
ui->buttonTreeWidget->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
|
||||
QShortcut* sc = new QShortcut(QKeySequence(QKeySequence::Save), this);
|
||||
|
||||
|
@ -71,7 +73,7 @@ void ButtonManager::addButton() {
|
|||
select(newButton);
|
||||
|
||||
// start editing
|
||||
ui->buttonTreeWidget->editItem(newButton, 1);
|
||||
ui->buttonTreeWidget->editItem(newButton, 0);
|
||||
} else {
|
||||
Log::error << "no row selected";
|
||||
}
|
||||
|
@ -180,12 +182,15 @@ void ButtonManager::itemChanged(QTreeWidgetItem* item, int column) {
|
|||
if(!dynamic_cast<ButtonManagerItem*>(item)) return;
|
||||
|
||||
if(ButtonItem* button = dynamic_cast<ButtonItem*>(item)) {
|
||||
if(column != 1) {
|
||||
if(column == 0) {
|
||||
// name
|
||||
button->nameWasChanged();
|
||||
} else if(column == 2) {
|
||||
//shortcut
|
||||
button->keyWasChanged();
|
||||
} else {
|
||||
Log::warn << "column: " << column << " of button was edited";
|
||||
return;
|
||||
}
|
||||
|
||||
button->nameWasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -296,6 +301,9 @@ RowItem* ButtonManager::getCurrentRow(bool create, bool onlyIfSelected) {
|
|||
}
|
||||
|
||||
ButtonItem* ButtonManager::getCurrentButton(bool create) const {
|
||||
// currently unused
|
||||
(void) create;
|
||||
|
||||
QTreeWidgetItem* selectedItem = getSelectedItem();
|
||||
if(!selectedItem) {
|
||||
// no item selected
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include "editbutton.h"
|
||||
#include "editsample.h"
|
||||
|
||||
#include "keysequencevalidator.h"
|
||||
|
||||
ButtonManagerItem::ButtonManagerItem(QTreeWidgetItem* parent, int type, uint8_t pos) : QTreeWidgetItem(parent, type), mparent(parent), pos(pos) {
|
||||
}
|
||||
|
||||
|
@ -184,7 +186,7 @@ uint8_t RowItem::getRow() const {
|
|||
}
|
||||
|
||||
void RowItem::updatePosition() {
|
||||
setData(0, Qt::ItemDataRole::DisplayRole, QVariant((int) pos+1));
|
||||
setData(0, Qt::ItemDataRole::DisplayRole, QVariant(QString::fromStdString("Row " + std::to_string(pos+1))));
|
||||
}
|
||||
|
||||
std::vector<Config::ButtonConfig>& RowItem::getConfig() {
|
||||
|
@ -196,7 +198,9 @@ std::vector<Config::ButtonConfig>& RowItem::getConfig() {
|
|||
|
||||
ButtonItem::ButtonItem(RowItem* parent, uint8_t buttonnr, Config::RootConfig& conf) : ButtonManagerItem(parent, TYPE, buttonnr), conf(conf) {
|
||||
Config::ButtonConfig& btn = getConfig();
|
||||
setData(1, Qt::ItemDataRole::DisplayRole, QVariant(QString::fromStdString(btn.name)));
|
||||
setData(0, Qt::ItemDataRole::DisplayRole, QString::fromStdString(btn.name));
|
||||
setData(1, Qt::ItemDataRole::DisplayRole, (int) btn.samples.size());
|
||||
setData(2, Qt::ItemDataRole::DisplayRole, QString::fromStdString(btn.key));
|
||||
setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable); // | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled
|
||||
|
||||
// iterate samples in a button
|
||||
|
@ -241,7 +245,7 @@ void ButtonItem::edit() {
|
|||
buttonConf.key = editor.getKey();
|
||||
buttonConf.width = editor.getWidth();
|
||||
|
||||
setData(1, Qt::ItemDataRole::DisplayRole, QVariant(QString::fromStdString(buttonConf.name)));
|
||||
setData(0, Qt::ItemDataRole::DisplayRole, QVariant(QString::fromStdString(buttonConf.name)));
|
||||
}
|
||||
|
||||
void ButtonItem::remove() {
|
||||
|
@ -294,10 +298,23 @@ void ButtonItem::moveDown() {
|
|||
}
|
||||
|
||||
void ButtonItem::nameWasChanged() {
|
||||
std::string newName = data(1, Qt::ItemDataRole::DisplayRole).toString().toStdString();
|
||||
std::string newName = data(0, Qt::ItemDataRole::DisplayRole).toString().toStdString();
|
||||
getConfig().name = newName;
|
||||
}
|
||||
|
||||
void ButtonItem::keyWasChanged() {
|
||||
QString newShortcut = data(2, Qt::ItemDataRole::DisplayRole).toString();
|
||||
KeysequenceValidator validator;
|
||||
int pos;
|
||||
Config::ButtonConfig& btn = getConfig();
|
||||
if(validator.validate(newShortcut, pos) == QValidator::Acceptable) {
|
||||
btn.key = newShortcut.toStdString();
|
||||
} else {
|
||||
//reset to old
|
||||
setData(2, Qt::ItemDataRole::DisplayRole, QString::fromStdString(btn.key));
|
||||
}
|
||||
}
|
||||
|
||||
Config::ButtonConfig& ButtonItem::getConfig() {
|
||||
return getParent<RowItem>()->getConfig().at(pos);
|
||||
}
|
||||
|
@ -372,8 +389,9 @@ void ButtonItem::moveToRowBelow() {
|
|||
SampleItem::SampleItem(ButtonItem* parent, uint8_t samplenr, Config::RootConfig& conf) : ButtonManagerItem(parent, TYPE, samplenr), conf(conf) {
|
||||
const Config::SampleConfig& sample = getConfig();
|
||||
updatePosition();
|
||||
setText(3, QString::fromStdString(sample.file));
|
||||
setToolTip(2, "Doubleclick to play");
|
||||
setText(1, QString::fromStdString(sample.file));
|
||||
setToolTip(0, "Doubleclick to play");
|
||||
setToolTip(1, "Doubleclick to play");
|
||||
}
|
||||
|
||||
bool SampleItem::hasEdit() const {
|
||||
|
@ -463,7 +481,7 @@ Config::SampleConfig& SampleItem::getConfig() {
|
|||
}
|
||||
|
||||
void SampleItem::updatePosition() {
|
||||
setData(2, Qt::ItemDataRole::DisplayRole, QVariant((int) pos+1));
|
||||
setData(0, Qt::ItemDataRole::DisplayRole, QVariant((int) pos+1));
|
||||
}
|
||||
|
||||
void SampleItem::moveToButtonAbove() {
|
||||
|
@ -526,4 +544,4 @@ void SampleItem::moveToButtonBelow() {
|
|||
reenumerateAllSiblings();
|
||||
|
||||
expandTree();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,26 +2,15 @@
|
|||
#include "ui_editbutton.h"
|
||||
|
||||
#include <QRegExpValidator>
|
||||
#include "keysequencevalidator.h"
|
||||
|
||||
#include <Log.h>
|
||||
|
||||
class MyKeysequenceValidtor : public QValidator {
|
||||
public:
|
||||
explicit MyKeysequenceValidtor(QObject * parent = nullptr) : QValidator(parent) {}
|
||||
~MyKeysequenceValidtor() {}
|
||||
|
||||
virtual State validate(QString& str, [[maybe_unused]] int& pos) const override {
|
||||
QKeySequence seq(str);
|
||||
return (seq.toString().isEmpty() && !str.isEmpty()) ? State::Intermediate : State::Acceptable;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
EditButton::EditButton(QWidget *parent) : QDialog(parent), ui(new Ui::EditButton) {
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->buttonName->setValidator(new QRegExpValidator(QRegExp("(\\w+ \\w+)|(\\w+)")));
|
||||
ui->buttonKey->setValidator(new MyKeysequenceValidtor());
|
||||
ui->buttonKey->setValidator(new KeysequenceValidator());
|
||||
|
||||
ui->buttonWidth->addItem("1/6", 1);
|
||||
ui->buttonWidth->addItem("1/3", 2);
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
#include "keysequencevalidator.h"
|
||||
|
||||
#include <QKeySequence>
|
||||
|
||||
KeysequenceValidator::KeysequenceValidator(QObject * parent) : QValidator(parent) {}
|
||||
KeysequenceValidator::~KeysequenceValidator() {}
|
||||
|
||||
QValidator::State KeysequenceValidator::validate(QString& str, [[maybe_unused]] int& pos) const {
|
||||
QKeySequence seq(str);
|
||||
return (seq.toString().isEmpty() && !str.isEmpty()) ? State::Intermediate : State::Acceptable;
|
||||
}
|
Loading…
Reference in New Issue