1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +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:
// 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);
viewport()->update();
return true;
@ -251,54 +251,34 @@ void LocationCompleterView::close()
QListView::hide();
verticalScrollBar()->setValue(0);
m_hoveredIndex = QPersistentModelIndex();
m_delegate->setShowSwitchToTab(true);
emit closed();
}
void LocationCompleterView::mouseMoveEvent(QMouseEvent* event)
void LocationCompleterView::mouseReleaseEvent(QMouseEvent* event)
{
if (m_ignoreNextMouseMove || !isVisible()) {
m_ignoreNextMouseMove = false;
QListView::mouseMoveEvent(event);
QModelIndex idx = indexAt(event->pos());
if (!idx.isValid()) {
return;
}
QModelIndex last = m_hoveredIndex;
QModelIndex atCursor = indexAt(mapFromGlobal(QCursor::pos()));
Qt::MouseButton button = event->button();
Qt::KeyboardModifiers modifiers = event->modifiers();
if (atCursor.isValid()) {
m_hoveredIndex = atCursor;
if (button == Qt::LeftButton && modifiers == Qt::NoModifier) {
emit indexActivated(idx);
return;
}
if (last != atCursor) {
viewport()->update();
if (button == Qt::MiddleButton || (button == Qt::LeftButton && modifiers == Qt::ControlModifier)) {
emit indexCtrlActivated(idx);
return;
}
QListView::mouseMoveEvent(event);
}
void LocationCompleterView::mouseReleaseEvent(QMouseEvent* event)
{
if (m_hoveredIndex.isValid()) {
Qt::MouseButton button = event->button();
Qt::KeyboardModifiers modifiers = event->modifiers();
if (button == Qt::LeftButton && modifiers == Qt::NoModifier) {
emit indexActivated(m_hoveredIndex);
return;
}
if (button == Qt::MiddleButton || (button == Qt::LeftButton && modifiers == Qt::ControlModifier)) {
emit indexCtrlActivated(m_hoveredIndex);
return;
}
if (button == Qt::LeftButton && modifiers == Qt::ShiftModifier) {
emit indexShiftActivated(m_hoveredIndex);
return;
}
if (button == Qt::LeftButton && modifiers == Qt::ShiftModifier) {
emit indexShiftActivated(idx);
return;
}
QListView::mouseReleaseEvent(event);

View File

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