Skip to content

Commit

Permalink
Merge PR #5866: Backport "FIX(client, ui): resolve log text scaling i…
Browse files Browse the repository at this point in the history
…ssues"
  • Loading branch information
Krzmbrzl authored Sep 9, 2022
2 parents ea3fe75 + 15ac2c5 commit 47e8321
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/mumble/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,9 @@ QString Log::validHtml(const QString &html, QTextCursor *tc) {
}

if (tc) {
tc->insertHtml(qtd.toHtml());
QTextCursor tcNew(&qtd);
tcNew.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
tc->insertFragment(tcNew.selection());
return QString();
} else {
return qtd.toHtml();
Expand All @@ -642,17 +644,29 @@ void Log::log(MsgType mt, const QString &console, const QString &terse, bool own
if ((flags & Settings::LogConsole)) {
QTextCursor tc = Global::get().mw->qteLog->textCursor();

tc.movePosition(QTextCursor::End);

// A newline is inserted after each frame, but this spaces out the
// log entries too much, so the font size is set to near-zero in order
// to reduce the space between log entries. This font size is set only
// for the blank lines between entries, not for entries themselves.
QTextCharFormat cf = tc.blockCharFormat();
cf.setFontPointSize(0.01);
tc.setBlockCharFormat(cf);

// We copy the value from the settings in order to make sure that
// we use the same margin everywhere while in this method (even if
// the setting might change in that time).
const int msgMargin = Global::get().s.iChatMessageMargins;

QTextFrameFormat qttf;
qttf.setTopMargin(0);
qttf.setBottomMargin(msgMargin);

LogTextBrowser *tlog = Global::get().mw->qteLog;
const int oldscrollvalue = tlog->getLogScroll();
const bool scroll = (oldscrollvalue == tlog->getLogScrollMaximum());

tc.movePosition(QTextCursor::End);

if (qdDate != dt.date()) {
qdDate = dt.date();
tc.insertBlock();
Expand All @@ -665,13 +679,6 @@ void Log::log(MsgType mt, const QString &console, const QString &terse, bool own
QString fixedNLPlain =
plain.replace(QLatin1String("\r\n"), QLatin1String("\n")).replace(QLatin1String("\r"), QLatin1String("\n"));

QTextFrameFormat qttf;
// `insertFrame` causes a blank line to precede the inserted frame.
// This is remedied by setting a negative top margin of equal height.
static int lineSpacing = QFontMetrics(tc.currentFrame()->format().toCharFormat().font()).lineSpacing();
qttf.setTopMargin(-lineSpacing);
qttf.setBottomMargin(msgMargin);

if (fixedNLPlain.contains(QRegExp(QLatin1String("\\n[ \\t]*$")))) {
// If the message ends with one or more blank lines (or lines only containing whitespace)
// paint a border around the message to make clear that it contains invisible parts.
Expand All @@ -692,6 +699,9 @@ void Log::log(MsgType mt, const QString &console, const QString &terse, bool own
tc.movePosition(QTextCursor::End);
Global::get().mw->qteLog->setTextCursor(tc);

// Shrink trailing blank line after the most recent log entry.
tc.setBlockCharFormat(cf);

if (scroll || ownMessage)
tlog->scrollLogToBottom();
else
Expand Down

0 comments on commit 47e8321

Please sign in to comment.