ExpertInfoWidget.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. #include "ExpertInfoWidget.h"
  2. #include <Widgets/LineEdit.h>
  3. #include <Widgets/Button.h>
  4. #include <Widgets/SpinBox.h>
  5. #include <QBoxLayout>
  6. #include <QGridLayout>
  7. #include <QLabel>
  8. #include <QDebug>
  9. ExpertInfoWidget::ExpertInfoWidget(QWidget *parent) : QWidget(parent)
  10. {
  11. initWindow();
  12. initialize();
  13. initLayout();
  14. connectSignalsAndSlots();
  15. updateState();
  16. }
  17. void ExpertInfoWidget::showEvent(QShowEvent *event)
  18. {
  19. QWidget::showEvent(event);
  20. clearFocus();
  21. }
  22. void ExpertInfoWidget::hideEvent(QHideEvent *event)
  23. {
  24. QWidget::hideEvent(event);
  25. }
  26. void ExpertInfoWidget::setMode(ExpertInfoWidget::Mode mode)
  27. {
  28. m_mode = mode;
  29. updateState();
  30. }
  31. void ExpertInfoWidget::clearInputs()
  32. {
  33. m_idLineEdit->clear();
  34. m_passwordLineEdit->clear();
  35. m_nameLineEdit->clear();
  36. m_companyLineEdit->clear();
  37. m_jobLineEdit->clear();
  38. m_majorLineEdit->clear();
  39. m_contactInfoLineEdit->clear();
  40. m_timeLineEdit->clear();
  41. m_noteTextEdit->clear();
  42. }
  43. void ExpertInfoWidget::initWindow()
  44. {
  45. setMaximumWidth(400);
  46. setWindowFlags(Qt::Window);
  47. setWindowFlag(Qt::WindowMinMaxButtonsHint, false);
  48. }
  49. void ExpertInfoWidget::initialize()
  50. {
  51. int labelHeight = 35;
  52. int editWidth = 300;
  53. m_vBoxLayout = new QVBoxLayout(this);
  54. m_gridLayout = new QGridLayout();
  55. m_idLabel = new QLabel(this);
  56. m_idLabel->setText("账号ID:");
  57. m_idLabel->setFixedHeight(labelHeight);
  58. m_idLineEdit = new LineEdit(this);
  59. m_idLineEdit->setFixedWidth(editWidth);
  60. m_idLineEdit->setPlaceholderText("请输入a-z/A-Z/0-9数字字母组合");
  61. m_passwordLabel = new QLabel(this);
  62. m_passwordLabel->setText("用户密码:");
  63. m_passwordLabel->setFixedHeight(labelHeight);
  64. m_passwordLineEdit = new PasswordLineEdit(this);
  65. m_passwordLineEdit->setFixedWidth(editWidth);
  66. m_passwordLineEdit->setPlaceholderText("请输入密码");
  67. m_nameLabel = new QLabel(this);
  68. m_nameLabel->setText("专家名:");
  69. m_nameLabel->setFixedHeight(labelHeight);
  70. m_nameLineEdit = new LineEdit(this);
  71. m_nameLineEdit->setFixedWidth(editWidth);
  72. m_nameLineEdit->setPlaceholderText("请输入专家名");
  73. m_companyLabel = new QLabel(this);
  74. m_companyLabel->setText("单位:");
  75. m_companyLabel->setFixedHeight(labelHeight);
  76. m_companyLineEdit = new LineEdit(this);
  77. m_companyLineEdit->setFixedWidth(editWidth);
  78. m_jobLabel = new QLabel(this);
  79. m_jobLabel->setText("职务:");
  80. m_jobLabel->setFixedHeight(labelHeight);
  81. m_jobLineEdit = new LineEdit(this);
  82. m_jobLineEdit->setFixedWidth(editWidth);
  83. m_majorLabel = new QLabel(this);
  84. m_majorLabel->setText("专业:");
  85. m_majorLabel->setFixedHeight(labelHeight);
  86. m_majorLineEdit = new LineEdit(this);
  87. m_majorLineEdit->setFixedWidth(editWidth);
  88. m_contactInfoLabel = new QLabel(this);
  89. m_contactInfoLabel->setText("联系方式:");
  90. m_contactInfoLabel->setFixedHeight(labelHeight);
  91. m_contactInfoLineEdit = new LineEdit(this);
  92. m_contactInfoLineEdit->setFixedWidth(editWidth);
  93. m_timeLabel = new QLabel(this);
  94. m_timeLabel->setText("填写时间:");
  95. m_timeLabel->setFixedHeight(labelHeight);
  96. m_timeLineEdit = new DateTimeEdit(this);
  97. m_timeLineEdit->setFixedWidth(editWidth);
  98. m_noteLabel = new QLabel(this);
  99. m_noteLabel->setText("备注:");
  100. m_noteLabel->setFixedHeight(labelHeight);
  101. m_noteTextEdit = new TextEdit(this);
  102. m_noteTextEdit->setFixedWidth(editWidth);
  103. m_noteTextEdit->setFixedHeight(100);
  104. m_hBoxLayout = new QHBoxLayout();
  105. m_confirmButton = new PushButton("确认", this);
  106. m_cancelButton = new PushButton("取消", this);
  107. }
  108. void ExpertInfoWidget::initLayout()
  109. {
  110. m_vBoxLayout->setContentsMargins(20, 10, 20, 10);
  111. m_vBoxLayout->addLayout(m_gridLayout);
  112. m_gridLayout->addWidget(m_idLabel, 0, 0, 1, 1, Qt::AlignRight);
  113. m_gridLayout->addWidget(m_idLineEdit, 0, 1, 1, 2, Qt::AlignLeft);
  114. m_gridLayout->addWidget(m_passwordLabel, 1, 0, 1, 1, Qt::AlignRight);
  115. m_gridLayout->addWidget(m_passwordLineEdit, 1, 1, Qt::AlignLeft);
  116. m_gridLayout->addWidget(m_nameLabel, 2, 0, 1, 1, Qt::AlignRight);
  117. m_gridLayout->addWidget(m_nameLineEdit, 2, 1, 1, 1, Qt::AlignLeft);
  118. m_gridLayout->addWidget(m_companyLabel, 3, 0, 1, 1, Qt::AlignRight);
  119. m_gridLayout->addWidget(m_companyLineEdit, 3, 1, 1, 1, Qt::AlignLeft);
  120. m_gridLayout->addWidget(m_jobLabel, 4, 0, 1, 1, Qt::AlignRight);
  121. m_gridLayout->addWidget(m_jobLineEdit, 4, 1, 1, 1, Qt::AlignLeft);
  122. m_gridLayout->addWidget(m_majorLabel, 5, 0, 1, 1, Qt::AlignRight);
  123. m_gridLayout->addWidget(m_majorLineEdit, 5, 1, 1, 1, Qt::AlignLeft);
  124. m_gridLayout->addWidget(m_contactInfoLabel, 6, 0, 1, 1, Qt::AlignRight);
  125. m_gridLayout->addWidget(m_contactInfoLineEdit, 6, 1, 1, 1, Qt::AlignLeft);
  126. m_gridLayout->addWidget(m_timeLabel, 7, 0, 1, 1, Qt::AlignRight);
  127. m_gridLayout->addWidget(m_timeLineEdit, 7, 1, 1, 1, Qt::AlignLeft);
  128. m_gridLayout->addWidget(m_noteLabel, 8, 0, 1, 1, Qt::AlignRight | Qt::AlignTop);
  129. m_gridLayout->addWidget(m_noteTextEdit, 8, 1, 1, 1, Qt::AlignLeft);
  130. m_vBoxLayout->addStretch();
  131. m_vBoxLayout->addLayout(m_hBoxLayout);
  132. m_hBoxLayout->addStretch();
  133. m_hBoxLayout->addWidget(m_confirmButton);
  134. m_hBoxLayout->addWidget(m_cancelButton);
  135. }
  136. void ExpertInfoWidget::connectSignalsAndSlots()
  137. {
  138. connect(m_confirmButton, &PushButton::clicked, this, &ExpertInfoWidget::slotConfirm);
  139. connect(m_cancelButton, &PushButton::clicked, this, &ExpertInfoWidget::slotCancel);
  140. }
  141. void ExpertInfoWidget::updateState()
  142. {
  143. int h = height();
  144. QString t = windowTitle();
  145. switch (m_mode) {
  146. case Add: {
  147. t = "添加用户";
  148. h = 300;
  149. break;
  150. }
  151. case Update: {
  152. t = "修改用户信息";
  153. h = 300;
  154. break;
  155. }
  156. case Read: {
  157. t = "用户信息";
  158. h = 450;
  159. break;
  160. }
  161. }
  162. setMaximumHeight(h);
  163. setWindowTitle(t);
  164. setEditable(m_mode != Read);
  165. setDetailsHideen(m_mode == Add);
  166. // update();
  167. repaint();
  168. }
  169. void ExpertInfoWidget::setDetailsHideen(bool hidden)
  170. {
  171. m_companyLabel->setHidden(hidden);
  172. m_companyLineEdit->setHidden(hidden);
  173. m_jobLabel->setHidden(hidden);
  174. m_jobLineEdit->setHidden(hidden);
  175. m_majorLabel->setHidden(hidden);
  176. m_majorLineEdit->setHidden(hidden);
  177. m_contactInfoLabel->setHidden(hidden);
  178. m_contactInfoLineEdit->setHidden(hidden);
  179. }
  180. void ExpertInfoWidget::setEditable(bool editable)
  181. {
  182. m_idLineEdit->setReadOnly(!editable);
  183. m_passwordLineEdit->setReadOnly(!editable);
  184. m_nameLineEdit->setReadOnly(!editable);
  185. m_companyLineEdit->setReadOnly(!editable);
  186. m_jobLineEdit->setReadOnly(!editable);
  187. m_majorLineEdit->setReadOnly(!editable);
  188. m_idLineEdit->setReadOnly(!editable);
  189. m_contactInfoLineEdit->setReadOnly(!editable);
  190. m_timeLineEdit->setReadOnly(!editable);
  191. m_noteTextEdit->setReadOnly(!editable);
  192. m_confirmButton->setHidden(!editable);
  193. m_cancelButton->setHidden(!editable);
  194. }
  195. void ExpertInfoWidget::slotConfirm()
  196. {
  197. close();
  198. }
  199. void ExpertInfoWidget::slotCancel()
  200. {
  201. close();
  202. }