UBAngleWidget.cpp 1.42 KB
Newer Older
Anatoly Mihalchenko's avatar
Anatoly Mihalchenko committed
1 2 3
#include "UBAngleWidget.h"
#include <QPainter>

4 5
#include "core/memcheck.h"

Anatoly Mihalchenko's avatar
Anatoly Mihalchenko committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
UBAngleWidget::UBAngleWidget(QWidget *parent)
    : QWidget(parent)
{
    this->setFixedSize(45,30);
    this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
    this->setAttribute(Qt::WA_TranslucentBackground);

    QImage mask_img(width(), height(), QImage::Format_Mono);
    mask_img.fill(0xff);
    QPainter mask_ptr(&mask_img);
    mask_ptr.setBrush( QBrush( QColor(0, 0, 0) ) );
    mask_ptr.drawRoundedRect(0,0,this->geometry().width() - 6,this->geometry().height() - 6,1,1);
    bmpMask = QBitmap::fromImage(mask_img);
    this->setMask(bmpMask);
}

UBAngleWidget::~UBAngleWidget()
{

}

void UBAngleWidget::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);

    this->move(this->cursor().pos().x(), this->cursor().pos().y() - 30);

    QPainter painter(this);
    painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
    QBrush brush(Qt::white);
    painter.setBrush(brush);
    painter.drawRoundedRect(1,1,this->geometry().width() - 10,this->geometry().height() - 10,1,1);

    painter.setPen(QColor(85,50,127));
    painter.setFont(QFont("Arial", 10));
    painter.drawText(1,1,this->geometry().width() - 10,this->geometry().height() - 10, Qt::AlignCenter, text);
}

void UBAngleWidget::setText(QString newText)
{
    text = newText;
    text.append(QChar(176));
}