soundboard/src/soundbutton.cpp

43 lines
1.1 KiB
C++

#include "soundbutton.h"
#include "sound.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) {
name = (name_.empty() ? filename : name_);
button = new QPushButton(QString::fromStdString(name));
button->setObjectName(QString::fromStdString("soundButton" + std::to_string(id)));
button->setGeometry(QRect(10, 10, 100, 27));
globalShortcut = new QxtGlobalShortcut(QString::fromStdString(keycombo));
QObject::connect(globalShortcut, SIGNAL( activated() ), this, SLOT( play() ));
QObject::connect(button, SIGNAL( clicked() ), this, SLOT( play() ));
}
SoundButton::~SoundButton() {
delete globalShortcut;
delete button;
}
const std::string& SoundButton::getName() const {
return name;
}
const std::string& SoundButton::getFile() const {
return file;
}
const std::string& SoundButton::getKeyCombo() const {
return keycombo;
}
QPushButton* SoundButton::getButton() {
return button;
}
void SoundButton::play() {
Sound::instance().addPlayback(file);
}