#include "clStudentInfo.h"
#include "ui_clStudentInfo.h"

#include "CAppInfo.h"

#include <QGraphicsDropShadowEffect>

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

    setStyleSheet(g_appInfoPtr->m_sQssStr);
}

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

void clStudentInfo::setUI(const int nLeft, const int nTop, const int nWidth, const int nHeight)
{
    setGeometry(nLeft, nTop, nWidth, nHeight);
    ui->label_clsi_studentName->setText(g_appInfoPtr->m_sStudentName);
    ui->label_clsi_orgName->setText(g_appInfoPtr->m_sOrgName);
    ui->label_clsi_studentCode->setText(g_appInfoPtr->m_sStudentCode);
    ui->label_clsi_identity->setText(g_appInfoPtr->m_sStudentIdentityNumber);
    QString sFileName = g_appInfoPtr->m_sStudentPhotoPath.right(g_appInfoPtr->m_sStudentPhotoPath.length() - g_appInfoPtr->m_sStudentPhotoPath.lastIndexOf("/") - 1);
    sFileName = g_appInfoPtr->m_sCacheFileDir + sFileName;

    ui->widget_npw_BG->setGeometry(g_appInfoPtr->m_fRate*5, g_appInfoPtr->m_fRate*5, width()-g_appInfoPtr->m_fRate*10, height()-g_appInfoPtr->m_fRate*10);

    ui->label_studentPhoto->setGeometry(ui->widget_npw_BG->width() - g_appInfoPtr->m_fRate*20 - g_appInfoPtr->m_fRate*64, g_appInfoPtr->m_fRate*20,
                                        g_appInfoPtr->m_fRate*64, g_appInfoPtr->m_fRate*80);
    ui->label_studentPhoto->setPixmap(QPixmap(sFileName).scaled(ui->label_studentPhoto->width(), ui->label_studentPhoto->height(),
                                                                Qt::IgnoreAspectRatio));
    ui->label_clsi_studentName->adjustSize();
    ui->label_clsi_studentName->setGeometry(g_appInfoPtr->m_fRate*20, g_appInfoPtr->m_fRate*20,
                                            ui->label_clsi_studentName->width(), ui->label_clsi_studentName->height());
    ui->label_clsi_studentCodeHint->adjustSize();
    ui->label_clsi_studentCodeHint->setGeometry(ui->label_clsi_studentName->x(), ui->label_clsi_studentName->y() + ui->label_clsi_studentName->height() + g_appInfoPtr->m_fRate*20,
                                                ui->label_clsi_studentCodeHint->width(), ui->label_clsi_studentCodeHint->height());
    ui->label_clsi_studentCode->adjustSize();
    ui->label_clsi_studentCode->setGeometry(ui->label_clsi_studentCodeHint->x() + ui->label_clsi_studentCodeHint->width() + g_appInfoPtr->m_fRate*34,
                                            ui->label_clsi_studentCodeHint->y(), ui->label_clsi_studentCode->width(), ui->label_clsi_studentCode->height());
    ui->label_clsi_identityHint->adjustSize();
    ui->label_clsi_identityHint->setGeometry(ui->label_clsi_studentName->x(), ui->label_clsi_studentCodeHint->y() + ui->label_clsi_studentCodeHint->height() + g_appInfoPtr->m_fRate*10,
                                             ui->label_clsi_identityHint->width(), ui->label_clsi_identityHint->height());
    ui->label_clsi_identity->adjustSize();
    ui->label_clsi_identity->setGeometry(ui->label_clsi_studentCode->x(), ui->label_clsi_identityHint->y(),
                                         ui->label_clsi_identity->width(), ui->label_clsi_identity->height());
    ui->label_clsi_orgNameHint->adjustSize();
    ui->label_clsi_orgNameHint->setGeometry(ui->label_clsi_studentName->x(), ui->label_clsi_identityHint->y() + ui->label_clsi_identityHint->height() + g_appInfoPtr->m_fRate*10,
                                            ui->label_clsi_orgNameHint->width(), ui->label_clsi_orgNameHint->height());
    ui->label_clsi_orgName->adjustSize();
    ui->label_clsi_orgName->setGeometry(ui->label_clsi_studentCode->x(), ui->label_clsi_orgNameHint->y(),
                                        ui->label_clsi_orgName->width(), ui->label_clsi_orgName->height());
    ui->label_HLine->setGeometry(ui->label_clsi_studentName->x(), ui->label_clsi_orgNameHint->y() + ui->label_clsi_orgNameHint->height() + g_appInfoPtr->m_fRate*20,
                                 ui->widget_npw_BG->width() - g_appInfoPtr->m_fRate*20*2,g_appInfoPtr->m_fRate*1 < 1 ? 1 : g_appInfoPtr->m_fRate*1);
    ui->btn_clsi_editPassword->setGeometry(ui->label_clsi_studentName->x(), ui->label_HLine->y() + ui->label_HLine->height() + g_appInfoPtr->m_fRate*20,
                                      g_appInfoPtr->m_fRate*135, g_appInfoPtr->m_fRate*32);
    ui->btn_clsi_exitLogin->setGeometry(ui->widget_npw_BG->width() - g_appInfoPtr->m_fRate*20 - ui->btn_clsi_editPassword->width(),
                                   ui->btn_clsi_editPassword->y(), ui->btn_clsi_editPassword->width(), ui->btn_clsi_editPassword->height());

    QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect;
    effect->setOffset(g_appInfoPtr->m_fRate*4,g_appInfoPtr->m_fRate*4);
    effect->setColor(QColor(0,0,0,30));
    effect->setBlurRadius(g_appInfoPtr->m_fRate*16);
    ui->widget_npw_BG->setGraphicsEffect(effect);
}

void clStudentInfo::on_btn_clsi_editPassword_clicked()
{
    emit sgnStudentEditPassword();
}

void clStudentInfo::on_btn_clsi_exitLogin_clicked()
{
    emit sgnStudentLogout();
}
