#include "networkbutton.h"
#include <QStylePainter>
#include <QStyleOption>
#include <QMouseEvent>

NetWorkButton::NetWorkButton(QWidget *parent)
    : KyNetworkIcon(parent)
{
    setFixedSize(48, 48);
    setIconSize(QSize(24, 24));
    setFocusPolicy(Qt::NoFocus);
}

void NetWorkButton::setClickedStatus(int status)
{
    curStatus = status;
    update();
}

void NetWorkButton::paintEvent(QPaintEvent *e)
{
    Q_UNUSED(e);
    QStylePainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);
    QStyleOptionButton option;
    initStyleOption(&option);

//    if (curStatus == NORMAL) {
//        painter.save();
//        painter.setPen(Qt::NoPen);
//        painter.setBrush(Qt::white);
//        painter.setOpacity(0);
//        painter.drawRoundedRect(option.rect.adjusted(1, 1, -1, -1), 6, 6);
//        painter.restore();
//    }

//    if (option.state & QStyle::State_MouseOver) {
//        painter.save();
//        painter.setPen(Qt::NoPen);
//        painter.setBrush(Qt::white);
//        painter.setOpacity(0.25);
//        painter.drawRoundedRect(option.rect.adjusted(1, 1, -1, -1), 6, 6);
//        painter.restore();
//    }

    if (curStatus == CLICKED) {
        painter.save();
        painter.setPen(Qt::NoPen);
        painter.setBrush(Qt::white);
        painter.setOpacity(0.35);
        painter.drawRoundedRect(option.rect.adjusted(1, 1, -1, -1), 6, 6);
        painter.restore();
    }

    if (curStatus == SELECT) {
        painter.save();
        painter.setPen(Qt::NoPen);
        painter.setBrush(Qt::white);
        painter.setOpacity(0.25);
        painter.drawRoundedRect(option.rect.adjusted(1, 1, -1, -1), 6, 6);
        painter.restore();

        painter.save();
        QStyleOption opt;
        QColor color = opt.palette.color(QPalette::Highlight);
        painter.setPen(QPen(color, 2));
        painter.setBrush(Qt::NoBrush);
        painter.drawRoundedRect(option.rect.adjusted(1, 1, -1, -1), 6, 6);
        painter.restore();
    }
    QPushButton::paintEvent(e);

}

void NetWorkButton::mouseReleaseEvent(QMouseEvent *e)
{
    e->ignore();
}

void NetWorkButton::mousePressEvent(QMouseEvent *e)
{
    e->ignore();
}
