andre@722: /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
andre@722:  * Software engineering by Intevation GmbH
andre@722:  *
andre@722:  * This file is Free Software under the GNU GPL (v>=2)
andre@722:  * and comes with ABSOLUTELY NO WARRANTY!
andre@722:  * See LICENSE.txt for details.
andre@722:  */
andre@722: 
andre@722: #include <QPaintEvent>
andre@722: #include <QPainter>
andre@722: #include <QFont>
andre@722: #include <QApplication>
andre@722: 
andre@722: #include <QDebug>
andre@722: 
andre@722: #include "textoverlaybutton.h"
andre@722: 
andre@722: void TextOverlayButton::paintEvent(QPaintEvent *e)
andre@722: {
andre@722:     QToolButton::paintEvent(e);
andre@743:     if (mOverlay == "0" || mOverlay.isEmpty()) {
andre@734:         return;
andre@734:     }
andre@722:     QPainter painter(this);
andre@735:     /* Only usable if opengl is used */
andre@735:     painter.setRenderHint(QPainter::HighQualityAntialiasing, true);
andre@735:     /* Else */
andre@735:     painter.setRenderHint(QPainter::Antialiasing, true);
andre@735: 
emanuel@731:     QRect myRect = e->rect().translated(26, -29);
andre@722: 
emanuel@731:     // circle
emanuel@731:     QLinearGradient gradient(myRect.topLeft(),
emanuel@731:                              myRect.bottomRight());
emanuel@731:     gradient.setColorAt(0, Qt::white);
emanuel@731:     gradient.setColorAt(0.7, Qt::red);
emanuel@731:     QBrush brush(gradient);
emanuel@731:     painter.setBrush(brush);
emanuel@731:     painter.setPen(Qt::white);
emanuel@731:     painter.drawEllipse(75.5, 6, 20, 20);
emanuel@731: 
emanuel@731:     // font
emanuel@731:     QFont font;
emanuel@731:     font.setPixelSize(11);
emanuel@731:     font.setWeight(QFont::Bold);
andre@722:     painter.setFont(font);
andre@722:     painter.drawText(myRect, Qt::AlignCenter | Qt::AlignVCenter, mOverlay);
andre@722: 
andre@722:     return;
andre@722: }