#include "titlewidget.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QGridLayout>
#include <QDebug>
#include <QApplication>
TitleWidget::TitleWidget(QWidget * parent ):QFrame(parent)
{
    init();
    initLay();
    initConnect();
}
TitleWidget::~TitleWidget()
{

}

void  TitleWidget::init()
{
    setStyleSheet("QWidget{background-color:#ffffff;}");
    m_labDes.setStyleSheet("border-image:url(:/image/sunnyou_logo.png);}");
   // m_labSystemName.setStyleSheet("border-image:url(:/image/index_bg_EEG_char.png);}");
    //m_labSystemName.setText(tr("Multi-channel wireless EEG acquisition system"));
    m_labSystemName.setStyleSheet("border-image:url(:/image/logo_txt.png);}");
    m_btnRet.setStyleSheet("background-image:url(:/image/icon_exit.png);}");



    m_btnRet.setStyleSheet("QPushButton{border-image:url(:/image/icon_exit.png);}"
                           "QPushButton:hover{border-image:url(:/image/icon_exit_hover.png);}"
                           "QPushButton:pressed{border-image:url(:/image/icon_exit_checked.png);}"
                           );


    m_labDes.setMaximumSize(QSize(300,40));
    m_labSystemName.setFixedSize(QSize(500,40));
    m_btnRet.setMaximumSize(QSize(60,60));

     m_labDes.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
     m_labSystemName.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
     m_btnRet.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

}
void  TitleWidget::initLay()
{
#if 0
    QHBoxLayout * hlay = new QHBoxLayout;
    hlay->addWidget(&m_labDes,Qt::AlignLeft);
    hlay->addWidget(&m_labSystemName,1,Qt::AlignHCenter);
    //hlay->addStretch();
    hlay->addWidget(&m_btnRet,1,Qt::AlignRight);
    setLayout(hlay);
#else
    QGridLayout * hlay = new   QGridLayout;
    hlay->addWidget(&m_labDes,0,0 );
    hlay->addWidget(&m_labSystemName,0,1,Qt::AlignHCenter );
    //hlay->addStretch();
    hlay->addWidget(&m_btnRet,0,2 );
    hlay->setContentsMargins(1,1,1,1);
    setLayout(hlay);
#endif

}

bool  TitleWidget::initConnect()
{
    bool bCon = true;
    bCon = connect(&m_btnRet,SIGNAL(clicked(bool)),qApp,SLOT(quit()));
    if(!bCon)
    {
        qDebug()<<"connect failed"<<endl;


    }
 return bCon;
}

