chatwidget: do not set focus to edit when it is not necessary

e.g. when a user just wants to browse chat history
This commit is contained in:
chelovechishko 2018-01-10 20:53:43 +09:00
parent c3e300e717
commit add9c1e72c

View File

@ -731,15 +731,6 @@ bool ChatWidget::eventFilter(QObject *obj, QEvent *event)
} }
} }
} else {
if (event->type() == QEvent::WindowActivate) {
if (isVisible() && (window() == NULL || window()->isActiveWindow())) {
newMessages = false;
emit infoChanged(this);
focusDialog();
ChatUserNotify::clearWaitingChat(chatId);
}
}
} }
// pass the event on to the parent class // pass the event on to the parent class
return QWidget::eventFilter(obj, event); return QWidget::eventFilter(obj, event);
@ -889,7 +880,17 @@ void ChatWidget::showEvent(QShowEvent */*event*/)
{ {
newMessages = false; newMessages = false;
emit infoChanged(this); emit infoChanged(this);
// if user waded through the jungle of history just let him on
// own decide whether to continue the journey or start typing
QScrollBar *scrollbar = ui->textBrowser->verticalScrollBar();
bool is_scrollbar_at_end = scrollbar->value() == scrollbar->maximum();
bool is_chat_text_edit_empty = ui->chatTextEdit->toPlainText().isEmpty();
if (is_scrollbar_at_end || !is_chat_text_edit_empty) {
focusDialog(); focusDialog();
} else {
// otherwise focus will be get even not chat itself
ui->textBrowser->setFocus();
}
ChatUserNotify::clearWaitingChat(chatId); ChatUserNotify::clearWaitingChat(chatId);
if (firstShow) { if (firstShow) {