refactor MainWiondow

This commit is contained in:
mrbesen 2021-12-14 10:23:06 +01:00
parent 0db1d49949
commit d9d2da16dc
Signed by untrusted user: MrBesen
GPG Key ID: 596B2350DCD67504
2 changed files with 23 additions and 27 deletions

View File

@ -27,6 +27,9 @@ signals:
void newStatusMessage(const QString&); void newStatusMessage(const QString&);
private: private:
void loadSoundFromConfig();
void removeAllButtons();
void loadButtonsFromConfig();
Ui::Soundboard *ui; Ui::Soundboard *ui;
std::vector<SoundButton*> soundbuttons; std::vector<SoundButton*> soundbuttons;

View File

@ -22,23 +22,6 @@ MainWindow::~MainWindow() {
Sound::deinit(); Sound::deinit();
} }
// https://stackoverflow.com/a/4857631/4399859
static void clearLayout(QLayout* layout) {
if (layout == NULL)
return;
QLayoutItem* item;
while ((item = layout->takeAt(0))) {
if (item->layout()) {
clearLayout(item->layout());
delete item->layout();
}
if (item->widget()) {
delete item->widget();
}
delete item;
}
}
void MainWindow::reloadConfig() { void MainWindow::reloadConfig() {
Log::info << "realodConfig()"; Log::info << "realodConfig()";
@ -47,6 +30,19 @@ void MainWindow::reloadConfig() {
config.load(); config.load();
loadSoundFromConfig();
removeAllButtons();
loadButtonsFromConfig();
QString done = QString::fromStdString("config loaded");
emit newStatusMessage(done);
Log::info << "realodConfig() done";
}
void MainWindow::loadSoundFromConfig() {
Sound& sound = Sound::instance(); // init sound Sound& sound = Sound::instance(); // init sound
sound.reset(); sound.reset();
const std::vector<std::string>& devices = config.rootConfig.audio.devices; const std::vector<std::string>& devices = config.rootConfig.audio.devices;
@ -63,18 +59,20 @@ void MainWindow::reloadConfig() {
Log::debug << "Sound devices loaded"; Log::debug << "Sound devices loaded";
Sound::FOLDER = config.rootConfig.audioPath;
Log::debug << "Sound::FOLDER: " << Sound::FOLDER;
}
void MainWindow::removeAllButtons() {
//remove old buttons //remove old buttons
for (SoundButton* sb : soundbuttons) { for (SoundButton* sb : soundbuttons) {
ui->gridLayout->removeWidget(sb->getButton()); ui->gridLayout->removeWidget(sb->getButton());
delete sb; delete sb;
} }
soundbuttons.clear(); soundbuttons.clear();
}
// clearLayout(ui->gridLayout); void MainWindow::loadButtonsFromConfig() {
Sound::FOLDER = config.rootConfig.audioPath;
Log::debug << "Sound::FOLDER: " << Sound::FOLDER;
int x = 0; int x = 0;
int y = 0; int y = 0;
const std::vector<std::vector<Config::ButtonConfig>>& buttonConfigs = config.rootConfig.buttons; const std::vector<std::vector<Config::ButtonConfig>>& buttonConfigs = config.rootConfig.buttons;
@ -100,9 +98,4 @@ void MainWindow::reloadConfig() {
x = 0; x = 0;
y++; y++;
} }
QString done = QString::fromStdString("config loaded");
emit newStatusMessage(done);
Log::info << "realodConfig() done";
} }