Skip to content

Commit

Permalink
FIX(client): Chatbar
Browse files Browse the repository at this point in the history
  • Loading branch information
Hartmnt committed Sep 30, 2024
1 parent 0a033af commit f2478be
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/mumble/CustomElements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,14 @@ void ChatbarTextEdit::dropEvent(QDropEvent *evt) {
}
}

#include <QDebug>

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("<center>Type chat message here</center>"));
Expand All @@ -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;
}
Expand All @@ -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();
}

Expand Down

0 comments on commit f2478be

Please sign in to comment.