configure all shortcuts

This commit is contained in:
MrBesen 2022-02-26 16:37:01 +01:00
parent 98c60bfc4c
commit 5fd8e72f52
5 changed files with 68 additions and 10 deletions

View File

@ -36,11 +36,21 @@ public:
const static uint8_t DEFAULTWIDTH;
};
struct ShortcutConfig {
std::string up;
std::string down;
std::string left;
std::string right;
std::string play;
std::string stop;
};
struct RootConfig {
AudioConfig audio;
std::vector<std::vector<ButtonConfig>> buttons;
std::string audioPath;
ShortcutConfig shortcuts;
} rootConfig;
private:

View File

@ -44,12 +44,15 @@ signals:
private:
void loadSoundFromConfig();
void loadShortcuts();
void removeAllButtons();
void loadButtonsFromConfig();
void reselectNext(std::function<void(uint8_t&,uint8_t&)> stepf);
QLayoutItem* findNextButton(std::function<void(uint8_t&,uint8_t&)> stepf);
QxtGlobalShortcut* loadShortcut(const std::string& key);
Ui::Soundboard *ui;
std::vector<SoundButton*> soundbuttons;
QxtGlobalShortcut* stopGlobal = nullptr;

View File

@ -5,6 +5,15 @@
""
]
},
"shortcuts": {
"up": "Shift+Up",
"down": "Shift+Down",
"left": "Shift+Left",
"right": "Shift+Right",
"play": "Shift+Num+Enter",
"stop": "Shift+Num+0"
},
"audioPath": "./neuesSB/",
"buttons": [
[
{

View File

@ -50,6 +50,15 @@ void from_json(const json& j, Config::ButtonConfig& bc) {
}
}
void from_json(const json& j, Config::ShortcutConfig& sc) {
sc.up = j.value("up", "");
sc.down = j.value("down", "");
sc.left = j.value("left", "");
sc.right = j.value("right", "");
sc.play = j.value("play", "");
sc.stop = j.value("stop", "");
}
void from_json(const json& j, Config::RootConfig& rc) {
rc.audio = j.value<Config::AudioConfig>("audio", {});
json barr = j.value("buttons", json::array());
@ -62,6 +71,7 @@ void from_json(const json& j, Config::RootConfig& rc) {
}
}
rc.audioPath = j.value("audioPath", "");
rc.shortcuts = j.value("shortcuts", Config::ShortcutConfig());
}
@ -101,6 +111,15 @@ void to_json(json& j, const Config::ButtonConfig& bc) {
}
}
void to_json(json& j, const Config::ShortcutConfig& sc) {
j["up"] = sc.up;
j["down"] = sc.down;
j["left"] = sc.left;
j["right"] = sc.right;
j["play"] = sc.play;
j["stop"] = sc.stop;
}
void to_json(json& j, const Config::RootConfig& rc) {
j["audio"] = rc.audio;
j["audioPath"] = rc.audioPath;
@ -118,4 +137,5 @@ void to_json(json& j, const Config::RootConfig& rc) {
}
j["buttons"] = buttonarr;
}
j["shortcuts"] = rc.shortcuts;
}

View File

@ -15,15 +15,6 @@
MainWindow::MainWindow(const std::string& binary, QWidget* parent) : QMainWindow(parent), ui(new Ui::Soundboard), config(binary) {
ui->setupUi(this);
up = new QxtGlobalShortcut(QKeySequence("Shift+Up"));
down = new QxtGlobalShortcut(QKeySequence("Shift+Down"));
left = new QxtGlobalShortcut(QKeySequence("Shift+Left"));
right = new QxtGlobalShortcut(QKeySequence("Shift+Right"));
play = new QxtGlobalShortcut(QKeySequence("Shift+Num+Enter"));
QKeySequence seq(QString::fromStdString("Shift+Num+0"));
stopGlobal = new QxtGlobalShortcut(seq);
reloadConfig();
QObject::connect(ui->reloadButton, SIGNAL(clicked()), this, SLOT(reloadConfig()));
@ -63,6 +54,7 @@ void MainWindow::reloadConfig() {
config.load();
loadSoundFromConfig();
loadShortcuts();
removeAllButtons();
@ -170,6 +162,23 @@ void MainWindow::loadSoundFromConfig() {
Log::debug << "Sound::FOLDER: " << Sound::FOLDER;
}
void MainWindow::loadShortcuts() {
delete up;
delete down;
delete left;
delete right;
delete play;
delete stopGlobal;
const Config::ShortcutConfig& sc = config.rootConfig.shortcuts;
up = loadShortcut(sc.up);
down = loadShortcut(sc.down);
left = loadShortcut(sc.left);
right = loadShortcut(sc.right);
play = loadShortcut(sc.play);
stopGlobal = loadShortcut(sc.stop);
}
void MainWindow::removeAllButtons() {
//remove old buttons
for (SoundButton* sb : soundbuttons) {
@ -253,4 +262,11 @@ QLayoutItem* MainWindow::findNextButton(std::function<void(uint8_t&,uint8_t&)> s
// might the same item
return item;
}
QxtGlobalShortcut* MainWindow::loadShortcut(const std::string& key) {
QKeySequence seq(QString::fromStdString(key));
if(seq.isEmpty())
return nullptr;
return new QxtGlobalShortcut(seq);
}