From 737ce1c255b464cbfd1265a82a56363f6db81214 Mon Sep 17 00:00:00 2001 From: Hartmnt Date: Mon, 30 Sep 2024 08:49:10 +0000 Subject: [PATCH] FIX(client): Limit size of the chat bar Previously, the chat bar QTextEdit was unlimited in screen space size and would start stretching the main window and chat log, if messages were too large. This resulted in the window becoming unusable unless you would manually resize the window down again. This commit adds a sensible limit to how much of the chat bar can be visible at once. Currently, this limit is set to 10 times the font height. After that the chat bar will stop growing in screen space and instead start showing a scrollbar. Fixes #6528 Fixes #1320 --- src/mumble/CustomElements.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/mumble/CustomElements.cpp b/src/mumble/CustomElements.cpp index b43742fcfc1..051fd196e73 100644 --- a/src/mumble/CustomElements.cpp +++ b/src/mumble/CustomElements.cpp @@ -107,7 +107,7 @@ ChatbarTextEdit::ChatbarTextEdit(QWidget *p) : QTextEdit(p), iHistoryIndex(-1) { setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setMinimumHeight(0); - connect(this, SIGNAL(textChanged()), SLOT(doResize())); + connect(this, &ChatbarTextEdit::textChanged, this, &ChatbarTextEdit::doResize); bDefaultVisible = true; setDefaultText(tr("
Type chat message here
")); @@ -121,10 +121,12 @@ QSize ChatbarTextEdit::minimumSizeHint() const { } QSize ChatbarTextEdit::sizeHint() const { - QSize sh = QTextEdit::sizeHint(); - const int minHeight = minimumSizeHint().height(); - const int documentHeight = static_cast< int >(document()->documentLayout()->documentSize().height()); - sh.setHeight(std::max(minHeight, documentHeight)); + QSize sh = QTextEdit::sizeHint(); + const int minHeight = minimumSizeHint().height(); + const int documentHeight = static_cast< int >(document()->documentLayout()->documentSize().height()); + const int chatBarLineHeight = QFontMetrics(ChatbarTextEdit::font()).height(); + + sh.setHeight(std::max(minHeight, std::min(chatBarLineHeight * 10, documentHeight))); const_cast< ChatbarTextEdit * >(this)->setMaximumHeight(sh.height()); return sh; } @@ -144,7 +146,8 @@ void ChatbarTextEdit::doResize() { } void ChatbarTextEdit::doScrollbar() { - setVerticalScrollBarPolicy(sizeHint().height() > height() ? Qt::ScrollBarAlwaysOn : Qt::ScrollBarAlwaysOff); + const int documentHeight = static_cast< int >(document()->documentLayout()->documentSize().height()); + setVerticalScrollBarPolicy(documentHeight > height() ? Qt::ScrollBarAlwaysOn : Qt::ScrollBarAlwaysOff); ensureCursorVisible(); }