UserView.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #include "UserView.h"
  2. #include "QFDIcon.h"
  3. #include "QFDAlert.h"
  4. #include <dbService/ClassSet.h>
  5. #include <Widgets/Button.h>
  6. #include <QBoxLayout>
  7. #include <QGridLayout>
  8. #include <QLabel>
  9. #include <QApplication>
  10. #include <QPixmap>
  11. #include <QResizeEvent>
  12. #include <QPainter>
  13. UserView::UserView(QWidget *parent) : QWidget(parent) { }
  14. void UserView::showEvent(QShowEvent *event)
  15. {
  16. QWidget::showEvent(event);
  17. init();
  18. refresh();
  19. }
  20. void UserView::resizeEvent(QResizeEvent *event)
  21. {
  22. QWidget::resizeEvent(event);
  23. init();
  24. m_bgLabel->resize(event->size());
  25. m_bgLabel->setPixmap(pixmap.scaled(width(), height(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation));
  26. }
  27. void UserView::init()
  28. {
  29. if (m_initilized == true) {
  30. return;
  31. }
  32. initilaize();
  33. initLayout();
  34. connectSignalsAndSlots();
  35. m_initilized = true;
  36. }
  37. void UserView::initilaize()
  38. {
  39. m_vBoxLayout = new QVBoxLayout(this);
  40. m_bgLabel = new QLabel(this);
  41. pixmap = QPixmap(":/resource/background/1.jpg");
  42. m_iconLabel = new QLabel(this);
  43. m_iconLabel->setFixedSize(QSize(50, 50));
  44. m_iconLabel->setScaledContents(true);
  45. QPixmap pixmap = QPixmap(":/resource/logo.png");
  46. pixmap.scaled(m_iconLabel->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
  47. m_iconLabel->setPixmap(pixmap);
  48. m_gridLayout = new QGridLayout();
  49. m_accNameLabel = new QLabel("用户名:", this);
  50. m_accValueLabel = new QLabel(this);
  51. m_idNameLabel = new QLabel("账号id:", this);
  52. m_idValueLabel = new QLabel(this);
  53. m_typeNameLabel = new QLabel("账号类型:", this);
  54. m_typeValueLabel = new QLabel(this);
  55. m_hBoxLayout = new QHBoxLayout();
  56. m_confirmButton = new PushButton("退出", NEWFLICON(QFDIcon, Logout), this);
  57. setStyleSheet("QLabel {font-size: 14px;font:Normal;font-family: 'Microsoft YaHei UI';}");
  58. }
  59. void UserView::initLayout()
  60. {
  61. m_vBoxLayout->setContentsMargins(20, 20, 20, 20);
  62. m_vBoxLayout->addStretch(1);
  63. m_vBoxLayout->addWidget(m_iconLabel, 0, Qt::AlignHCenter);
  64. m_vBoxLayout->addSpacing(50);
  65. m_vBoxLayout->addLayout(m_gridLayout);
  66. m_gridLayout->setAlignment(Qt::AlignHCenter);
  67. m_gridLayout->addWidget(m_accNameLabel, 0, 0, 1, 1, Qt::AlignRight);
  68. m_gridLayout->addWidget(m_accValueLabel, 0, 1, 1, 1, Qt::AlignLeft);
  69. m_gridLayout->addWidget(m_idNameLabel, 1, 0, 1, 1, Qt::AlignRight);
  70. m_gridLayout->addWidget(m_idValueLabel, 1, 1, 1, 1, Qt::AlignLeft);
  71. m_gridLayout->addWidget(m_typeNameLabel, 2, 0, 1, 1, Qt::AlignRight);
  72. m_gridLayout->addWidget(m_typeValueLabel, 2, 1, 1, 1, Qt::AlignLeft);
  73. m_vBoxLayout->addStretch(2);
  74. m_vBoxLayout->addLayout(m_hBoxLayout);
  75. m_hBoxLayout->setAlignment(Qt::AlignRight);
  76. m_hBoxLayout->addWidget(m_confirmButton);
  77. }
  78. void UserView::connectSignalsAndSlots()
  79. {
  80. connect(m_confirmButton, &PushButton::clicked, this, &UserView::slotLogout);
  81. }
  82. void UserView::refresh()
  83. {
  84. // m_accValueLabel->setText(QFUser::currentUser()->userName);
  85. m_accValueLabel->setText("admin");
  86. m_idValueLabel->setText(QFUser::currentUser()->userNo);
  87. // m_typeValueLabel->setText(QFUser::currentUser()->roleName());
  88. m_typeValueLabel->setText("军方论证人员");
  89. }
  90. void UserView::slotLogout()
  91. {
  92. int code = QFUser::logout();
  93. if (code == QF_CODE_SUCCEEDED) {
  94. emit signalLogout();
  95. } else {
  96. QFDAlert::showAlertWithCode(code, this);
  97. }
  98. }