1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

LocationCompleterView: Use better window type

It is no longer modal, so it doesn't break shortcuts.

Closes #2213
This commit is contained in:
David Rosca 2017-02-13 20:56:16 +01:00
parent e150e44cc6
commit 71b06197ef

View File

@ -1,6 +1,6 @@
/* ============================================================ /* ============================================================
* QupZilla - WebKit based browser * QupZilla - Qt web browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com> * Copyright (C) 2010-2017 David Rosca <nowrep@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -28,7 +28,9 @@ LocationCompleterView::LocationCompleterView()
: QListView(0) : QListView(0)
, m_ignoreNextMouseMove(false) , m_ignoreNextMouseMove(false)
{ {
setWindowFlags(Qt::Popup); setAttribute(Qt::WA_ShowWithoutActivating);
setAttribute(Qt::WA_X11NetWmWindowTypeCombo);
setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::BypassWindowManagerHint);
setUniformItemSizes(true); setUniformItemSizes(true);
setEditTriggers(QAbstractItemView::NoEditTriggers); setEditTriggers(QAbstractItemView::NoEditTriggers);
@ -38,7 +40,7 @@ LocationCompleterView::LocationCompleterView()
setSelectionMode(QAbstractItemView::SingleSelection); setSelectionMode(QAbstractItemView::SingleSelection);
setMouseTracking(true); setMouseTracking(true);
installEventFilter(this); qApp->installEventFilter(this);
m_delegate = new LocationCompleterDelegate(this); m_delegate = new LocationCompleterDelegate(this);
setItemDelegate(m_delegate); setItemDelegate(m_delegate);
@ -51,9 +53,12 @@ QPersistentModelIndex LocationCompleterView::hoveredIndex() const
bool LocationCompleterView::eventFilter(QObject* object, QEvent* event) bool LocationCompleterView::eventFilter(QObject* object, QEvent* event)
{ {
Q_UNUSED(object)
// Event filter based on QCompleter::eventFilter from qcompleter.cpp // Event filter based on QCompleter::eventFilter from qcompleter.cpp
if (object == this || !isVisible()) {
return false;
}
switch (event->type()) { switch (event->type()) {
case QEvent::KeyPress: { case QEvent::KeyPress: {
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event); QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
@ -88,9 +93,21 @@ bool LocationCompleterView::eventFilter(QObject* object, QEvent* event)
break; break;
case Qt::Key_End: case Qt::Key_End:
if (modifiers & Qt::ControlModifier) {
setCurrentIndex(model()->index(model()->rowCount() - 1, 0));
return true;
} else {
close();
}
break;
case Qt::Key_Home: case Qt::Key_Home:
if (modifiers & Qt::ControlModifier) { if (modifiers & Qt::ControlModifier) {
return false; setCurrentIndex(model()->index(0, 0));
scrollToTop();
return true;
} else {
close();
} }
break; break;
@ -107,10 +124,13 @@ bool LocationCompleterView::eventFilter(QObject* object, QEvent* event)
case Qt::Key_Tab: case Qt::Key_Tab:
case Qt::Key_Backtab: { case Qt::Key_Backtab: {
if (keyEvent->modifiers() != Qt::NoModifier) {
return false;
}
Qt::Key k = keyEvent->key() == Qt::Key_Tab ? Qt::Key_Down : Qt::Key_Up; Qt::Key k = keyEvent->key() == Qt::Key_Tab ? Qt::Key_Down : Qt::Key_Up;
QKeyEvent ev(QKeyEvent::KeyPress, k, Qt::NoModifier); QKeyEvent ev(QKeyEvent::KeyPress, k, Qt::NoModifier);
QApplication::sendEvent(this, &ev); QApplication::sendEvent(focusProxy(), &ev);
return false; return true;
} }
case Qt::Key_Up: case Qt::Key_Up:
@ -118,26 +138,24 @@ bool LocationCompleterView::eventFilter(QObject* object, QEvent* event)
int rowCount = model()->rowCount(); int rowCount = model()->rowCount();
QModelIndex lastIndex = model()->index(rowCount - 1, 0); QModelIndex lastIndex = model()->index(rowCount - 1, 0);
setCurrentIndex(lastIndex); setCurrentIndex(lastIndex);
return true; } else if (idx.row() == 0) {
}
else if (idx.row() == 0) {
setCurrentIndex(QModelIndex()); setCurrentIndex(QModelIndex());
return true; } else {
setCurrentIndex(model()->index(idx.row() - 1, 0));
} }
return false; return true;
case Qt::Key_Down: case Qt::Key_Down:
if (!idx.isValid()) { if (!idx.isValid()) {
QModelIndex firstIndex = model()->index(0, 0); QModelIndex firstIndex = model()->index(0, 0);
setCurrentIndex(firstIndex); setCurrentIndex(firstIndex);
return true; } else if (idx.row() == model()->rowCount() - 1) {
}
else if (idx.row() == model()->rowCount() - 1) {
setCurrentIndex(QModelIndex()); setCurrentIndex(QModelIndex());
scrollToTop(); scrollToTop();
return true; } else {
setCurrentIndex(model()->index(idx.row() + 1, 0));
} }
return false; return true;
case Qt::Key_Delete: case Qt::Key_Delete:
if (viewport()->rect().contains(visualRect(idx))) { if (viewport()->rect().contains(visualRect(idx))) {
@ -147,8 +165,18 @@ bool LocationCompleterView::eventFilter(QObject* object, QEvent* event)
break; break;
case Qt::Key_PageUp: case Qt::Key_PageUp:
case Qt::Key_PageDown: if (keyEvent->modifiers() != Qt::NoModifier) {
return false; return false;
}
selectionModel()->setCurrentIndex(moveCursor(QAbstractItemView::MovePageUp, Qt::NoModifier), QItemSelectionModel::SelectCurrent);
return true;
case Qt::Key_PageDown:
if (keyEvent->modifiers() != Qt::NoModifier) {
return false;
}
selectionModel()->setCurrentIndex(moveCursor(QAbstractItemView::MovePageDown, Qt::NoModifier), QItemSelectionModel::SelectCurrent);
return true;
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
@ -181,17 +209,30 @@ bool LocationCompleterView::eventFilter(QObject* object, QEvent* event)
m_ignoreNextMouseMove = true; m_ignoreNextMouseMove = true;
break; break;
case QEvent::Wheel:
case QEvent::MouseButtonPress: case QEvent::MouseButtonPress:
if (!underMouse()) { if (!underMouse()) {
close(); close();
return true; return false;
} }
break; break;
case QEvent::ShortcutOverride: case QEvent::FocusOut: {
case QEvent::InputMethod: QFocusEvent *focusEvent = static_cast<QFocusEvent*>(event);
QApplication::sendEvent(focusProxy(), event); if (focusEvent->reason() != Qt::PopupFocusReason) {
close();
}
break; break;
}
case QEvent::Move:
case QEvent::Resize: {
QWidget *w = qobject_cast<QWidget*>(object);
if (w && w->isWindow() && w == focusProxy()->window()) {
close();
}
break;
}
default: default:
break; break;