/*
 * Copyright (C) 2020, KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
#include "cpushbuttonex.h"
#include <QMouseEvent>
#include <QPainter>

CPushButtonEx::CPushButtonEx(QWidget *parent) : QPushButton(parent)
{
    m_varData = 0;
    m_bExArea = false;
    m_fRadio = 0.0;
    m_bRadio = false;

    setCursor(Qt::ArrowCursor); //设置鼠标样式
}

CPushButtonEx::~CPushButtonEx()
{

}

void CPushButtonEx::mouseReleaseEvent( QMouseEvent *e )
{
    if (!m_bExArea)
        return QPushButton::mouseReleaseEvent(e);

    QRect rcEx = rect();
    rcEx.setTopLeft(QPoint(rcEx.bottom() / 4 * 3, rcEx.right() / 4 * 3));

    if (!rcEx.contains(e->pos()))
        Q_EMIT SignalClicked();
    else
        Q_EMIT SignalClickedExArea();

    return QPushButton::mouseReleaseEvent(e);
}

void CPushButtonEx::resizeEvent(QResizeEvent *event)
{
    if (m_bRadio)
    {
        setFixedHeight(width() / m_fRadio);

        this->setStyleSheet(QString("QPushButton{font: bold %1px;} QPushButton:hover{font: bold %2px;} QPushButton:pressed{font: bold %3px;}")
                           .arg(this->height() / 2).arg(this->height() / 2 + 6).arg(this->height() / 2 + 2));
    }
}
