1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Auto focus the chat input box when typing

Fixes #1779 for real
This commit is contained in:
tux3 2015-06-05 22:08:29 +02:00
parent 15ca7a587f
commit b948ef890f
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
2 changed files with 20 additions and 0 deletions

View File

@ -19,6 +19,7 @@
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QDebug> #include <QDebug>
#include <QShortcut> #include <QShortcut>
#include <QKeyEvent>
#include "src/misc/smileypack.h" #include "src/misc/smileypack.h"
#include "src/widget/emoticonswidget.h" #include "src/widget/emoticonswidget.h"
@ -240,6 +241,23 @@ void GenericChatForm::show(Ui::MainWindow &ui)
QWidget::show(); 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) void GenericChatForm::onChatContextMenuRequested(QPoint pos)
{ {
QWidget* sender = (QWidget*)QObject::sender(); QWidget* sender = (QWidget*)QObject::sender();

View File

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