disable buttons

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

View File

@ -32,6 +32,8 @@ public slots:
void play();
private:
void setDisabled();
static uint64_t nextid;
uint64_t id;
@ -42,6 +44,8 @@ private:
uint64_t lengthms = 0; // ignored when length = 0
float volume = 1.f;
bool disabled = false;
QxtGlobalShortcut* globalShortcut = nullptr;
QPushButton* button = nullptr;
};

View File

@ -2,6 +2,8 @@
#include "sound.h"
#include <Log.h>
uint64_t SoundButton::nextid = 0;
SoundButton::SoundButton(const std::string& filename, const std::string& name_, const std::string& keycombo) : id(nextid++), file(filename), keycombo(keycombo) {
@ -63,6 +65,18 @@ QPushButton* SoundButton::getButton() {
}
void SoundButton::play() {
if(disabled) return;
uint64_t endms = (lengthms == 0 ? 0 : startms + lengthms);
Sound::instance().addPlayback(file, volume, startms, endms);
try {
Sound::instance().addPlayback(file, volume, startms, endms);
} catch(const std::exception& e) {
Log::error << "Catched Exception when plaing Audio File: " << file;
setDisabled();
}
}
void SoundButton::setDisabled() {
disabled = true;
button->setText(QString::fromStdString(name + " DISABLED"));
}