highlight border

This commit is contained in:
mrbesen 2021-12-19 14:57:18 +01:00
parent a9ff7e1e6a
commit 3585f6a538
Signed by untrusted user: MrBesen
GPG Key ID: 596B2350DCD67504
2 changed files with 15 additions and 9 deletions

View File

@ -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;
};

View File

@ -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;