1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

LocationCompleterView: Completely remove the hovered index tracking logic

This commit is contained in:
David Rosca 2017-08-11 13:01:41 +02:00
parent 6bceef43e2
commit c3bead5ed7
2 changed files with 15 additions and 37 deletions

View File

@ -185,7 +185,7 @@ bool LocationCompleterView::eventFilter(QObject* object, QEvent* event)
case Qt::Key_Shift: case Qt::Key_Shift:
// don't switch if there is no hovered or selected index to not disturb typing // don't switch if there is no hovered or selected index to not disturb typing
if (idx != visitSearchIdx || m_hoveredIndex.isValid()) { if (idx != visitSearchIdx || underMouse()) {
m_delegate->setShowSwitchToTab(false); m_delegate->setShowSwitchToTab(false);
viewport()->update(); viewport()->update();
return true; return true;
@ -251,55 +251,35 @@ void LocationCompleterView::close()
QListView::hide(); QListView::hide();
verticalScrollBar()->setValue(0); verticalScrollBar()->setValue(0);
m_hoveredIndex = QPersistentModelIndex();
m_delegate->setShowSwitchToTab(true); m_delegate->setShowSwitchToTab(true);
emit closed(); emit closed();
} }
void LocationCompleterView::mouseMoveEvent(QMouseEvent* event) void LocationCompleterView::mouseReleaseEvent(QMouseEvent* event)
{ {
if (m_ignoreNextMouseMove || !isVisible()) { QModelIndex idx = indexAt(event->pos());
m_ignoreNextMouseMove = false; if (!idx.isValid()) {
QListView::mouseMoveEvent(event);
return; return;
} }
QModelIndex last = m_hoveredIndex;
QModelIndex atCursor = indexAt(mapFromGlobal(QCursor::pos()));
if (atCursor.isValid()) {
m_hoveredIndex = atCursor;
}
if (last != atCursor) {
viewport()->update();
}
QListView::mouseMoveEvent(event);
}
void LocationCompleterView::mouseReleaseEvent(QMouseEvent* event)
{
if (m_hoveredIndex.isValid()) {
Qt::MouseButton button = event->button(); Qt::MouseButton button = event->button();
Qt::KeyboardModifiers modifiers = event->modifiers(); Qt::KeyboardModifiers modifiers = event->modifiers();
if (button == Qt::LeftButton && modifiers == Qt::NoModifier) { if (button == Qt::LeftButton && modifiers == Qt::NoModifier) {
emit indexActivated(m_hoveredIndex); emit indexActivated(idx);
return; return;
} }
if (button == Qt::MiddleButton || (button == Qt::LeftButton && modifiers == Qt::ControlModifier)) { if (button == Qt::MiddleButton || (button == Qt::LeftButton && modifiers == Qt::ControlModifier)) {
emit indexCtrlActivated(m_hoveredIndex); emit indexCtrlActivated(idx);
return; return;
} }
if (button == Qt::LeftButton && modifiers == Qt::ShiftModifier) { if (button == Qt::LeftButton && modifiers == Qt::ShiftModifier) {
emit indexShiftActivated(m_hoveredIndex); emit indexShiftActivated(idx);
return; return;
} }
}
QListView::mouseReleaseEvent(event); QListView::mouseReleaseEvent(event);
} }

View File

@ -48,14 +48,12 @@ public slots:
void close(); void close();
protected: protected:
void mouseMoveEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event); void mouseReleaseEvent(QMouseEvent* event);
private: private:
bool m_ignoreNextMouseMove; bool m_ignoreNextMouseMove;
LocationCompleterDelegate* m_delegate; LocationCompleterDelegate* m_delegate;
QPersistentModelIndex m_hoveredIndex;
}; };
#endif // LOCATIONCOMPLETERVIEW_H #endif // LOCATIONCOMPLETERVIEW_H