diff --git a/src/domain/UBAngleWidget.cpp b/src/domain/UBAngleWidget.cpp new file mode 100644 index 00000000..542a7eed --- /dev/null +++ b/src/domain/UBAngleWidget.cpp @@ -0,0 +1,46 @@ +#include "UBAngleWidget.h" +#include + +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)); +} \ No newline at end of file diff --git a/src/domain/UBAngleWidget.h b/src/domain/UBAngleWidget.h new file mode 100644 index 00000000..20b09431 --- /dev/null +++ b/src/domain/UBAngleWidget.h @@ -0,0 +1,25 @@ +#ifndef UBANGLEWIDGET_H +#define UBANGLEWIDGET_H + +#include +#include + +class UBAngleWidget : public QWidget +{ + Q_OBJECT + +public: + UBAngleWidget(QWidget *parent = 0); + ~UBAngleWidget(); + + void setText(QString); + +protected: + void paintEvent(QPaintEvent *event); + +private: + QString text; + QBitmap bmpMask; +}; + +#endif // UBANGLEWIDGET_H