Commit 356b85d4 authored by Eike Ziller's avatar Eike Ziller
Browse files

Work around issue in Qt5 that shortcut override events are posted twice



Make shortcut override handling not have side effects.

Task-number: QTBUG-30164
Change-Id: Ie54a31fc6539d4e509b0903983df0effa06cee12
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent 0d850d7d
...@@ -285,6 +285,14 @@ void FindToolBar::installEventFilters() ...@@ -285,6 +285,14 @@ void FindToolBar::installEventFilters()
} }
} }
bool FindToolBar::shouldSetFocusOnKeyEvent(QKeyEvent *event)
{
return event->key() == Qt::Key_Escape && !event->modifiers()
&& !m_findCompleter->popup()->isVisible()
&& !m_replaceCompleter->popup()->isVisible()
&& m_currentDocumentFind->isEnabled();
}
bool FindToolBar::eventFilter(QObject *obj, QEvent *event) bool FindToolBar::eventFilter(QObject *obj, QEvent *event)
{ {
if (event->type() == QEvent::KeyPress) { if (event->type() == QEvent::KeyPress) {
...@@ -315,13 +323,9 @@ bool FindToolBar::eventFilter(QObject *obj, QEvent *event) ...@@ -315,13 +323,9 @@ bool FindToolBar::eventFilter(QObject *obj, QEvent *event)
} }
} else if (obj == this && event->type() == QEvent::ShortcutOverride) { } else if (obj == this && event->type() == QEvent::ShortcutOverride) {
QKeyEvent *ke = static_cast<QKeyEvent *>(event); QKeyEvent *ke = static_cast<QKeyEvent *>(event);
if (ke->key() == Qt::Key_Escape && !ke->modifiers() if (shouldSetFocusOnKeyEvent(ke)) {
&& !m_findCompleter->popup()->isVisible() event->accept();
&& !m_replaceCompleter->popup()->isVisible()) { return true;
if (setFocusToCurrentFindSupport()) {
event->accept();
return true;
}
} else if (ke->key() == Qt::Key_Space && (ke->modifiers() & Utils::HostOsInfo::controlModifier())) { } else if (ke->key() == Qt::Key_Space && (ke->modifiers() & Utils::HostOsInfo::controlModifier())) {
event->accept(); event->accept();
return true; return true;
...@@ -334,6 +338,16 @@ bool FindToolBar::eventFilter(QObject *obj, QEvent *event) ...@@ -334,6 +338,16 @@ bool FindToolBar::eventFilter(QObject *obj, QEvent *event)
return Utils::StyledBar::eventFilter(obj, event); return Utils::StyledBar::eventFilter(obj, event);
} }
void FindToolBar::keyPressEvent(QKeyEvent *event)
{
if (shouldSetFocusOnKeyEvent(event)) {
if (setFocusToCurrentFindSupport())
event->accept();
return;
}
return Utils::StyledBar::keyPressEvent(event);
}
void FindToolBar::adaptToCandidate() void FindToolBar::adaptToCandidate()
{ {
updateFindAction(); updateFindAction();
......
...@@ -97,6 +97,7 @@ private slots: ...@@ -97,6 +97,7 @@ private slots:
protected: protected:
bool focusNextPrevChild(bool next); bool focusNextPrevChild(bool next);
void keyPressEvent(QKeyEvent *event);
private: private:
void installEventFilters(); void installEventFilters();
...@@ -115,6 +116,8 @@ private: ...@@ -115,6 +116,8 @@ private:
void updateIcons(); void updateIcons();
void updateFlagMenus(); void updateFlagMenus();
bool shouldSetFocusOnKeyEvent(QKeyEvent *event);
FindPlugin *m_plugin; FindPlugin *m_plugin;
CurrentDocumentFind *m_currentDocumentFind; CurrentDocumentFind *m_currentDocumentFind;
Ui::FindWidget m_ui; Ui::FindWidget m_ui;
......
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