UserView.cpp 2.8 KB

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