forked from MrBesen/soundboard
highlight border
This commit is contained in:
parent
a9ff7e1e6a
commit
3585f6a538
|
@ -48,7 +48,10 @@ private:
|
|||
uint64_t lengthms = 0; // ignored when length = 0
|
||||
float volume = 1.f;
|
||||
|
||||
bool highlighted = false;
|
||||
bool disabled = false;
|
||||
|
||||
const static uint8_t HIGHLIGHTBORDEROFFSET = 5;
|
||||
|
||||
QxtGlobalShortcut* globalShortcut = nullptr;
|
||||
};
|
|
@ -66,26 +66,29 @@ void SoundButton::setVolume(float v) {
|
|||
volume = v;
|
||||
}
|
||||
|
||||
void SoundButton::setHighlighted(bool highlighted) {
|
||||
if(highlighted) {
|
||||
setStyleSheet("SoundButton { color: red; }");
|
||||
//setText("-> " + getInfo());
|
||||
} else {
|
||||
setStyleSheet("SoundButton {}");
|
||||
//setText(getInfo());
|
||||
}
|
||||
void SoundButton::setHighlighted(bool highlighted_) {
|
||||
highlighted = highlighted_;
|
||||
|
||||
repaint();
|
||||
}
|
||||
|
||||
void SoundButton::paintEvent(QPaintEvent* event) {
|
||||
QPushButton::paintEvent(event);
|
||||
|
||||
QPainter painter(this);
|
||||
if(highlighted) {
|
||||
QSize s = size();
|
||||
QRect rect(HIGHLIGHTBORDEROFFSET, HIGHLIGHTBORDEROFFSET, s.width()-HIGHLIGHTBORDEROFFSET*2, s.height()-HIGHLIGHTBORDEROFFSET*2);
|
||||
painter.setPen(QPen(Qt::red));
|
||||
painter.drawRect(rect);
|
||||
}
|
||||
|
||||
QString text = "";
|
||||
|
||||
// cancel if nothing to print
|
||||
if(text.isEmpty())
|
||||
return;
|
||||
|
||||
QPainter painter(this);
|
||||
painter.setPen(QPen(Qt::white));
|
||||
QPoint textPos(0, painter.fontMetrics().height());
|
||||
textPos.rx() = width() - painter.fontMetrics().horizontalAdvance(text) - 6;
|
||||
|
|
Loading…
Reference in New Issue