Change the way the text color for snore notifications is computed.

This commit is contained in:
Patrick von Reth 2015-09-21 16:32:36 +02:00
parent b5e77e6d5d
commit a256dd3ed5
2 changed files with 9 additions and 2 deletions

View File

@ -97,8 +97,7 @@ void NotifyWidget::display(const Notification &notification)
color = computeBackgrondColor(notification.application().icon().image().scaled(20, 20));
notification.application().hints().setPrivateValue(parent(), "backgroundColor", color);
}
QRgb gray = qGray(qGray(color.rgb()) - qGray(QColor(Qt::white).rgb()));
QColor textColor = QColor(gray, gray, gray);
QColor textColor = compueTextColor(color);
QMetaObject::invokeMethod(rootObject(), "update", Qt::QueuedConnection,
Q_ARG(QVariant, notification.title(Utils::ALL_MARKUP)),
Q_ARG(QVariant, notification.text(Utils::ALL_MARKUP)),
@ -203,3 +202,10 @@ QColor NotifyWidget::computeBackgrondColor(const QImage &img)
return QColor(r / s, g / s, b / s);
}
QColor NotifyWidget::compueTextColor(const QColor &backgroundColor)
{
// based on http://stackoverflow.com/a/946734
QRgb compColor = qGray(backgroundColor.rgb()) > 186 ? 0 : 255;
return QColor(compColor, compColor, compColor);
}

View File

@ -70,6 +70,7 @@ private Q_SLOTS:
private:
QColor computeBackgrondColor(const QImage &img);
QColor compueTextColor(const QColor &backgroundColor);
Snore::Notification m_notification;
int m_id;