123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- #include "HomeView.h"
- #include "CreateProjWidget.h"
- #include "ProjectStateWidget.h"
- #include "ProjectManager.h"
- #include "QFDAlert.h"
- #include <Widgets/Button.h>
- #include <Widgets/LineEdit.h>
- #include <QBoxLayout>
- #include <QLabel>
- #include <QDebug>
- HomeView::HomeView(QWidget *parent) : QWidget(parent) { }
- void HomeView::showEvent(QShowEvent *event)
- {
- if (m_initilized == false) {
- initialize();
- initLayout();
- connectSignalsAndSlots();
- m_initilized = true;
- }
- QWidget::showEvent(event);
- refreshTable();
- }
- void HomeView::hideEvent(QHideEvent *event)
- {
- QWidget::hideEvent(event);
- }
- void HomeView::initialize()
- {
- m_vBoxLayout = new QVBoxLayout(this);
- m_titleLabel = new QLabel(this);
- m_titleLabel->setText("工程列表");
- QFont ft("Microsoft YaHei", 12);
- m_titleLabel->setFont(ft);
- m_hBoxLayout = new QHBoxLayout();
- m_searchLineEdit = new LineEdit(this);
- m_searchLineEdit->setIsClearButtonEnabled(true);
- m_searchLineEdit->setPlaceholderText("输入工程名搜索");
- m_searchLineEdit->setMinimumWidth(300);
- m_createProjPushButton = new PushButton("新建工程", NEWFLICON(FluentIcon, ADD), this);
- m_projStateWidget = new ProjectStateWidget(this);
- m_createProjWidget = new CreateProjWidget(this);
- }
- void HomeView::initLayout()
- {
- m_vBoxLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
- m_vBoxLayout->setContentsMargins(15, 10, 10, 15);
- m_vBoxLayout->addLayout(m_hBoxLayout);
- m_hBoxLayout->addWidget(m_titleLabel);
- m_hBoxLayout->addSpacing(15);
- m_hBoxLayout->addWidget(m_searchLineEdit, 0, Qt::AlignLeft);
- m_hBoxLayout->addWidget(m_createProjPushButton, 1, Qt::AlignLeft);
- m_vBoxLayout->addWidget(m_projStateWidget);
- }
- void HomeView::connectSignalsAndSlots()
- {
- connect(m_createProjPushButton, &PushButton::clicked, this, &HomeView::slotCreateProjClicked);
- connect(m_searchLineEdit, &LineEdit::textChanged, this, &HomeView::slotSearchTextChanged);
- }
- void HomeView::refreshTable()
- {
- qDeleteAll(m_projList);
- m_projList.clear();
- int code = ProjectManager::queryProjects(&m_projList);
- if (code != QF_CODE_SUCCEEDED) {
- QFDAlert::showAlertWithCode(code, this);
- return;
- }
- m_projStateWidget->showProjects(searchResult());
- }
- QList<ProjectInfo *> HomeView::searchResult() const
- {
- QList<ProjectInfo *> list;
- for (ProjectInfo *proj : m_projList) {
- if (proj->projectName.contains(m_searchLineEdit->text())) {
- list.append(proj);
- }
- }
- return list;
- }
- void HomeView::slotCreateProjClicked()
- {
- if (m_createProjWidget->isVisible() == false) {
- m_createProjWidget->clearInputs();
- m_createProjWidget->show();
- }
- }
- void HomeView::slotSearchTextChanged()
- {
- m_projStateWidget->showProjects(searchResult());
- }
|