forked from MrBesen/soundboard
configure all shortcuts
This commit is contained in:
parent
98c60bfc4c
commit
5fd8e72f52
|
@ -36,11 +36,21 @@ public:
|
||||||
const static uint8_t DEFAULTWIDTH;
|
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 {
|
struct RootConfig {
|
||||||
AudioConfig audio;
|
AudioConfig audio;
|
||||||
|
|
||||||
std::vector<std::vector<ButtonConfig>> buttons;
|
std::vector<std::vector<ButtonConfig>> buttons;
|
||||||
std::string audioPath;
|
std::string audioPath;
|
||||||
|
ShortcutConfig shortcuts;
|
||||||
} rootConfig;
|
} rootConfig;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -44,12 +44,15 @@ signals:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void loadSoundFromConfig();
|
void loadSoundFromConfig();
|
||||||
|
void loadShortcuts();
|
||||||
void removeAllButtons();
|
void removeAllButtons();
|
||||||
void loadButtonsFromConfig();
|
void loadButtonsFromConfig();
|
||||||
|
|
||||||
void reselectNext(std::function<void(uint8_t&,uint8_t&)> stepf);
|
void reselectNext(std::function<void(uint8_t&,uint8_t&)> stepf);
|
||||||
QLayoutItem* findNextButton(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;
|
Ui::Soundboard *ui;
|
||||||
std::vector<SoundButton*> soundbuttons;
|
std::vector<SoundButton*> soundbuttons;
|
||||||
QxtGlobalShortcut* stopGlobal = nullptr;
|
QxtGlobalShortcut* stopGlobal = nullptr;
|
||||||
|
|
|
@ -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": [
|
"buttons": [
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
|
|
|
@ -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) {
|
void from_json(const json& j, Config::RootConfig& rc) {
|
||||||
rc.audio = j.value<Config::AudioConfig>("audio", {});
|
rc.audio = j.value<Config::AudioConfig>("audio", {});
|
||||||
json barr = j.value("buttons", json::array());
|
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.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) {
|
void to_json(json& j, const Config::RootConfig& rc) {
|
||||||
j["audio"] = rc.audio;
|
j["audio"] = rc.audio;
|
||||||
j["audioPath"] = rc.audioPath;
|
j["audioPath"] = rc.audioPath;
|
||||||
|
@ -118,4 +137,5 @@ void to_json(json& j, const Config::RootConfig& rc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
j["buttons"] = buttonarr;
|
j["buttons"] = buttonarr;
|
||||||
}
|
j["shortcuts"] = rc.shortcuts;
|
||||||
|
}
|
||||||
|
|
|
@ -15,15 +15,6 @@
|
||||||
MainWindow::MainWindow(const std::string& binary, QWidget* parent) : QMainWindow(parent), ui(new Ui::Soundboard), config(binary) {
|
MainWindow::MainWindow(const std::string& binary, QWidget* parent) : QMainWindow(parent), ui(new Ui::Soundboard), config(binary) {
|
||||||
ui->setupUi(this);
|
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();
|
reloadConfig();
|
||||||
|
|
||||||
QObject::connect(ui->reloadButton, SIGNAL(clicked()), this, SLOT(reloadConfig()));
|
QObject::connect(ui->reloadButton, SIGNAL(clicked()), this, SLOT(reloadConfig()));
|
||||||
|
@ -63,6 +54,7 @@ void MainWindow::reloadConfig() {
|
||||||
config.load();
|
config.load();
|
||||||
|
|
||||||
loadSoundFromConfig();
|
loadSoundFromConfig();
|
||||||
|
loadShortcuts();
|
||||||
|
|
||||||
removeAllButtons();
|
removeAllButtons();
|
||||||
|
|
||||||
|
@ -170,6 +162,23 @@ void MainWindow::loadSoundFromConfig() {
|
||||||
Log::debug << "Sound::FOLDER: " << Sound::FOLDER;
|
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() {
|
void MainWindow::removeAllButtons() {
|
||||||
//remove old buttons
|
//remove old buttons
|
||||||
for (SoundButton* sb : soundbuttons) {
|
for (SoundButton* sb : soundbuttons) {
|
||||||
|
@ -253,4 +262,11 @@ QLayoutItem* MainWindow::findNextButton(std::function<void(uint8_t&,uint8_t&)> s
|
||||||
|
|
||||||
// might the same item
|
// might the same item
|
||||||
return item;
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
QxtGlobalShortcut* MainWindow::loadShortcut(const std::string& key) {
|
||||||
|
QKeySequence seq(QString::fromStdString(key));
|
||||||
|
if(seq.isEmpty())
|
||||||
|
return nullptr;
|
||||||
|
return new QxtGlobalShortcut(seq);
|
||||||
}
|
}
|
Loading…
Reference in New Issue