Browse Source

fix(chatform): include pressed key(s) when changing focus

Instead of just giving focus, give focus and add the key that was pressed. Also change from KeyRelease to KeyPress to avoid missing the second key pressed in the case of the second key being pressed before the first is released.
reviewable/pr5054/r1
Anthony Bilinski 7 years ago
parent
commit
a8fc6e5c6b
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
  1. 4
      src/widget/form/genericchatform.cpp
  2. 5
      src/widget/searchform.cpp
  3. 1
      src/widget/searchform.h

4
src/widget/form/genericchatform.cpp

@ -311,13 +311,15 @@ void GenericChatForm::showEvent(QShowEvent*)
bool GenericChatForm::event(QEvent* e) bool GenericChatForm::event(QEvent* e)
{ {
// If the user accidentally starts typing outside of the msgEdit, focus it automatically // If the user accidentally starts typing outside of the msgEdit, focus it automatically
if (e->type() == QEvent::KeyRelease && !msgEdit->hasFocus()) { if (e->type() == QEvent::KeyPress) {
QKeyEvent* ke = static_cast<QKeyEvent*>(e); QKeyEvent* ke = static_cast<QKeyEvent*>(e);
if ((ke->modifiers() == Qt::NoModifier || ke->modifiers() == Qt::ShiftModifier) if ((ke->modifiers() == Qt::NoModifier || ke->modifiers() == Qt::ShiftModifier)
&& !ke->text().isEmpty()) { && !ke->text().isEmpty()) {
if (searchForm->isHidden()) { if (searchForm->isHidden()) {
msgEdit->sendKeyEvent(ke);
msgEdit->setFocus(); msgEdit->setFocus();
} else { } else {
searchForm->insertEditor(ke->text());
searchForm->setFocusEditor(); searchForm->setFocusEditor();
} }
} }

5
src/widget/searchform.cpp

@ -65,6 +65,11 @@ void SearchForm::setFocusEditor()
searchLine->setFocus(); searchLine->setFocus();
} }
void SearchForm::insertEditor(const QString &text)
{
searchLine->insert(text);
}
void SearchForm::showEvent(QShowEvent* event) void SearchForm::showEvent(QShowEvent* event)
{ {
QWidget::showEvent(event); QWidget::showEvent(event);

1
src/widget/searchform.h

@ -34,6 +34,7 @@ public:
void removeSearchPhrase(); void removeSearchPhrase();
QString getSearchPhrase() const; QString getSearchPhrase() const;
void setFocusEditor(); void setFocusEditor();
void insertEditor(const QString &text);
protected: protected:
virtual void showEvent(QShowEvent* event) final override; virtual void showEvent(QShowEvent* event) final override;

Loading…
Cancel
Save