ExpertInfoWidget.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #include "ExpertInfoWidget.h"
  2. #include <Widgets/LineEdit.h>
  3. #include <Widgets/Button.h>
  4. #include <QBoxLayout>
  5. #include <QGridLayout>
  6. #include <QLabel>
  7. ExpertInfoWidget::ExpertInfoWidget(QWidget *parent) : QWidget(parent)
  8. {
  9. initWindow();
  10. initialize();
  11. initLayout();
  12. connectSignalsAndSlots();
  13. updateState();
  14. }
  15. void ExpertInfoWidget::setMode(ExpertInfoWidget::Mode mode)
  16. {
  17. m_mode = mode;
  18. updateState();
  19. }
  20. void ExpertInfoWidget::clearInputs()
  21. {
  22. m_idLineEdit->clear();
  23. m_passwordLineEdit->clear();
  24. m_nameLineEdit->clear();
  25. m_companyLineEdit->clear();
  26. m_jobLineEdit->clear();
  27. m_majorLineEdit->clear();
  28. m_contactInfoLineEdit->clear();
  29. m_noteTextEdit->clear();
  30. updateState();
  31. }
  32. void ExpertInfoWidget::initWindow()
  33. {
  34. setWindowFlags(Qt::Window);
  35. setWindowFlag(Qt::WindowMinMaxButtonsHint, false);
  36. resize(400, 450);
  37. }
  38. void ExpertInfoWidget::initialize()
  39. {
  40. int editWidth = 300;
  41. m_vBoxLayout = new QVBoxLayout(this);
  42. m_gridLayout = new QGridLayout();
  43. m_idLabel = new QLabel(this);
  44. m_idLabel->setText("账号ID:");
  45. m_idLineEdit = new LineEdit(this);
  46. m_idLineEdit->setFixedWidth(editWidth);
  47. m_idLineEdit->setPlaceholderText("请输入a-z/A-Z/0-9数字字母组合");
  48. m_passwordLabel = new QLabel(this);
  49. m_passwordLabel->setText("用户密码:");
  50. m_passwordLineEdit = new PasswordLineEdit(this);
  51. m_passwordLineEdit->setFixedWidth(editWidth);
  52. m_passwordLineEdit->setPlaceholderText("请输入密码");
  53. m_nameLabel = new QLabel(this);
  54. m_nameLabel->setText("专家名:");
  55. m_nameLineEdit = new LineEdit(this);
  56. m_nameLineEdit->setFixedWidth(editWidth);
  57. m_nameLineEdit->setPlaceholderText("请输入专家名");
  58. m_companyLabel = new QLabel(this);
  59. m_companyLabel->setText("单位:");
  60. m_companyLineEdit = new LineEdit(this);
  61. m_companyLineEdit->setFixedWidth(editWidth);
  62. m_jobLabel = new QLabel(this);
  63. m_jobLabel->setText("职务:");
  64. m_jobLineEdit = new LineEdit(this);
  65. m_jobLineEdit->setFixedWidth(editWidth);
  66. m_majorLabel = new QLabel(this);
  67. m_majorLabel->setText("专业:");
  68. m_majorLineEdit = new LineEdit(this);
  69. m_majorLineEdit->setFixedWidth(editWidth);
  70. m_contactInfoLabel = new QLabel(this);
  71. m_contactInfoLabel->setText("联系方式:");
  72. m_contactInfoLineEdit = new LineEdit(this);
  73. m_contactInfoLineEdit->setFixedWidth(editWidth);
  74. m_noteLabel = new QLabel(this);
  75. m_noteLabel->setText("备注:");
  76. m_noteTextEdit = new TextEdit(this);
  77. m_noteTextEdit->setFixedWidth(editWidth);
  78. m_noteTextEdit->setFixedHeight(100);
  79. m_hBoxLayout = new QHBoxLayout();
  80. m_confirmButton = new PushButton("确认", this);
  81. m_cancelButton = new PushButton("取消", this);
  82. }
  83. void ExpertInfoWidget::initLayout()
  84. {
  85. m_vBoxLayout->setContentsMargins(20, 10, 20, 10);
  86. m_vBoxLayout->addLayout(m_gridLayout);
  87. m_gridLayout->addWidget(m_idLabel, 0, 0, 1, 1, Qt::AlignRight);
  88. m_gridLayout->addWidget(m_idLineEdit, 0, 1, 1, 2, Qt::AlignLeft);
  89. m_gridLayout->addWidget(m_passwordLabel, 1, 0, 1, 1, Qt::AlignRight);
  90. m_gridLayout->addWidget(m_passwordLineEdit, 1, 1, Qt::AlignLeft);
  91. m_gridLayout->addWidget(m_nameLabel, 2, 0, 1, 1, Qt::AlignRight);
  92. m_gridLayout->addWidget(m_nameLineEdit, 2, 1, 1, 1, Qt::AlignLeft);
  93. m_gridLayout->addWidget(m_companyLabel, 3, 0, 1, 1, Qt::AlignRight);
  94. m_gridLayout->addWidget(m_companyLineEdit, 3, 1, 1, 1, Qt::AlignLeft);
  95. m_gridLayout->addWidget(m_jobLabel, 4, 0, 1, 1, Qt::AlignRight);
  96. m_gridLayout->addWidget(m_jobLineEdit, 4, 1, 1, 1, Qt::AlignLeft);
  97. m_gridLayout->addWidget(m_majorLabel, 5, 0, 1, 1, Qt::AlignRight);
  98. m_gridLayout->addWidget(m_majorLineEdit, 5, 1, 1, 1, Qt::AlignLeft);
  99. m_gridLayout->addWidget(m_contactInfoLabel, 6, 0, 1, 1, Qt::AlignRight);
  100. m_gridLayout->addWidget(m_contactInfoLineEdit, 6, 1, 1, 1, Qt::AlignLeft);
  101. m_gridLayout->addWidget(m_noteLabel, 7, 0, 1, 1, Qt::AlignRight | Qt::AlignTop);
  102. m_gridLayout->addWidget(m_noteTextEdit, 7, 1, 1, 1, Qt::AlignLeft);
  103. m_vBoxLayout->addStretch();
  104. m_vBoxLayout->addLayout(m_hBoxLayout);
  105. m_hBoxLayout->addStretch();
  106. m_hBoxLayout->addWidget(m_confirmButton);
  107. m_hBoxLayout->addWidget(m_cancelButton);
  108. }
  109. void ExpertInfoWidget::connectSignalsAndSlots()
  110. {
  111. connect(m_confirmButton, &PushButton::clicked, this, &ExpertInfoWidget::slotConfirm);
  112. connect(m_cancelButton, &PushButton::clicked, this, &ExpertInfoWidget::slotCancel);
  113. }
  114. void ExpertInfoWidget::updateState()
  115. {
  116. switch (m_mode) {
  117. case Add: {
  118. setWindowTitle("添加用户");
  119. break;
  120. }
  121. case Update: {
  122. setWindowTitle("修改用户信息");
  123. }
  124. case Read: {
  125. setWindowTitle("用户信息");
  126. }
  127. }
  128. bool editEnabled = m_mode != Read;
  129. m_idLineEdit->setEnabled(editEnabled);
  130. m_passwordLineEdit->setEnabled(editEnabled);
  131. m_nameLineEdit->setEnabled(editEnabled);
  132. m_companyLineEdit->setEnabled(editEnabled);
  133. m_jobLineEdit->setEnabled(editEnabled);
  134. m_majorLineEdit->setEnabled(editEnabled);
  135. m_idLineEdit->setEnabled(editEnabled);
  136. m_contactInfoLineEdit->setEnabled(editEnabled);
  137. m_noteTextEdit->setEnabled(editEnabled);
  138. m_confirmButton->setHidden(!editEnabled);
  139. m_cancelButton->setHidden(!editEnabled);
  140. }
  141. void ExpertInfoWidget::slotConfirm()
  142. {
  143. close();
  144. }
  145. void ExpertInfoWidget::slotCancel()
  146. {
  147. close();
  148. }