#include "CustomCommandLinkButton.h"
#include "ui_CustomCommandLinkButton.h"

#include <QMouseEvent>
#include <QDebug>

CustomCommandLinkButton::CustomCommandLinkButton(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::CustomCommandLinkButton)
{
    ui->setupUi(this);

    setBackground();
    ui->toolButton->setAttribute(Qt::WA_TransparentForMouseEvents);

    ui->description->setStyleSheet("font-size : 16px; color : #808080");
}

CustomCommandLinkButton::~CustomCommandLinkButton()
{
    delete ui;
}

void CustomCommandLinkButton::setMainText(const QString &text)
{
    ui->text->setText(text);
}

void CustomCommandLinkButton::setDescriptionText(const QString &text)
{
    if (text.isEmpty()) {
        ui->description->hide();
    } else {
        ui->description->show();
    }
    ui->description->setText(text);
}

void CustomCommandLinkButton::setBackground()
{
    m_background = new QLabel();
    ui->background_layout->addWidget(m_background, 0, 0, ui->background_layout->rowCount(), ui->background_layout->columnCount());
    m_background->setPixmap(QPixmap(":/images/background/custom_btn_background.png"));
    m_background->lower();
    m_background->setScaledContents(true);
}

void CustomCommandLinkButton::mouseMoveEvent(QMouseEvent *event)
{
    m_background->setPixmap(QPixmap(":/images/background/custom_btn_press_background.png"));
    QWidget::mouseMoveEvent(event);
}

void CustomCommandLinkButton::mousePressEvent(QMouseEvent *event)
{
    m_background->setPixmap(QPixmap(":/images/background/custom_btn_press_background.png"));
    emit clicked();
    QWidget::mousePressEvent(event);
}

void CustomCommandLinkButton::mouseReleaseEvent(QMouseEvent *event)
{
    m_background->setPixmap(QPixmap(":/images/background/custom_btn_background.png"));
    QWidget::mouseReleaseEvent(event);
}
