soundboard/include/soundbutton.h

56 lines
1016 B
C++

#pragma once
#include <string>
#include <cstdint>
#include <QPushButton>
#include "qxtglobalshortcut.h"
class SoundButton : public QPushButton
{
Q_OBJECT
public:
struct Sample {
std::string file;
uint64_t startms = 0;
uint64_t lengthms = 0; // ignored when length = 0
float volume = 1.f;
};
explicit SoundButton(const std::string& name_ = "", const std::string& keycombo = "", QWidget* parent = nullptr);
~SoundButton();
const std::string& getName() const;
const std::string& getKeyCombo() const;
void addSample(Sample& sample);
void setHighlighted(bool highlighted);
void paintEvent(QPaintEvent *) override;
public slots:
void play();
private:
void setDisabled();
QString getInfo() const;
static uint64_t nextid;
uint64_t id;
std::string name;
std::string keycombo;
uint8_t currentSample = 0;
std::vector<Sample> samples;
bool highlighted = false;
bool disabled = false;
const static uint8_t HIGHLIGHTBORDEROFFSET = 5;
QxtGlobalShortcut* globalShortcut = nullptr;
};