Commit c80ec551 authored by David Schulz's avatar David Schulz Committed by Eike Ziller
Browse files

fix for locator using up and down keys under mac



Fixes the issue that you cannot switch elements by the up- and downkey in the locator under mac.

Task-number: QTCREATORBUG-6826
Change-Id: I452bb487608fad3b32c845036939f02e9cf4b3b6
Reviewed-by: default avatarEike Ziller <eike.ziller@nokia.com>
parent 2ac162dd
......@@ -401,7 +401,59 @@ void LocatorWidget::updateFilterList()
bool LocatorWidget::eventFilter(QObject *obj, QEvent *event)
{
if (obj == m_fileLineEdit && event->type() == QEvent::FocusOut) {
if (obj == m_fileLineEdit && event->type() == QEvent::KeyPress) {
if (m_possibleToolTipRequest)
m_possibleToolTipRequest = false;
if (QToolTip::isVisible())
QToolTip::hideText();
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
switch (keyEvent->key()) {
case Qt::Key_Up:
case Qt::Key_Down:
case Qt::Key_PageUp:
case Qt::Key_PageDown:
showCompletionList();
QApplication::sendEvent(m_completionList, event);
return true;
case Qt::Key_Enter:
case Qt::Key_Return:
scheduleAcceptCurrentEntry();
return true;
case Qt::Key_Escape:
m_completionList->hide();
return true;
case Qt::Key_Tab:
m_completionList->next();
return true;
case Qt::Key_Backtab:
m_completionList->previous();
return true;
case Qt::Key_Alt:
if (keyEvent->modifiers() == Qt::AltModifier) {
m_possibleToolTipRequest = true;
return true;
}
break;
default:
break;
}
} else if (obj == m_fileLineEdit && event->type() == QEvent::KeyRelease) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if (m_possibleToolTipRequest) {
m_possibleToolTipRequest = false;
if (m_completionList->isVisible()
&& (keyEvent->key() == Qt::Key_Alt)
&& (keyEvent->modifiers() == Qt::NoModifier)) {
const QModelIndex index = m_completionList->currentIndex();
if (index.isValid()) {
QToolTip::showText(m_completionList->pos() + m_completionList->visualRect(index).topRight(),
m_locatorModel->data(index, Qt::ToolTipRole).toString());
return true;
}
}
}
} else if (obj == m_fileLineEdit && event->type() == QEvent::FocusOut) {
#if defined(Q_OS_WIN)
QFocusEvent *fev = static_cast<QFocusEvent*>(event);
if (fev->reason() != Qt::ActiveWindowFocusReason ||
......@@ -432,64 +484,6 @@ bool LocatorWidget::eventFilter(QObject *obj, QEvent *event)
return QWidget::eventFilter(obj, event);
}
void LocatorWidget::keyPressEvent(QKeyEvent *keyEvent)
{
if (QToolTip::isVisible())
QToolTip::hideText();
if (m_possibleToolTipRequest)
m_possibleToolTipRequest = false;
switch (keyEvent->key()) {
case Qt::Key_Up:
case Qt::Key_Down:
case Qt::Key_PageUp:
case Qt::Key_PageDown:
showCompletionList();
QApplication::sendEvent(m_completionList, keyEvent);
return;
case Qt::Key_Enter:
case Qt::Key_Return:
scheduleAcceptCurrentEntry();
return;
case Qt::Key_Escape:
m_completionList->hide();
return;
case Qt::Key_Tab:
m_completionList->next();
return;
case Qt::Key_Backtab:
m_completionList->previous();
return;
case Qt::Key_Alt:
if (keyEvent->modifiers() == Qt::AltModifier) {
m_possibleToolTipRequest = true;
return;
}
break;
default:
break;
}
QWidget::keyPressEvent(keyEvent);
}
void LocatorWidget::keyReleaseEvent(QKeyEvent *keyEvent)
{
if (m_possibleToolTipRequest) {
m_possibleToolTipRequest = false;
if (m_completionList->isVisible()
&& (keyEvent->key() == Qt::Key_Alt)
&& (keyEvent->modifiers() == Qt::NoModifier)) {
const QModelIndex index = m_completionList->currentIndex();
if (index.isValid()) {
QToolTip::showText(m_completionList->pos() + m_completionList->visualRect(index).topRight(),
m_locatorModel->data(index, Qt::ToolTipRole).toString());
return;
}
}
}
QWidget::keyReleaseEvent(keyEvent);
}
void LocatorWidget::showCompletionList()
{
const int border = m_completionList->frameWidth();
......
......@@ -80,8 +80,6 @@ private slots:
private:
bool eventFilter(QObject *obj, QEvent *event);
void keyPressEvent(QKeyEvent *keyEvent);
void keyReleaseEvent(QKeyEvent *keyEvent);
void showEvent(QShowEvent *e);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment