ExpertInfoWidget.cpp 5.5 KB

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