#include "HomeView.h" #include "CreateProjWidget.h" #include "ProjectStateWidget.h" #include "ProjectManager.h" #include "QFDAlert.h" #include "QFDIcon.h" #include "ProjectListWidget.h" #include #include #include #include #include HomeView::HomeView(QWidget *parent) : QWidget(parent) { } void HomeView::showEvent(QShowEvent *event) { if (m_initilized == false) { initWidgets(); initLayout(); connectSignalsAndSlots(); m_initilized = true; } QWidget::showEvent(event); loadProjects(); } void HomeView::hideEvent(QHideEvent *event) { QWidget::hideEvent(event); } void HomeView::initWidgets() { m_title = new QLabel(this); m_title->setText("项目列表"); QFont ft("Microsoft YaHei", 12); m_title->setFont(ft); m_create = new PushButton("新建", NEWFLICON(FluentIcon, ADD), this); m_create->setToolTip("新建项目"); m_search = new LineEdit(this); m_search->setIsClearButtonEnabled(true); m_search->setPlaceholderText("输入项目名搜索"); m_search->setMinimumWidth(300); m_filter = new PushButton("筛选", NEWFLICON(QFDIcon, Filter), this); m_filter->setToolTip("筛选项目"); m_projListWidget = new ProjectListWidget(this); m_createProjWidget = new CreateProjWidget(this); } void HomeView::initLayout() { // 总体布局 m_layout = new QVBoxLayout(this); m_layout->setAlignment(Qt::AlignTop | Qt::AlignLeft); m_layout->setContentsMargins(15, 10, 10, 15); m_topLayout = new QHBoxLayout(); m_layout->addLayout(m_topLayout); m_layout->addWidget(m_projListWidget); // 顶部布局 m_topLayout->addWidget(m_title); m_topLayout->addSpacing(15); m_topLayout->addWidget(m_create, 1, Qt::AlignLeft); m_topLayout->addWidget(m_search, 0, Qt::AlignLeft); m_topLayout->addStretch(); m_topLayout->addWidget(m_filter); } void HomeView::connectSignalsAndSlots() { connect(m_create, &PushButton::clicked, this, &HomeView::slotCreateProjClicked); connect(m_search, &LineEdit::textChanged, this, &HomeView::slotSearchTextChanged); connect(m_createProjWidget, &CreateProjWidget::signalCreate, this, &HomeView::slotConfirmCreate); } void HomeView::loadProjects() { qDeleteAll(m_projList); m_projList.clear(); int code = ProjectManager::queryProjects(&m_projList); if (code != QF_CODE_SUCCEEDED) { QFDAlert::showAlertWithCode(code, this); return; } m_projListWidget->showProjects(searchResult()); } QList HomeView::searchResult() const { QList list; for (ProjectInfo *proj : m_projList) { if (proj->projectName.contains(m_search->text())) { list.append(proj); } } return list; } void HomeView::slotCreateProjClicked() { if (m_createProjWidget->isVisible() == false) { m_createProjWidget->resetInputs(); m_createProjWidget->show(); } } void HomeView::slotSearchTextChanged() { m_projListWidget->showProjects(searchResult()); } void HomeView::slotConfirmCreate() { ProjectInfo info = m_createProjWidget->projectInfo(); }