#include "UserView.h" #include "QFDIcon.h" #include "QFDAlert.h" #include #include #include #include #include #include #include #include #include UserView::UserView(QWidget *parent) : QWidget(parent) { } void UserView::showEvent(QShowEvent *event) { QWidget::showEvent(event); init(); refresh(); } void UserView::resizeEvent(QResizeEvent *event) { QWidget::resizeEvent(event); init(); m_bgLabel->resize(event->size()); m_bgLabel->setPixmap(pixmap.scaled(width(), height(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation)); } void UserView::init() { if (m_initilized == true) { return; } initilaize(); initLayout(); connectSignalsAndSlots(); m_initilized = true; } void UserView::initilaize() { m_vBoxLayout = new QVBoxLayout(this); m_bgLabel = new QLabel(this); pixmap = QPixmap(":/resource/background/1.jpg"); m_iconLabel = new QLabel(this); m_iconLabel->setFixedSize(QSize(50, 50)); m_iconLabel->setScaledContents(true); QPixmap pixmap = QPixmap(":/resource/logo.png"); pixmap.scaled(m_iconLabel->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); m_iconLabel->setPixmap(pixmap); m_gridLayout = new QGridLayout(); m_accNameLabel = new QLabel("用户名:", this); m_accValueLabel = new QLabel(this); m_idNameLabel = new QLabel("账号id:", this); m_idValueLabel = new QLabel(this); m_typeNameLabel = new QLabel("账号类型:", this); m_typeValueLabel = new QLabel(this); m_hBoxLayout = new QHBoxLayout(); m_confirmButton = new PushButton("退出", NEWFLICON(QFDIcon, Logout), this); setStyleSheet("QLabel {font-size: 14px;font:Normal;font-family: 'Microsoft YaHei UI';}"); } void UserView::initLayout() { m_vBoxLayout->setContentsMargins(20, 20, 20, 20); m_vBoxLayout->addStretch(1); m_vBoxLayout->addWidget(m_iconLabel, 0, Qt::AlignHCenter); m_vBoxLayout->addSpacing(50); m_vBoxLayout->addLayout(m_gridLayout); m_gridLayout->setAlignment(Qt::AlignHCenter); m_gridLayout->addWidget(m_accNameLabel, 0, 0, 1, 1, Qt::AlignRight); m_gridLayout->addWidget(m_accValueLabel, 0, 1, 1, 1, Qt::AlignLeft); m_gridLayout->addWidget(m_idNameLabel, 1, 0, 1, 1, Qt::AlignRight); m_gridLayout->addWidget(m_idValueLabel, 1, 1, 1, 1, Qt::AlignLeft); m_gridLayout->addWidget(m_typeNameLabel, 2, 0, 1, 1, Qt::AlignRight); m_gridLayout->addWidget(m_typeValueLabel, 2, 1, 1, 1, Qt::AlignLeft); m_vBoxLayout->addStretch(2); m_vBoxLayout->addLayout(m_hBoxLayout); m_hBoxLayout->setAlignment(Qt::AlignRight); m_hBoxLayout->addWidget(m_confirmButton); } void UserView::connectSignalsAndSlots() { connect(m_confirmButton, &PushButton::clicked, this, &UserView::slotLogout); } void UserView::refresh() { // m_accValueLabel->setText(QFUser::currentUser()->userName); m_accValueLabel->setText("admin"); m_idValueLabel->setText(QFUser::currentUser()->userNo); // m_typeValueLabel->setText(QFUser::currentUser()->roleName()); m_typeValueLabel->setText("军方论证人员"); } void UserView::slotLogout() { int code = QFUser::logout(); if (code == QF_CODE_SUCCEEDED) { emit signalLogout(); } else { QFDAlert::showAlertWithCode(code, this); } }