Browse Source

Auto focus the chat input box when typing

Fixes #1779 for real
pull/1816/head
tux3 10 years ago
parent
commit
b948ef890f
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
  1. 18
      src/widget/form/genericchatform.cpp
  2. 2
      src/widget/form/genericchatform.h

18
src/widget/form/genericchatform.cpp

@ -19,6 +19,7 @@ @@ -19,6 +19,7 @@
#include <QHBoxLayout>
#include <QDebug>
#include <QShortcut>
#include <QKeyEvent>
#include "src/misc/smileypack.h"
#include "src/widget/emoticonswidget.h"
@ -240,6 +241,23 @@ void GenericChatForm::show(Ui::MainWindow &ui) @@ -240,6 +241,23 @@ void GenericChatForm::show(Ui::MainWindow &ui)
QWidget::show();
}
void GenericChatForm::showEvent(QShowEvent *)
{
msgEdit->setFocus();
}
bool GenericChatForm::event(QEvent* e)
{
// If the user accidentally starts typing outside of the msgEdit, focus it automatically
if (e->type() == QEvent::KeyRelease && !msgEdit->hasFocus())
{
QKeyEvent* ke = static_cast<QKeyEvent*>(e);
if (ke->modifiers() == Qt::NoModifier || ke->modifiers() == Qt::ShiftModifier)
msgEdit->setFocus();
}
return QWidget::event(e);
}
void GenericChatForm::onChatContextMenuRequested(QPoint pos)
{
QWidget* sender = (QWidget*)QObject::sender();

2
src/widget/form/genericchatform.h

@ -87,6 +87,8 @@ protected: @@ -87,6 +87,8 @@ protected:
QString resolveToxId(const ToxId &id);
void insertChatMessage(ChatMessage::Ptr msg);
void hideEvent(QHideEvent* event);
void showEvent(QShowEvent *);
bool event(QEvent *);
void resizeEvent(QResizeEvent* event);
void adjustFileMenuPosition();

Loading…
Cancel
Save