ExpertListWidget.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #include "ExpertListWidget.h"
  2. #include <dbService/ClassSet.h>
  3. #include <Common/Icon.h>
  4. #include <QBoxLayout>
  5. #include <QListWidget>
  6. #include <QLabel>
  7. #include <QDebug>
  8. ExpertListWidget::ExpertListWidget(QWidget *parent) : QWidget(parent)
  9. {
  10. initialize();
  11. initLayout();
  12. connectSignalsAndSlots();
  13. }
  14. void ExpertListWidget::showUsers(const QList<QFUser *> &list)
  15. {
  16. m_listWidget->clear();
  17. for (int i = 0; i < list.count(); i++) {
  18. QListWidgetItem *item = new QListWidgetItem;
  19. item->setSizeHint(QSize(200, 60));
  20. m_listWidget->addItem(item);
  21. QWidget *w = new QWidget();
  22. m_listWidget->setItemWidget(item, w);
  23. QHBoxLayout *hBox = new QHBoxLayout(w);
  24. hBox->setSpacing(0);
  25. hBox->setMargin(10);
  26. QLabel *idx = new QLabel(QString::number(i + 1));
  27. idx->setFixedWidth(20);
  28. hBox->addWidget(idx);
  29. hBox->addSpacing(10);
  30. QLabel *name = new QLabel(list[i]->userName);
  31. hBox->addWidget(name);
  32. hBox->addStretch();
  33. QLabel *time = new QLabel(list[i]->writeTime);
  34. hBox->addWidget(time);
  35. }
  36. }
  37. bool ExpertListWidget::hasSelectedItem() const
  38. {
  39. return m_listWidget->selectedItems().count() > 0;
  40. }
  41. int ExpertListWidget::selectedRow() const
  42. {
  43. QListWidgetItem *item = m_listWidget->selectedItems().first();
  44. return m_listWidget->row(item);
  45. }
  46. void ExpertListWidget::clearSelection()
  47. {
  48. m_listWidget->clearSelection();
  49. }
  50. void ExpertListWidget::initialize()
  51. {
  52. m_vBoxLayout = new QVBoxLayout(this);
  53. m_listWidget = new QListWidget(this);
  54. m_listWidget->setAlternatingRowColors(true);
  55. m_listWidget->setStyleSheet("QListWidget {border: 1px solid rgba(0, 0, 0, 0.073);background: rgb(255, 255, "
  56. "255);alternate-background-color: rgb(244, 244, 255);}");
  57. }
  58. void ExpertListWidget::initLayout()
  59. {
  60. m_vBoxLayout->addWidget(m_listWidget);
  61. }
  62. void ExpertListWidget::connectSignalsAndSlots()
  63. {
  64. connect(m_listWidget, &QListWidget::itemDoubleClicked, this, &ExpertListWidget::slotItemDoubleClicked);
  65. connect(m_listWidget, &QListWidget::itemClicked, this, &ExpertListWidget::slotItemClicked);
  66. connect(m_listWidget, &QListWidget::currentItemChanged, this, &ExpertListWidget::slotCurrentItemChanged);
  67. connect(m_listWidget, &QListWidget::currentRowChanged, this, &ExpertListWidget::slotCurrentRowChanged);
  68. connect(m_listWidget, &QListWidget::itemSelectionChanged, this, &ExpertListWidget::slotItemSelectionChanged);
  69. }
  70. void ExpertListWidget::slotItemDoubleClicked(QListWidgetItem *item)
  71. {
  72. emit siganlItemDoubleClicked(m_listWidget->row(item));
  73. }
  74. void ExpertListWidget::slotItemClicked(QListWidgetItem *)
  75. {
  76. qDebug() << __FUNCTION__ << __LINE__;
  77. }
  78. void ExpertListWidget::slotCurrentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
  79. {
  80. qDebug() << __FUNCTION__ << __LINE__ << current << previous;
  81. }
  82. void ExpertListWidget::slotCurrentRowChanged(int currentRow)
  83. {
  84. qDebug() << __FUNCTION__ << __LINE__ << currentRow;
  85. }
  86. void ExpertListWidget::slotItemSelectionChanged()
  87. {
  88. qDebug() << __FUNCTION__ << __LINE__ << m_listWidget->selectedItems();
  89. emit signalSelectionChanged();
  90. }