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 += \
$$PWD/show-more-label.h \
$$PWD/title-label.h \
$$PWD/title-label.h
SOURCES += \
$$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_tmpMousePressIndex = indexAt(event->pos());
if (m_tmpMousePressIndex.isValid() and m_tmpCurrentIndex != m_tmpMousePressIndex) {
Q_EMIT this->clicked(m_tmpMousePressIndex);
}
return QTreeView::mousePressEvent(event);
}
void BestListView::mouseReleaseEvent(QMouseEvent *event)
{
QModelIndex index = indexAt(event->pos());
if (!index.isValid() or index != m_tmpMousePressIndex) {
this->setCurrentIndex(m_tmpCurrentIndex);
if (index.isValid()) {
Q_EMIT this->clicked(index);
} else {
Q_EMIT this->clicked(this->currentIndex());
}
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()
{
connect(this, &BestListView::startSearch, [ = ](const QString &keyword) {

View File

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

View File

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

View File

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