#include "fontutils.h"
#include "iconutils.h"
-PainterUtils::PainterUtils() { }
+PainterUtils::PainterUtils() {}
-void PainterUtils::centeredMessage(const QString &message, QWidget* widget) {
+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);
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);