ProjectListWidget.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #include "ProjectListWidget.h"
  2. #include "QFDIcon.h"
  3. #include "ProjectManager.h"
  4. #include "dbService/ClassSet.h"
  5. #include <Widgets/LineEdit.h>
  6. #include <Widgets/Button.h>
  7. #include <Widgets/TreeView.h>
  8. #include <QBoxLayout>
  9. #include <QListWidget>
  10. #include <QLabel>
  11. #include <QDateTime>
  12. #include <QDebug>
  13. ProjectListItemWidget::ProjectListItemWidget(QWidget *parent) : QWidget(parent)
  14. {
  15. initWidgets();
  16. initLayout();
  17. }
  18. void ProjectListItemWidget::initWidgets()
  19. {
  20. m_name = new QLabel(this);
  21. m_name->setObjectName("name");
  22. m_time = new QLabel(this);
  23. m_time->setObjectName("time");
  24. m_taskLabel = new QLabel(this);
  25. m_taskLabel->setObjectName("taskLabel");
  26. m_taskLabel->setText("任务名称:");
  27. m_task = new QLabel(this);
  28. m_task->setObjectName("task");
  29. m_typeLabel = new QLabel(this);
  30. m_typeLabel->setObjectName("typeLabel");
  31. m_typeLabel->setText("评估类型:");
  32. m_type = new QLabel(this);
  33. m_type->setObjectName("type");
  34. m_open = new PushButton("打开", NEWFLICON(QFDIcon, Open), this);
  35. m_open->setObjectName("open");
  36. m_edit = new PushButton("编辑", NEWFLICON(FluentIcon, EDIT), this);
  37. m_edit->setObjectName("edit");
  38. setStyleSheet("#name {color:#1196db; font-size:15px; font:bold}"
  39. "#time {color:gray}"
  40. "#taskLabel {color: gray;}"
  41. "#task {color: gray;}"
  42. "#typeLabel {color: gray;}"
  43. "#type {color: gray;}");
  44. }
  45. void ProjectListItemWidget::initLayout()
  46. {
  47. // 总体布局
  48. m_layout = new QVBoxLayout(this);
  49. m_layout->setMargin(10);
  50. m_nameLayout = new QHBoxLayout();
  51. m_layout->addLayout(m_nameLayout);
  52. m_layout->addSpacing(5);
  53. m_taskLayout = new QHBoxLayout();
  54. m_layout->addLayout(m_taskLayout);
  55. m_typeLayout = new QHBoxLayout();
  56. m_layout->addLayout(m_typeLayout);
  57. m_buttonLayout = new QHBoxLayout();
  58. m_layout->addLayout(m_buttonLayout);
  59. // 名称
  60. m_nameLayout->addWidget(m_name);
  61. m_nameLayout->addStretch();
  62. m_nameLayout->addWidget(m_time);
  63. // 任务
  64. m_taskLayout->setContentsMargins(10, 0, 10, 0);
  65. m_taskLayout->addWidget(m_taskLabel);
  66. m_taskLayout->addSpacing(5);
  67. m_taskLayout->addWidget(m_task);
  68. m_taskLayout->addStretch();
  69. // 类型
  70. m_typeLayout->setContentsMargins(10, 0, 10, 0);
  71. m_typeLayout->addWidget(m_typeLabel);
  72. m_typeLayout->addSpacing(5);
  73. m_typeLayout->addWidget(m_type);
  74. m_typeLayout->addStretch();
  75. // 按钮
  76. m_buttonLayout->addStretch();
  77. m_buttonLayout->addWidget(m_open);
  78. m_buttonLayout->addWidget(m_edit);
  79. }
  80. void ProjectListItemWidget::setData(ProjectInfo *info)
  81. {
  82. m_info = info;
  83. if (info == nullptr) {
  84. return;
  85. }
  86. m_name->setText(info->projectName);
  87. QDateTime t = QDateTime::fromTime_t(info->estimateTime.toUInt());
  88. m_time->setText(t.toString("yyyy-M-d"));
  89. m_task->setText(info->taskName);
  90. QString tStr;
  91. QList<ProjectManager::EvalType> types = ProjectManager::evalTypeList(*info);
  92. for (int i = 0; i < types.count(); i++) {
  93. tStr += ProjectManager::nameOfEvalType(types[i]);
  94. if (i < types.count() - 1) {
  95. tStr += "、";
  96. }
  97. }
  98. m_type->setText(tStr);
  99. }
  100. ProjectListWidget::ProjectListWidget(QWidget *parent) : QWidget(parent)
  101. {
  102. initWidgets();
  103. initLayout();
  104. connectSiganlsAndSlots();
  105. }
  106. void ProjectListWidget::showProjects(QList<ProjectInfo *> list)
  107. {
  108. m_listWidget->clear();
  109. for (ProjectInfo *info : list) {
  110. ProjectListItemWidget *w = new ProjectListItemWidget(m_listWidget);
  111. w->setData(info);
  112. QListWidgetItem *item = new QListWidgetItem(m_listWidget);
  113. item->setSizeHint(QSize(300, 135));
  114. m_listWidget->setItemWidget(item, w);
  115. }
  116. }
  117. void ProjectListWidget::initWidgets()
  118. {
  119. QPalette pal(palette());
  120. pal.setColor(QPalette::Background, QColor("#eeeeee"));
  121. setAutoFillBackground(true);
  122. setPalette(pal);
  123. m_vBoxLayout = new QVBoxLayout(this);
  124. m_listWidget = new QListWidget(this);
  125. m_listWidget->setAlternatingRowColors(true);
  126. m_listWidget->setStyleSheet("QListWidget {border: 1px solid rgba(0, 0, 0, 0.073);background: rgb(255, 255, "
  127. "255);alternate-background-color: rgb(244, 244, 255);}");
  128. }
  129. void ProjectListWidget::initLayout()
  130. {
  131. m_vBoxLayout->setMargin(0);
  132. m_vBoxLayout->addWidget(m_listWidget);
  133. }
  134. void ProjectListWidget::connectSiganlsAndSlots()
  135. {
  136. connect(m_listWidget, &QListWidget::itemDoubleClicked, this, &ProjectListWidget::slotItemDoubleClicked);
  137. connect(m_listWidget, &QListWidget::itemClicked, this, &ProjectListWidget::slotItemClicked);
  138. connect(m_listWidget, &QListWidget::currentItemChanged, this, &ProjectListWidget::slotCurrentItemChanged);
  139. connect(m_listWidget, &QListWidget::currentRowChanged, this, &ProjectListWidget::slotCurrentRowChanged);
  140. connect(m_listWidget, &QListWidget::itemSelectionChanged, this, &ProjectListWidget::slotItemSelectionChanged);
  141. }
  142. void ProjectListWidget::slotItemDoubleClicked(QListWidgetItem *item)
  143. {
  144. qDebug() << __FUNCTION__ << __LINE__;
  145. }
  146. void ProjectListWidget::slotItemClicked(QListWidgetItem *item)
  147. {
  148. qDebug() << __FUNCTION__ << __LINE__;
  149. }
  150. void ProjectListWidget::slotCurrentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
  151. {
  152. qDebug() << __FUNCTION__ << __LINE__;
  153. }
  154. void ProjectListWidget::slotCurrentRowChanged(int currentRow)
  155. {
  156. qDebug() << __FUNCTION__ << __LINE__;
  157. }
  158. void ProjectListWidget::slotItemSelectionChanged()
  159. {
  160. qDebug() << __FUNCTION__ << __LINE__;
  161. }