Optimize selected functions;

This commit is contained in:
jixiaoxu 2021-09-09 11:23:59 +08:00
parent 69db4572d2
commit e5033adff6
5 changed files with 45 additions and 8 deletions

View File

@ -2,8 +2,8 @@ INCLUDEPATH += $$PWD
HEADERS += \ HEADERS += \
$$PWD/show-more-label.h \ $$PWD/show-more-label.h \
$$PWD/title-label.h \ $$PWD/title-label.h
SOURCES += \ SOURCES += \
$$PWD/show-more-label.cpp \ $$PWD/show-more-label.cpp \
$$PWD/title-label.cpp \ $$PWD/title-label.cpp

View File

@ -145,18 +145,34 @@ void BestListView::mousePressEvent(QMouseEvent *event)
{ {
m_tmpCurrentIndex = this->currentIndex(); m_tmpCurrentIndex = this->currentIndex();
m_tmpMousePressIndex = indexAt(event->pos()); m_tmpMousePressIndex = indexAt(event->pos());
if (m_tmpMousePressIndex.isValid() and m_tmpCurrentIndex != m_tmpMousePressIndex) {
Q_EMIT this->clicked(m_tmpMousePressIndex);
}
return QTreeView::mousePressEvent(event); return QTreeView::mousePressEvent(event);
} }
void BestListView::mouseReleaseEvent(QMouseEvent *event) void BestListView::mouseReleaseEvent(QMouseEvent *event)
{ {
QModelIndex index = indexAt(event->pos()); QModelIndex index = indexAt(event->pos());
if (!index.isValid() or index != m_tmpMousePressIndex) { if (index.isValid()) {
this->setCurrentIndex(m_tmpCurrentIndex); Q_EMIT this->clicked(index);
} else {
Q_EMIT this->clicked(this->currentIndex());
} }
return QTreeView::mouseReleaseEvent(event); return QTreeView::mouseReleaseEvent(event);
} }
void BestListView::mouseMoveEvent(QMouseEvent *event)
{
m_tmpCurrentIndex = this->currentIndex();
m_tmpMousePressIndex = indexAt(event->pos());
if (m_tmpMousePressIndex.isValid() and m_tmpCurrentIndex != m_tmpMousePressIndex) {
Q_EMIT this->clicked(m_tmpMousePressIndex);
}
return QTreeView::mouseMoveEvent(event);
}
void BestListView::initConnections() void BestListView::initConnections()
{ {
connect(this, &BestListView::startSearch, [ = ](const QString &keyword) { connect(this, &BestListView::startSearch, [ = ](const QString &keyword) {

View File

@ -39,6 +39,7 @@ public Q_SLOTS:
protected: protected:
void mousePressEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent * event); void mouseReleaseEvent(QMouseEvent * event);
void mouseMoveEvent(QMouseEvent *event);
private: private:
void initConnections(); void initConnections();

View File

@ -237,8 +237,10 @@ void ResultView::onRowSelectedSlot(const QModelIndex &index)
{ {
//NEW_TODO //NEW_TODO
m_is_selected = true; m_is_selected = true;
Q_EMIT this->currentRowChanged(m_plugin_id, m_model->getInfo(index)); if(index.isValid()) {
// if(!selected.isEmpty()) { Q_EMIT this->currentRowChanged(m_plugin_id, m_model->getInfo(index));
}
// if(!selected.isEmpty()) {
// QRegion region = visualRegionForSelection(selected); // QRegion region = visualRegionForSelection(selected);
// QRect rect = region.boundingRect(); // QRect rect = region.boundingRect();
//// Q_EMIT this->currentSelectPos(mapToParent(rect.topLeft())); //// Q_EMIT this->currentSelectPos(mapToParent(rect.topLeft()));
@ -282,18 +284,34 @@ void ResultView::mousePressEvent(QMouseEvent *event)
{ {
m_tmpCurrentIndex = this->currentIndex(); m_tmpCurrentIndex = this->currentIndex();
m_tmpMousePressIndex = indexAt(event->pos()); m_tmpMousePressIndex = indexAt(event->pos());
if (m_tmpMousePressIndex.isValid() and m_tmpCurrentIndex != m_tmpMousePressIndex) {
Q_EMIT this->clicked(m_tmpMousePressIndex);
}
return QTreeView::mousePressEvent(event); return QTreeView::mousePressEvent(event);
} }
void ResultView::mouseReleaseEvent(QMouseEvent *event) void ResultView::mouseReleaseEvent(QMouseEvent *event)
{ {
QModelIndex index = indexAt(event->pos()); QModelIndex index = indexAt(event->pos());
if (!index.isValid() or index != m_tmpMousePressIndex) { if (index.isValid()) {
this->setCurrentIndex(m_tmpCurrentIndex); Q_EMIT this->clicked(index);
} else {
Q_EMIT this->clicked(this->currentIndex());
} }
return QTreeView::mouseReleaseEvent(event); return QTreeView::mouseReleaseEvent(event);
} }
void ResultView::mouseMoveEvent(QMouseEvent *event)
{
m_tmpCurrentIndex = this->currentIndex();
m_tmpMousePressIndex = indexAt(event->pos());
if (m_tmpMousePressIndex.isValid() and m_tmpCurrentIndex != m_tmpMousePressIndex) {
Q_EMIT this->clicked(m_tmpMousePressIndex);
}
return QTreeView::mouseMoveEvent(event);
}
void ResultView::initConnections() void ResultView::initConnections()
{ {
connect(this, &ResultView::startSearch, [ = ](const QString &keyword) { connect(this, &ResultView::startSearch, [ = ](const QString &keyword) {

View File

@ -36,6 +36,7 @@ public Q_SLOTS:
protected: protected:
void mousePressEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
private: private:
void initConnections(); void initConnections();
@ -55,6 +56,7 @@ Q_SIGNALS:
void listLengthChanged(const int &); void listLengthChanged(const int &);
void rowClicked(); void rowClicked();
void lableReset(); void lableReset();
void mouseSelect(QModelIndex &index);
}; };
class ResultWidget : public QWidget class ResultWidget : public QWidget