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 uint64_t lengthms = 0; // ignored when length = 0
float volume = 1.f; float volume = 1.f;
bool highlighted = false;
bool disabled = false; bool disabled = false;
const static uint8_t HIGHLIGHTBORDEROFFSET = 5;
QxtGlobalShortcut* globalShortcut = nullptr; QxtGlobalShortcut* globalShortcut = nullptr;
}; };

View File

@ -66,26 +66,29 @@ void SoundButton::setVolume(float v) {
volume = v; volume = v;
} }
void SoundButton::setHighlighted(bool highlighted) { void SoundButton::setHighlighted(bool highlighted_) {
if(highlighted) { highlighted = highlighted_;
setStyleSheet("SoundButton { color: red; }");
//setText("-> " + getInfo()); repaint();
} else {
setStyleSheet("SoundButton {}");
//setText(getInfo());
}
} }
void SoundButton::paintEvent(QPaintEvent* event) { void SoundButton::paintEvent(QPaintEvent* event) {
QPushButton::paintEvent(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 = ""; QString text = "";
// cancel if nothing to print // cancel if nothing to print
if(text.isEmpty()) if(text.isEmpty())
return; return;
QPainter painter(this);
painter.setPen(QPen(Qt::white)); painter.setPen(QPen(Qt::white));
QPoint textPos(0, painter.fontMetrics().height()); QPoint textPos(0, painter.fontMetrics().height());
textPos.rx() = width() - painter.fontMetrics().horizontalAdvance(text) - 6; textPos.rx() = width() - painter.fontMetrics().horizontalAdvance(text) - 6;