123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- #include "HomeView.h"
- #include "CreateProjWidget.h"
- #include "ProjectStateWidget.h"
- #include "ProjectManager.h"
- #include "QFDAlert.h"
- #include "QFDIcon.h"
- #include "ProjectListWidget.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) {
- 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<ProjectInfo *> HomeView::searchResult() const
- {
- QList<ProjectInfo *> 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();
- }
|