From 15ac2c5e65a7f3e999e75ebabf02e0223a196371 Mon Sep 17 00:00:00 2001 From: Dexter Gaon-Shatford Date: Mon, 22 Aug 2022 00:55:26 -0400 Subject: [PATCH] FIX(client, ui): resolve log text scaling issues Fixed chat log scaling issue introduced by PR #5619 (my fault, whoops) The bug fixed by that commit is still fixed after this PR, but the regression introduced has been resolved. Fixes #5818 (cherry picked from commit ece450aa3d8363a9b0728e23204c6b97e727ff62) --- src/mumble/Log.cpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/mumble/Log.cpp b/src/mumble/Log.cpp index 9e51ea085a8..ead281bf1bc 100644 --- a/src/mumble/Log.cpp +++ b/src/mumble/Log.cpp @@ -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(); @@ -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(); @@ -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. @@ -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