-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) {
- static const QPixmap badge1 = QPixmap(":/images/badge.png");
- static const QPixmap badge3 = QPixmap(":/images/badge3.png");
- static const QPixmap badge4 = QPixmap(":/images/badge4.png");
- static const int size = badge1.height();
-
- const int textSize = text.size();
-
- QPixmap badge;
- if (textSize < 3) badge = badge1;
- else if (textSize == 3) badge = badge3;
- else badge = badge4;
-
- int x = 0;
- if (center) x -= badge.width() / 2;
-
- QRect rect(x, 0, badge.width(), size);
- painter->drawPixmap(rect, badge);
-
- QFont f = painter->font();
- f.setPixelSize(11);
- f.setHintingPreference(QFont::PreferNoHinting);
-#ifdef APP_MAC
- f.setFamily("Helvetica");
-#endif
-#ifdef APP_WIN
- rect.adjust(0, -2, 0, 0);
-#endif
-#ifdef Q_WS_X11
- rect.adjust(0, -1, 0, 0);
-#endif