#include "ktooltip.h"
#include <QLabel>
#include <QHBoxLayout>
#include <QEvent>
#include <QDebug>
#include <QPainter>
#include <QStyleOption>

Tooltip::Tooltip(QWidget *parent)
    : QWidget(parent)
{
    setAttribute(Qt::WA_DeleteOnClose);
    tipLabel = new QLabel(this);
    QHBoxLayout *mLayout = new QHBoxLayout(this);
    mLayout->addWidget(tipLabel);
    mLayout->setContentsMargins(0, 0, 0, 0);
}

Tooltip::~Tooltip()
{
}

void Tooltip::setText(const QString &text)
{
    tipLabel->setText(text);
    tipLabel->setContentsMargins(2, 0, 2, 0);
}

void Tooltip::popup(Tooltip *kToolTip, const QString &text)
{
    kToolTip->setText(text);
    kToolTip->adjustSize();
    kToolTip->show();
}

void Tooltip::tipClose(Tooltip *kToolTip)
{
    kToolTip->hide();
    this->close();
}

void Tooltip::paintEvent(QPaintEvent * event){
    Q_UNUSED(event)

    QStyleOption opt;
    opt.init(this);
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}

