ExpertInfoWidget.cpp 7.1 KB

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