]> git.sur5r.net Git - minitube/blobdiff - src/painterutils.cpp
Switch watchfile to Github API
[minitube] / src / painterutils.cpp
index 71ce0124fdb7703d9b56f11821cd25dfacf6dd4c..7d145f79458b9e03b4e139973f1fd350bcff1541 100644 (file)
@@ -22,22 +22,24 @@ $END_LICENSE */
 #include "fontutils.h"
 #include "iconutils.h"
 
-PainterUtils::PainterUtils() { }
+PainterUtils::PainterUtils() {}
 
-void PainterUtils::centeredMessage(const QString &message, QWidgetwidget) {
+void PainterUtils::centeredMessage(const QString &message, QWidget *widget) {
     QPainter painter(widget);
     painter.setFont(FontUtils::big());
     QSize textSize(QFontMetrics(painter.font()).size(Qt::TextSingleLine, message));
-    QPoint topLeft(
-                (widget->width()-textSize.width())/2,
-                ((widget->height()-textSize.height())/2)
-                );
+    QPoint topLeft((widget->width() - textSize.width()) / 2,
+                   ((widget->height() - textSize.height()) / 2));
     QRect rect(topLeft, textSize);
     painter.setOpacity(.5);
     painter.drawText(rect, Qt::AlignCenter, message);
 }
 
-void PainterUtils::paintBadge(QPainter *painter, const QString &text, bool center, QColor backgroundColor) {
+void PainterUtils::paintBadge(QPainter *painter,
+                              const QString &text,
+                              bool center,
+                              const QColor &backgroundColor,
+                              bool literalColor) {
     painter->save();
 
     QRect textBox = painter->boundingRect(QRect(), Qt::AlignCenter, text);
@@ -48,11 +50,17 @@ void PainterUtils::paintBadge(QPainter *painter, const QString &text, bool cente
     if (rect.width() < rect.height() || text.length() == 1) rect.setWidth(rect.height());
 
     painter->setPen(Qt::NoPen);
-    painter->setBrush(backgroundColor);
+    QColor bg;
+    if (literalColor)
+        bg = backgroundColor;
+    else
+        bg = backgroundColor.value() > 128 ? QColor(0, 0, 0, 64) : QColor(255, 255, 255, 64);
+    painter->setBrush(bg);
     painter->setRenderHint(QPainter::Antialiasing);
-    qreal borderRadius = rect.height()/2.;
+    qreal borderRadius = rect.height() / 2.;
     painter->drawRoundedRect(rect, borderRadius, borderRadius);
 
+    painter->setFont(FontUtils::small());
     painter->setPen(Qt::white);
     painter->drawText(rect, Qt::AlignCenter, text);