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&);
private:
void loadSoundFromConfig();
void removeAllButtons();
void loadButtonsFromConfig();
Ui::Soundboard *ui;
std::vector<SoundButton*> soundbuttons;

View File

@ -22,23 +22,6 @@ MainWindow::~MainWindow() {
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() {
Log::info << "realodConfig()";
@ -47,6 +30,19 @@ void MainWindow::reloadConfig() {
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.reset();
const std::vector<std::string>& devices = config.rootConfig.audio.devices;
@ -63,18 +59,20 @@ void MainWindow::reloadConfig() {
Log::debug << "Sound devices loaded";
Sound::FOLDER = config.rootConfig.audioPath;
Log::debug << "Sound::FOLDER: " << Sound::FOLDER;
}
void MainWindow::removeAllButtons() {
//remove old buttons
for (SoundButton* sb : soundbuttons) {
ui->gridLayout->removeWidget(sb->getButton());
delete sb;
}
soundbuttons.clear();
}
// clearLayout(ui->gridLayout);
Sound::FOLDER = config.rootConfig.audioPath;
Log::debug << "Sound::FOLDER: " << Sound::FOLDER;
void MainWindow::loadButtonsFromConfig() {
int x = 0;
int y = 0;
const std::vector<std::vector<Config::ButtonConfig>>& buttonConfigs = config.rootConfig.buttons;
@ -100,9 +98,4 @@ void MainWindow::reloadConfig() {
x = 0;
y++;
}
QString done = QString::fromStdString("config loaded");
emit newStatusMessage(done);
Log::info << "realodConfig() done";
}