HomeView.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include "HomeView.h"
  2. #include "CreateProjWidget.h"
  3. #include "ProjectStateWidget.h"
  4. #include <Widgets/Button.h>
  5. #include <Widgets/LineEdit.h>
  6. #include <QBoxLayout>
  7. #include <QLabel>
  8. #include <QDebug>
  9. HomeView::HomeView(QWidget *parent) : QWidget(parent) { }
  10. void HomeView::showEvent(QShowEvent *event)
  11. {
  12. qDebug() << __FUNCTION__ << __LINE__;
  13. if (m_initilized == false) {
  14. initialize();
  15. initLayout();
  16. connectSignalsAndSlots();
  17. m_initilized = true;
  18. }
  19. QWidget::showEvent(event);
  20. }
  21. void HomeView::hideEvent(QHideEvent *event)
  22. {
  23. qDebug() << __FUNCTION__ << __LINE__;
  24. QWidget::hideEvent(event);
  25. }
  26. void HomeView::initialize()
  27. {
  28. m_vBoxLayout = new QVBoxLayout(this);
  29. m_titleLabel = new QLabel(this);
  30. m_titleLabel->setText("工程列表");
  31. QFont ft("Microsoft YaHei", 12);
  32. m_titleLabel->setFont(ft);
  33. m_hBoxLayout = new QHBoxLayout();
  34. m_searchLineEdit = new SearchLineEdit(this);
  35. m_searchLineEdit->setPlaceholderText("搜索工程");
  36. m_searchLineEdit->setMinimumWidth(300);
  37. m_createProjPushButton = new PushButton("新建工程", NEWFLICON(FluentIcon, ADD), this);
  38. m_projStateWidget = new ProjectStateWidget(this);
  39. m_createProjWidget = new CreateProjWidget(this);
  40. }
  41. void HomeView::initLayout()
  42. {
  43. m_vBoxLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
  44. m_vBoxLayout->setContentsMargins(15, 10, 10, 15);
  45. m_vBoxLayout->addLayout(m_hBoxLayout);
  46. m_hBoxLayout->addWidget(m_titleLabel);
  47. m_hBoxLayout->addSpacing(15);
  48. m_hBoxLayout->addWidget(m_searchLineEdit, 0, Qt::AlignLeft);
  49. m_hBoxLayout->addWidget(m_createProjPushButton, 1, Qt::AlignLeft);
  50. m_vBoxLayout->addWidget(m_projStateWidget);
  51. }
  52. void HomeView::connectSignalsAndSlots()
  53. {
  54. connect(m_createProjPushButton, &PushButton::clicked, this, &HomeView::slotCreateProjClicked);
  55. }
  56. void HomeView::slotCreateProjClicked()
  57. {
  58. if (m_createProjWidget->isVisible() == false) {
  59. m_createProjWidget->clearInputs();
  60. m_createProjWidget->show();
  61. }
  62. }