#include "toolpop.h"

#include <QPaintEvent>
#include <QPainterPath>
#include <QPainter>

ToolPop::ToolPop(QWidget* parent) : QLabel (parent)
{
//    this->setAlignment(Qt::AlignCenter);
//    this->setStyleSheet("margin: 0 15");
}

void ToolPop::popupSlot(QPoint point) {
    this->move(point.x() - this->width() / 2 -4,
               point.y() - this->height() - 8);
    this->show();
}

void ToolPop::paintEvent(QPaintEvent *event) {
    QPainter painter(this);
    painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing,
                           true);

    painter.setPen(Qt::transparent);
    QPalette pal;
    painter.setBrush(pal.highlight());
    painter.drawRoundedRect(this->rect(), 4, 4);

    QFont font;
    font.setPixelSize(12);
    QFontMetrics fontMetrics(font);
    int labelLen = fontMetrics.width(this->text());
    painter.setPen(QPen(Qt::white));
    painter.setFont(font);
    painter.drawText((this->width() - labelLen) / 2, (this->height() + 10) / 2, this->text());
}


