#include "ProjectListWidget.h" #include "QFDIcon.h" #include "ProjectManager.h" #include "dbService/ClassSet.h" #include #include #include #include #include #include #include #include ProjectListItemWidget::ProjectListItemWidget(QWidget *parent) : QWidget(parent) { initWidgets(); initLayout(); connectSignalsAndSlots(); } void ProjectListItemWidget::initWidgets() { m_name = new QLabel(this); m_name->setObjectName("name"); m_time = new QLabel(this); m_time->setObjectName("time"); m_taskLabel = new QLabel(this); m_taskLabel->setObjectName("taskLabel"); m_taskLabel->setText("任务名称:"); m_task = new QLabel(this); m_task->setObjectName("task"); m_typeLabel = new QLabel(this); m_typeLabel->setObjectName("typeLabel"); m_typeLabel->setText("评估类型:"); m_type = new QLabel(this); m_type->setObjectName("type"); m_info = new PushButton("详情", NEWFLICON(FluentIcon, INFO), this); m_info->setObjectName("info"); m_open = new PushButton("打开", NEWFLICON(QFDIcon, Open), this); m_open->setObjectName("open"); m_delete = new PushButton("删除", NEWFLICON(FluentIcon, DELETE), this); m_delete->setObjectName("delete"); m_export = new PushButton("导出资源包", NEWFLICON(FluentIcon, SHARE), this); m_export->setObjectName("export"); setStyleSheet("#name {color:#1196db; font-size:17px; font:bold}" "#time {color:gray; font-size:12px;}" "#taskLabel {color: gray; font-size:14px;}" "#task {color: gray; font-size:14px;}" "#typeLabel {color: gray; font-size:14px;}" "#type {color: gray; font-size:14px;}"); } void ProjectListItemWidget::initLayout() { // 总体布局 m_layout = new QVBoxLayout(this); m_layout->setMargin(10); m_nameLayout = new QHBoxLayout(); m_layout->addLayout(m_nameLayout); m_layout->addSpacing(5); m_taskLayout = new QHBoxLayout(); m_layout->addLayout(m_taskLayout); m_typeLayout = new QHBoxLayout(); m_layout->addLayout(m_typeLayout); m_buttonLayout = new QHBoxLayout(); m_layout->addLayout(m_buttonLayout); // 名称 m_nameLayout->addWidget(m_name); m_nameLayout->addStretch(); m_nameLayout->addWidget(m_time); // 任务 m_taskLayout->setContentsMargins(10, 0, 10, 0); m_taskLayout->addWidget(m_taskLabel); m_taskLayout->addSpacing(5); m_taskLayout->addWidget(m_task); m_taskLayout->addStretch(); // 类型 m_typeLayout->setContentsMargins(10, 0, 10, 0); m_typeLayout->addWidget(m_typeLabel); m_typeLayout->addSpacing(5); m_typeLayout->addWidget(m_type); m_typeLayout->addStretch(); // 按钮 m_buttonLayout->addStretch(); m_buttonLayout->addWidget(m_info); m_buttonLayout->addWidget(m_open); m_buttonLayout->addWidget(m_delete); m_buttonLayout->addWidget(m_export); } void ProjectListItemWidget::connectSignalsAndSlots() { connect(m_info, &PushButton::clicked, this, &ProjectListItemWidget::sigInfo); connect(m_open, &PushButton::clicked, this, &ProjectListItemWidget::sigOpen); connect(m_delete, &PushButton::clicked, this, &ProjectListItemWidget::sigDelete); connect(m_export, &PushButton::clicked, this, &ProjectListItemWidget::sigExport); } void ProjectListItemWidget::setProj(ProjectInfo *info) { m_proj = info; if (info == nullptr) { return; } m_name->setText(info->projectName); QDateTime t = QDateTime::fromTime_t(info->estimateTime.toUInt()); m_time->setText(t.toString("yyyy-M-d H:mm")); m_task->setText(info->taskName); QString tStr; QList types = ProjectManager::evalTypeList(*info); for (int i = 0; i < types.count(); i++) { tStr += ProjectManager::nameOfEvalType(types[i]); if (i < types.count() - 1) { tStr += "、"; } } m_type->setText(tStr); } ProjectInfo *ProjectListItemWidget::proj() const { return m_proj; } ProjectListWidget::ProjectListWidget(QWidget *parent) : QWidget(parent) { initWidgets(); initLayout(); connectSiganlsAndSlots(); } void ProjectListWidget::setProjects(QList list) { m_projList.clear(); m_listWidget->clear(); for (auto proj : list) { addProject(proj); } } void ProjectListWidget::showLast() const { if (m_projList.count() > 0) { m_listWidget->setCurrentRow(m_projList.count() - 1); } } void ProjectListWidget::addProject(ProjectInfo *proj) { m_projList.append(proj); ProjectListItemWidget *w = new ProjectListItemWidget(m_listWidget); w->setProj(proj); connect(w, &ProjectListItemWidget::sigInfo, this, &ProjectListWidget::slotInfo); connect(w, &ProjectListItemWidget::sigOpen, this, &ProjectListWidget::slotOpen); connect(w, &ProjectListItemWidget::sigDelete, this, &ProjectListWidget::slotDelete); connect(w, &ProjectListItemWidget::sigExport, this, &ProjectListWidget::slotExport); QListWidgetItem *item = new QListWidgetItem(m_listWidget); item->setSizeHint(QSize(300, 135)); m_listWidget->setItemWidget(item, w); } void ProjectListWidget::removeProject(ProjectInfo *proj) { int index = m_projList.indexOf(proj); qDebug() << __FUNCTION__ << __LINE__ << "index:" << index << endl; m_listWidget->takeItem(index); } ProjectListItemWidget *ProjectListWidget::widgetOfItem(QListWidgetItem *item) const { QWidget *w = m_listWidget->itemWidget(item); return dynamic_cast(w); } QListWidgetItem *ProjectListWidget::itemOfWidget(ProjectListItemWidget *widget) const { for (int i = 0; i < m_listWidget->count(); i++) { QListWidgetItem *item = m_listWidget->item(i); if (m_listWidget->itemWidget(item) == widget) { return item; } } return nullptr; } void ProjectListWidget::initWidgets() { QPalette pal(palette()); pal.setColor(QPalette::Background, QColor("#eeeeee")); setAutoFillBackground(true); setPalette(pal); m_vBoxLayout = new QVBoxLayout(this); m_listWidget = new QListWidget(this); m_listWidget->setAlternatingRowColors(true); m_listWidget->setStyleSheet("QListWidget {border: 1px solid rgba(0, 0, 0, 0.073);background: rgb(255, 255, " "255);alternate-background-color: rgb(233, 233, 244);}"); } void ProjectListWidget::initLayout() { m_vBoxLayout->setMargin(0); m_vBoxLayout->addWidget(m_listWidget); } void ProjectListWidget::connectSiganlsAndSlots() { connect(m_listWidget, &QListWidget::itemDoubleClicked, this, &ProjectListWidget::slotItemDoubleClicked); connect(m_listWidget, &QListWidget::itemClicked, this, &ProjectListWidget::slotItemClicked); connect(m_listWidget, &QListWidget::currentItemChanged, this, &ProjectListWidget::slotCurrentItemChanged); connect(m_listWidget, &QListWidget::currentRowChanged, this, &ProjectListWidget::slotCurrentRowChanged); connect(m_listWidget, &QListWidget::itemSelectionChanged, this, &ProjectListWidget::slotItemSelectionChanged); } void ProjectListWidget::slotItemDoubleClicked(QListWidgetItem *item) { ProjectListItemWidget *w = dynamic_cast(m_listWidget->itemWidget(item)); emit sigInfo(w->proj()); } void ProjectListWidget::slotItemClicked(QListWidgetItem *item) { } void ProjectListWidget::slotCurrentItemChanged(QListWidgetItem *current, QListWidgetItem *previous) { } void ProjectListWidget::slotCurrentRowChanged(int currentRow) { } void ProjectListWidget::slotItemSelectionChanged() { } void ProjectListWidget::slotInfo() { ProjectListItemWidget *w = dynamic_cast(sender()); itemOfWidget(w)->setSelected(true); emit sigInfo(w->proj()); } void ProjectListWidget::slotOpen() { ProjectListItemWidget *w = dynamic_cast(sender()); itemOfWidget(w)->setSelected(true); emit sigOpen(w->proj()); } void ProjectListWidget::slotDelete() { ProjectListItemWidget *w = dynamic_cast(sender()); itemOfWidget(w)->setSelected(true); emit sigDelete(w->proj()); } void ProjectListWidget::slotExport() { ProjectListItemWidget *w = dynamic_cast(sender()); itemOfWidget(w)->setSelected(true); emit sigExport(w->proj()); }