Set title text color of rollup widget depending on title bar peceived brightness

This commit is contained in:
f4exb 2017-10-05 22:11:17 +02:00
parent 1e33bc3e8d
commit f9fc22c234
2 changed files with 7 additions and 1 deletions

View File

@ -14,7 +14,9 @@ RollupWidget::RollupWidget(QWidget* parent) :
setAutoFillBackground(false);
setAttribute(Qt::WA_OpaquePaintEvent, true);
// Vorgaben aus der Palette
m_titleColor = palette().highlight().color();
m_titleTextColor = palette().highlightedText().color();
}
QByteArray RollupWidget::saveState(int version) const
@ -92,6 +94,8 @@ bool RollupWidget::restoreState(const QByteArray& state, int version)
void RollupWidget::setTitleColor(const QColor& c)
{
m_titleColor = c;
float l = 0.2126*c.redF() + 0.7152*c.greenF() + 0.0722*c.blueF();
m_titleTextColor = l < 0.5f ? Qt::white : Qt::black;
update();
}
@ -187,7 +191,8 @@ void RollupWidget::paintEvent(QPaintEvent*)
p.drawLine(r.bottomLeft() + QPointF(1, -1), r.topRight() + QPointF(-1, 1));
// Titel
p.setPen(palette().highlightedText().color());
//p.setPen(palette().highlightedText().color());
p.setPen(m_titleTextColor);
p.drawText(QRect(2 + fm.height(), 2, width() - 4 - 2 * fm.height(), fm.height()),
fm.elidedText(windowTitle(), Qt::ElideMiddle, width() - 4 - 2 * fm.height(), 0));

View File

@ -20,6 +20,7 @@ protected:
};
QColor m_titleColor;
QColor m_titleTextColor;
int arrangeRollups();