123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- #include "ExpertListWidget.h"
- #include <dbService/ClassSet.h>
- #include <Common/Icon.h>
- #include <QBoxLayout>
- #include <QListWidget>
- #include <QLabel>
- #include <QDebug>
- ExpertListWidget::ExpertListWidget(QWidget *parent) : QWidget(parent)
- {
- initialize();
- initLayout();
- connectSignalsAndSlots();
- }
- void ExpertListWidget::showUsers(const QList<QFUser *> &list)
- {
- m_listWidget->clear();
- for (int i = 0; i < list.count(); i++) {
- QListWidgetItem *item = new QListWidgetItem;
- item->setSizeHint(QSize(200, 60));
- m_listWidget->addItem(item);
- QWidget *w = new QWidget();
- m_listWidget->setItemWidget(item, w);
- QHBoxLayout *hBox = new QHBoxLayout(w);
- hBox->setSpacing(0);
- hBox->setMargin(10);
- QLabel *idx = new QLabel(QString::number(i + 1));
- idx->setFixedWidth(20);
- hBox->addWidget(idx);
- hBox->addSpacing(10);
- QLabel *name = new QLabel(list[i]->userName);
- hBox->addWidget(name);
- hBox->addStretch();
- QLabel *time = new QLabel(list[i]->writeTime);
- hBox->addWidget(time);
- }
- }
- bool ExpertListWidget::hasSelectedItem() const
- {
- return m_listWidget->selectedItems().count() > 0;
- }
- int ExpertListWidget::selectedRow() const
- {
- QListWidgetItem *item = m_listWidget->selectedItems().first();
- return m_listWidget->row(item);
- }
- void ExpertListWidget::clearSelection()
- {
- m_listWidget->clearSelection();
- }
- void ExpertListWidget::initialize()
- {
- 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(244, 244, 255);}");
- }
- void ExpertListWidget::initLayout()
- {
- m_vBoxLayout->addWidget(m_listWidget);
- }
- void ExpertListWidget::connectSignalsAndSlots()
- {
- connect(m_listWidget, &QListWidget::itemDoubleClicked, this, &ExpertListWidget::slotItemDoubleClicked);
- connect(m_listWidget, &QListWidget::itemClicked, this, &ExpertListWidget::slotItemClicked);
- connect(m_listWidget, &QListWidget::currentItemChanged, this, &ExpertListWidget::slotCurrentItemChanged);
- connect(m_listWidget, &QListWidget::currentRowChanged, this, &ExpertListWidget::slotCurrentRowChanged);
- connect(m_listWidget, &QListWidget::itemSelectionChanged, this, &ExpertListWidget::slotItemSelectionChanged);
- }
- void ExpertListWidget::slotItemDoubleClicked(QListWidgetItem *item)
- {
- emit siganlItemDoubleClicked(m_listWidget->row(item));
- }
- void ExpertListWidget::slotItemClicked(QListWidgetItem *)
- {
- qDebug() << __FUNCTION__ << __LINE__;
- }
- void ExpertListWidget::slotCurrentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
- {
- qDebug() << __FUNCTION__ << __LINE__ << current << previous;
- }
- void ExpertListWidget::slotCurrentRowChanged(int currentRow)
- {
- qDebug() << __FUNCTION__ << __LINE__ << currentRow;
- }
- void ExpertListWidget::slotItemSelectionChanged()
- {
- qDebug() << __FUNCTION__ << __LINE__ << m_listWidget->selectedItems();
- emit signalSelectionChanged();
- }
|