#include "additionalwidget.h"
#include "iconhelper.h"
#include "ctextedit.h"
#include "global.h"
#include "fancydialog.h"

#include <QHBoxLayout>
#include <QToolButton>
#include <QPushButton>


AdditionalWidget::AdditionalWidget(QWidget *parent)
    : QWidget(parent)
{
    initUI();
    createConnections();
}

QRect AdditionalWidget::relativePosition()
{
    return mHeadButton->geometry();
}

void AdditionalWidget::setNotLoginState()
{
    mLogButton->setEnabled(false);
    mSystemButton->setEnabled(false);
}

void AdditionalWidget::setLoginState()
{
    mLogButton->setEnabled(true);
    mSystemButton->setEnabled(true);
}

bool AdditionalWidget::headHasMouse()
{
    return mHeadButton->hasMouse();
}

void AdditionalWidget::initUI()
{
    QPixmap pix = IconHelper::Instance()->getPixmap("#FEFEFE", 0xf013, 30, 35, 35);

    mMainHLayout = new QHBoxLayout;
    mLogButton = new QToolButton;
    mLogButton->setObjectName("AdditionalWidgetToolButton");
    mLogButton->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonTextUnderIcon);
    mLogButton->setText(tr("日志"));
    mLogButton->setFixedSize(50, 50);
    mLogButton->setIcon(QIcon(pix));
    mSystemButton = new QToolButton;
    mSystemButton->setObjectName("AdditionalWidgetToolButton");
    mSystemButton->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonTextUnderIcon);
    mSystemButton->setText(tr("系统"));
    mSystemButton->setFixedSize(50, 50);
    pix = IconHelper::Instance()->getPixmap("#FEFEFE", 0xf06b, 30, 35, 35);
    mSystemButton->setIcon(QIcon(pix));
    mLoginButton = new QToolButton;
    mLoginButton->setObjectName("AdditionalWidgetToolButton");
    mLoginButton->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonTextUnderIcon);
    mLoginButton->setText(tr("登录"));
    mLoginButton->setFixedSize(50, 50);
    pix = IconHelper::Instance()->getPixmap("#FEFEFE", 0xf113, 30, 35, 35);
    mLoginButton->setIcon(QIcon(pix));

    mHeadButton = new HeadButton;
    mHeadButton->setObjectName("AdditionalWidgetPushButton");
    mHeadButton->setIconSize(QSize(28, 28));
    mHeadButton->setFixedSize(QSize(36, 36));
    mHeadButton->setIcon(QIcon(Global::Instance()->resourceDirPath() + "/image/fries.png"));
    mMainHLayout->addWidget(mLogButton);
    mMainHLayout->addWidget(mSystemButton);
    mMainHLayout->addWidget(mLoginButton);
    mMainHLayout->addWidget(mHeadButton);
    mMainHLayout->setSpacing(1);
    this->setLayout(mMainHLayout);
    this->setObjectName("AdditionalWidget");


}

void AdditionalWidget::createConnections()
{
    connect(mLogButton, &QPushButton::clicked, this, &AdditionalWidget::logInfo);
    connect(mLoginButton, &QPushButton::clicked, this, &AdditionalWidget::loginInfo);
    connect(mSystemButton, &QPushButton::clicked, this, &AdditionalWidget::menuInfo);
    connect(mHeadButton, &HeadButton::signalEnter, this, &AdditionalWidget::enterHead);
    connect(mHeadButton, &HeadButton::signalLeave, this, &AdditionalWidget::leaveHead);
}




HeadButton::HeadButton(const QIcon &icon, const QString &text, QWidget *parent)
    : QPushButton(icon, text, parent)
{

}

HeadButton::HeadButton(const QString &text, QWidget *parent)
    : QPushButton(text, parent)
{

}

HeadButton::HeadButton(QWidget *parent)
    : QPushButton(parent)
{

}

bool HeadButton::hasMouse()
{
    if(this->underMouse())
        return true;
    else
        return false;
}

void HeadButton::enterEvent(QEvent *e)
{
    emit signalEnter();
}

void HeadButton::leaveEvent(QEvent *e)
{
    emit signalLeave();
}
