From 5cb5f2e367f38f7f43932f4929c7069bb002d896 Mon Sep 17 00:00:00 2001 From: rku Date: Tue, 15 Dec 2015 19:31:45 +0200 Subject: [PATCH] Focus current chat widget text input when window is activated or empty window space clicked. --- src/widget/widget.cpp | 20 +++++++++++++++++++- src/widget/widget.h | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index cbbdc8754..2de05f090 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -1577,6 +1577,10 @@ bool Widget::event(QEvent * e) { switch (e->type()) { + case QEvent::MouseButtonPress: + case QEvent::MouseButtonDblClick: + focusChatInput(); + break; case QEvent::WindowActivate: if (activeChatroomWidget != nullptr) { @@ -1584,6 +1588,7 @@ bool Widget::event(QEvent * e) activeChatroomWidget->updateStatusLight(); setWindowTitle(activeChatroomWidget->getTitle()); } + if (eventFlag) { eventFlag = false; @@ -1591,13 +1596,15 @@ bool Widget::event(QEvent * e) updateIcons(); } + focusChatInput(); + #ifdef Q_OS_MAC emit windowStateChanged(windowState()); case QEvent::WindowStateChange: Nexus::getInstance().updateWindowsStates(); #endif - + break; default: break; } @@ -2080,3 +2087,14 @@ void Widget::retranslateUi() previousConversationAction->setText(tr("Previous Conversation")); #endif } + +void Widget::focusChatInput() +{ + if (activeChatroomWidget) + { + if (Friend* f = activeChatroomWidget->getFriend()) + f->getChatForm()->focusInput(); + else if (Group* g = activeChatroomWidget->getGroup()) + g->getChatForm()->focusInput(); + } +} diff --git a/src/widget/widget.h b/src/widget/widget.h index 87a698978..7ca4f18e2 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -221,6 +221,7 @@ private: static bool filterOnline(int index); static bool filterOffline(int index); void retranslateUi(); + void focusChatInput(); private: SystemTrayIcon *icon;