diff --git a/src/mumble/CustomElements.cpp b/src/mumble/CustomElements.cpp index b43742fcfc1..d3c52eb21db 100644 --- a/src/mumble/CustomElements.cpp +++ b/src/mumble/CustomElements.cpp @@ -102,12 +102,14 @@ void ChatbarTextEdit::dropEvent(QDropEvent *evt) { } } +#include + ChatbarTextEdit::ChatbarTextEdit(QWidget *p) : QTextEdit(p), iHistoryIndex(-1) { setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); 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
")); @@ -124,7 +126,18 @@ 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)); + + qDebug() << "1"; + QFont font = ChatbarTextEdit::font(); + qDebug() << "2"; + QFontMetrics fontMetrics = QFontMetrics(font); + qDebug() << "3"; + const int chatBarTextHeight = fontMetrics.height(); + + qDebug() << "chat bar height max " << (chatBarTextHeight * 10); + + sh.setHeight(std::max(minHeight, std::min(chatBarTextHeight * 10, documentHeight))); + qDebug() << "4"; const_cast< ChatbarTextEdit * >(this)->setMaximumHeight(sh.height()); return sh; } @@ -144,7 +157,8 @@ void ChatbarTextEdit::doResize() { } void ChatbarTextEdit::doScrollbar() { - setVerticalScrollBarPolicy(sizeHint().height() > height() ? Qt::ScrollBarAlwaysOn : Qt::ScrollBarAlwaysOff); + float documentHeight = document()->documentLayout()->documentSize().height(); + setVerticalScrollBarPolicy(documentHeight > height() ? Qt::ScrollBarAlwaysOn : Qt::ScrollBarAlwaysOff); ensureCursorVisible(); }