X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fpainterutils.cpp;fp=src%2Fpainterutils.cpp;h=71ce0124fdb7703d9b56f11821cd25dfacf6dd4c;hb=533489a63a9716c645a11a99ca446978b20eedd0;hp=9281b0d62ab5003eea0e2418c9557bf8b01d6ac1;hpb=994e6e5e95196b0e36c680b1fd496f12d71739c9;p=minitube diff --git a/src/painterutils.cpp b/src/painterutils.cpp index 9281b0d..71ce012 100644 --- a/src/painterutils.cpp +++ b/src/painterutils.cpp @@ -33,75 +33,26 @@ void PainterUtils::centeredMessage(const QString &message, QWidget* widget) { ((widget->height()-textSize.height())/2) ); QRect rect(topLeft, textSize); - - /* - rect.adjust(0, -1, 0, 0); - painter.setPen(QColor(0, 0, 0, 128)); - painter.drawText(rect, Qt::AlignCenter, message); - rect.adjust(0, 1, 0, 0); - */ - - QPen textPen; - textPen.setBrush(widget->palette().mid()); - painter.setPen(textPen); + painter.setOpacity(.5); painter.drawText(rect, Qt::AlignCenter, message); } -void PainterUtils::topShadow(QWidget *widget) { - static QLinearGradient shadow; - static const int shadowHeight = 10; - if (shadow.stops().count() == 2) { - shadow.setFinalStop(0, shadowHeight); - const qreal initialOpacity = 96; - for (qreal i = 0; i <= 1; i += 1.0/shadowHeight) { - qreal opacity = qPow(initialOpacity, (1.0 - i)) - 1; - shadow.setColorAt(i, QColor(0x00, 0x00, 0x00, opacity)); - } - } - QRect rect = widget->rect(); - QPainter p(widget); - p.fillRect(rect.x(), rect.y(), rect.width(), shadowHeight, QBrush(shadow)); -} - -void PainterUtils::paintBadge(QPainter *painter, const QString &text, bool center) { - const QPixmap badge1 = IconUtils::pixmap(":/images/badge.png"); - const QPixmap badge3 = IconUtils::pixmap(":/images/badge3.png"); - const QPixmap badge4 = IconUtils::pixmap(":/images/badge4.png"); - - const int textSize = text.size(); - - QPixmap badge; - if (textSize < 3) badge = badge1; - else if (textSize == 3) badge = badge3; - else badge = badge4; - - const int w = badge.width() / badge.devicePixelRatio(); - const int h = badge.height() / badge.devicePixelRatio(); +void PainterUtils::paintBadge(QPainter *painter, const QString &text, bool center, QColor backgroundColor) { + painter->save(); + QRect textBox = painter->boundingRect(QRect(), Qt::AlignCenter, text); + int w = textBox.width() + painter->fontMetrics().width('m'); int x = 0; if (center) x -= w / 2; + QRect rect(x, 0, w, textBox.height()); + if (rect.width() < rect.height() || text.length() == 1) rect.setWidth(rect.height()); - QRect rect(x, 0, w, h); - painter->drawPixmap(rect, badge); - - QFont f = painter->font(); - f.setPixelSize(11); - f.setHintingPreference(QFont::PreferNoHinting); -#ifdef APP_MAC - f.setFamily("Helvetica"); -#elif APP_WIN - rect.adjust(0, -2, 0, 0); -#else - rect.adjust(0, -1, 0, 0); -#endif - painter->save(); - painter->setFont(f); - - rect.adjust(0, 1, 0, 0); - painter->setPen(QColor(0, 0, 0, 64)); - painter->drawText(rect, Qt::AlignCenter, text); + painter->setPen(Qt::NoPen); + painter->setBrush(backgroundColor); + painter->setRenderHint(QPainter::Antialiasing); + qreal borderRadius = rect.height()/2.; + painter->drawRoundedRect(rect, borderRadius, borderRadius); - rect.adjust(0, -1, 0, 0); painter->setPen(Qt::white); painter->drawText(rect, Qt::AlignCenter, text);