ExpertManageView.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #include "ExpertManageView.h"
  2. #include "QFDIcon.h"
  3. #include "MainWindow.h"
  4. #include "ExpertInfoWidget.h"
  5. #include "ExpertListWidget.h"
  6. #include <Widgets/Button.h>
  7. #include <Widgets/LineEdit.h>
  8. #include <DialogBox/Dialog.h>
  9. #include <QBoxLayout>
  10. #include <QLabel>
  11. #include <QDebug>
  12. ExpertManageView::ExpertManageView(QWidget *parent) : QWidget(parent)
  13. {
  14. initialize();
  15. initLayout();
  16. connectSignalsAndSlots();
  17. }
  18. void ExpertManageView::initialize()
  19. {
  20. m_vBoxLayout = new QVBoxLayout(this);
  21. m_titleLabel = new QLabel(this);
  22. m_titleLabel->setText("专家列表");
  23. QFont ft("Microsoft YaHei", 12);
  24. m_titleLabel->setFont(ft);
  25. m_hBoxLayout = new QHBoxLayout();
  26. m_searchLineEdit = new SearchLineEdit(this);
  27. m_searchLineEdit->setPlaceholderText("搜索");
  28. m_searchLineEdit->setMinimumWidth(300);
  29. m_addExpertButton = new PushButton("添加", NEWFLICON(FluentIcon, ADD), this);
  30. m_detailButton = new ToolButton(NEWFLICON(QFDIcon, Detail), this);
  31. m_detailButton->setToolTip("详细信息");
  32. m_deleteButton = new ToolButton(NEWFLICON(FluentIcon, DELETE), this);
  33. m_deleteButton->setToolTip("删除用户");
  34. m_expertInfoWidget = new ExpertInfoWidget(this);
  35. m_expertListWidget = new ExpertListWidget(this);
  36. }
  37. void ExpertManageView::initLayout()
  38. {
  39. m_vBoxLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
  40. m_vBoxLayout->setContentsMargins(15, 10, 10, 15);
  41. m_vBoxLayout->addLayout(m_hBoxLayout);
  42. m_hBoxLayout->setContentsMargins(10, 0, 10, 0);
  43. m_hBoxLayout->addWidget(m_titleLabel);
  44. m_hBoxLayout->addSpacing(15);
  45. m_hBoxLayout->addWidget(m_searchLineEdit, 0, Qt::AlignLeft);
  46. m_hBoxLayout->addWidget(m_addExpertButton, 1, Qt::AlignLeft);
  47. m_hBoxLayout->addStretch();
  48. m_hBoxLayout->addWidget(m_detailButton);
  49. m_hBoxLayout->addWidget(m_deleteButton);
  50. setListButtonHidden(true);
  51. m_vBoxLayout->addWidget(m_expertListWidget);
  52. }
  53. void ExpertManageView::connectSignalsAndSlots()
  54. {
  55. connect(m_addExpertButton, &PushButton::clicked, this, &ExpertManageView::slotAddExpertClicked);
  56. connect(m_detailButton, &PushButton::clicked, this, &ExpertManageView::slotDetailClicked);
  57. connect(m_deleteButton, &PushButton::clicked, this, &ExpertManageView::slotDeleteClicked);
  58. connect(m_expertListWidget, &ExpertListWidget::signalSelectionChanged, this,
  59. &ExpertManageView::slotListSelectionChanged);
  60. connect(m_expertListWidget, &ExpertListWidget::siganlItemDoubleClicked, this,
  61. &ExpertManageView::slotListItemDoubleClicked);
  62. }
  63. void ExpertManageView::setListButtonHidden(bool hidden)
  64. {
  65. m_detailButton->setHidden(hidden);
  66. m_deleteButton->setHidden(hidden);
  67. }
  68. void ExpertManageView::showExpertInfo()
  69. {
  70. if (m_expertInfoWidget->isVisible() == false) {
  71. m_expertInfoWidget->clearInputs();
  72. m_expertInfoWidget->show();
  73. }
  74. }
  75. void ExpertManageView::slotAddExpertClicked()
  76. {
  77. m_expertInfoWidget->setMode(ExpertInfoWidget::Add);
  78. showExpertInfo();
  79. }
  80. void ExpertManageView::slotDetailClicked()
  81. {
  82. m_expertInfoWidget->setMode(ExpertInfoWidget::Read);
  83. showExpertInfo();
  84. }
  85. void ExpertManageView::slotDeleteClicked()
  86. {
  87. MessageBox *m = new MessageBox("删除专家信息", "删除后不可恢复,确认删除?", topLevelWidget());
  88. m->exec();
  89. }
  90. void ExpertManageView::slotListSelectionChanged()
  91. {
  92. setListButtonHidden(!m_expertListWidget->isItemSelected());
  93. }
  94. void ExpertManageView::slotListItemDoubleClicked()
  95. {
  96. m_expertInfoWidget->setMode(ExpertInfoWidget::Read);
  97. showExpertInfo();
  98. }