UserView.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 <QPainter>
  12. UserView::UserView(QWidget *parent) : QWidget(parent)
  13. {
  14. initilaize();
  15. initLayout();
  16. connectSignalsAndSlots();
  17. refresh();
  18. }
  19. void UserView::paintEvent(QPaintEvent *event)
  20. {
  21. QWidget::paintEvent(event);
  22. QPainter painter(this);
  23. QPixmap pixmap(":/resource/background/1.jpg");
  24. painter.drawPixmap(0, 0,
  25. pixmap.scaled(width(), height(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation));
  26. }
  27. void UserView::initilaize()
  28. {
  29. m_vBoxLayout = new QVBoxLayout(this);
  30. m_iconLabel = new QLabel(this);
  31. m_iconLabel->setFixedSize(QSize(50, 50));
  32. m_iconLabel->setScaledContents(true);
  33. QPixmap pixmap = QPixmap(":/resource/logo.png");
  34. pixmap.scaled(m_iconLabel->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
  35. m_iconLabel->setPixmap(pixmap);
  36. m_gridLayout = new QGridLayout();
  37. m_accNameLabel = new QLabel("用户名:", this);
  38. m_accValueLabel = new QLabel(this);
  39. m_idNameLabel = new QLabel("账号id:", this);
  40. m_idValueLabel = new QLabel(this);
  41. m_typeNameLabel = new QLabel("账号类型:", this);
  42. m_typeValueLabel = new QLabel(this);
  43. m_hBoxLayout = new QHBoxLayout();
  44. m_confirmButton = new PushButton("退出", NEWFLICON(QFDIcon, Logout), this);
  45. setStyleSheet("QLabel {font-size: 14px;font:Normal;font-family: 'Microsoft YaHei UI';}");
  46. }
  47. void UserView::initLayout()
  48. {
  49. m_vBoxLayout->setContentsMargins(20, 20, 20, 20);
  50. m_vBoxLayout->addStretch(1);
  51. m_vBoxLayout->addWidget(m_iconLabel, 0, Qt::AlignHCenter);
  52. m_vBoxLayout->addSpacing(50);
  53. m_vBoxLayout->addLayout(m_gridLayout);
  54. m_gridLayout->setAlignment(Qt::AlignHCenter);
  55. m_gridLayout->addWidget(m_accNameLabel, 0, 0, 1, 1, Qt::AlignRight);
  56. m_gridLayout->addWidget(m_accValueLabel, 0, 1, 1, 1, Qt::AlignLeft);
  57. m_gridLayout->addWidget(m_idNameLabel, 1, 0, 1, 1, Qt::AlignRight);
  58. m_gridLayout->addWidget(m_idValueLabel, 1, 1, 1, 1, Qt::AlignLeft);
  59. m_gridLayout->addWidget(m_typeNameLabel, 2, 0, 1, 1, Qt::AlignRight);
  60. m_gridLayout->addWidget(m_typeValueLabel, 2, 1, 1, 1, Qt::AlignLeft);
  61. m_vBoxLayout->addStretch(2);
  62. m_vBoxLayout->addLayout(m_hBoxLayout);
  63. m_hBoxLayout->setAlignment(Qt::AlignRight);
  64. m_hBoxLayout->addWidget(m_confirmButton);
  65. }
  66. void UserView::connectSignalsAndSlots()
  67. {
  68. connect(m_confirmButton, &PushButton::clicked, this, &UserView::slotLogout);
  69. }
  70. void UserView::refresh()
  71. {
  72. m_accValueLabel->setText("admin");
  73. m_idValueLabel->setText("100001");
  74. m_typeValueLabel->setText("超级管理员");
  75. }
  76. void UserView::slotLogout()
  77. {
  78. int code = QFUser::logout();
  79. if (code == QF_CODE_SUCCEEDED) {
  80. emit signalLogout();
  81. } else {
  82. QFDAlert::showAlertWithCode(code, this);
  83. }
  84. }