#include "formheadertype1.h"
#include "ui_formheadertype1.h"

#include <QResizeEvent>
#include <QEvent>
#include "mainwindow.h"

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

    m_nID = 0;
}

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


void FormHeaderType1::resizeEvent(QResizeEvent *event)
{
    event->type();

    QSize sz = size();
    ui->horizontalLayoutWidget->setGeometry(0, 0, sz.width(), sz.height());

    int nDisplayType = MainWindow::GetCommonData()->GetDisplayType();
    int nFontSize = 22;
    if(nDisplayType==SDISPLAY_1280X1024)
    {
        ui->frame_image->move(15, 20);
        nFontSize = 16;
    }
    else if(nDisplayType==SDISPLAY_1920X1080)
    {
        ui->frame_image->move(15, 25);
    }

    QString strLabel = QString(
    "QLabel \
    { \
        qproperty-alignment: 'AlignHCenter | AlignVCenter'; \
        font-family: 'Roboto'; \
        font-size: %1px; \
        font-weight: bold; \
        color: white; \
    }").arg(nFontSize);

    ui->label->setStyleSheet(strLabel);


}


void FormHeaderType1::enterEvent(QEvent *event)
{
    //ui->label->setText("hover");

    ui->horizontalLayoutWidget->setStyleSheet("QWidget { background: #ff0000; }");
    //setStyleSheet("");
}

void FormHeaderType1::leaveEvent(QEvent *event)
{
    //ui->label->setText("leave");
    ui->horizontalLayoutWidget->setStyleSheet("QWidget { background: transparent; }");
}


void FormHeaderType1::mousePressEvent(QMouseEvent *event)
{
    //ui->label->setText("click");
    //ui->horizontalLayoutWidget->setStyleSheet("QWidget { background: #000000; }");

    //ui->label->setStyleSheet("QLabel { color: white; }");
    //ui->frame->setStyleSheet("QFrame {border-image: url(://image/Arrow_top_2.png);}");

    /*
    setStyleSheet(
                        "QTableWidget {background-color: transparent; border: none; outline: none;}"
                        //"QHeaderView { border:none; border-bottom: 3px solid rgb(0, 160, 230); background: rgb(57, 58, 60); min-height: 60px;}"
                        "QHeaderView { border:none; border-bottom: 3px solid rgb(0, 160, 230); background: transparent; min-height: 60px;}"

                        "QHeaderView::section:horizontal { border:none; border-right: 1px solid white; color: white; background: transparent ; padding-left: 10px; }"
                        "QHeaderView::section:horizontal:hover { background: rgb(0, 160, 230);}"
                        "QHeaderView::section:horizontal:pressed { background: rgb(0, 180, 255);}"
                        "QHeaderView::up-arrow { width: 23px; height: 12px; padding-right: 25px; image: url(://image/Arrow_top_2.png); subcontrol-position: center right; }"
                        "QHeaderView::down-arrow { width: 23px; height: 12px; padding-right: 25px; image: url(://image/Arrow_under_2.png); subcontrol-position: center right; }");
                        */

}

void FormHeaderType1::mouseReleaseEvent(QMouseEvent *event)
{
    Clicked(m_nID);
}


void FormHeaderType1::Unselect()
{
    //ui->horizontalSpacer->changeSize(0, 0);
    ui->frame->hide();

    //m_nOrder = Qt::AscendingOrder;
    m_nOrder = -1;
}

void FormHeaderType1::Select(int nOrder)
{
    m_nOrder = nOrder;
    if(ui->frame->isVisible()==false)
    {
        //ui->horizontalSpacer->changeSize(10, 20);
        ui->frame->show();
    }


    if(nOrder==Qt::AscendingOrder)
    {
        ui->frame_image->setStyleSheet("QFrame {border-image: url(://image/Arrow_under_2.png);}");
    }
    else if(nOrder==Qt::DescendingOrder)
    {
        ui->frame_image->setStyleSheet("QFrame {border-image: url(://image/Arrow_top_2.png);}");
    }
    else
    {
        ui->frame_image->setStyleSheet("QFrame {border: none;}");
    }


}

int FormHeaderType1::GetOrder()
{
    return m_nOrder;
}

void FormHeaderType1::SetID(int nID)
{
    m_nID = nID;
}

int FormHeaderType1::GetID()
{
    return m_nID;
}

void FormHeaderType1::SetHeaderText(QString& strText)
{
    ui->label->setText(strText);
}

