mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
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.
This commit is contained in:
parent
65d59ba6b7
commit
a8fc6e5c6b
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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…
Reference in New Issue
Block a user