소스 검색

UI: Fix rendering of spaces & tabs in Log Viewer

For some reason, the combination of QPlainTextEdit and a HTML block
seems to treat spaces as HTML shoult (only display one, no tabs, etc)
rather than how QTextEdit + HTML does, which is strange. As we don't
need HTML for existing log lines, insert them as plaintext, but for
new entries wrap non-error non-warning messages in a <font> tag and
format that with white-space: pre
Matt Gajownik 3 년 전
부모
커밋
f77ab0e199
1개의 변경된 파일7개의 추가작업 그리고 1개의 파일을 삭제
  1. 7 1
      UI/log-viewer.cpp

+ 7 - 1
UI/log-viewer.cpp

@@ -27,6 +27,9 @@ OBSLogViewer::OBSLogViewer(QWidget *parent) : QDialog(parent)
 	textArea = new QPlainTextEdit();
 	textArea->setReadOnly(true);
 	textArea->setFont(fixedFont);
+	// Fix display of tabs & multiple spaces
+	textArea->document()->setDefaultStyleSheet(
+		"font { white-space: pre; }");
 
 	QHBoxLayout *buttonLayout = new QHBoxLayout();
 	QPushButton *clearButton = new QPushButton(QTStr("Clear"));
@@ -112,7 +115,7 @@ void OBSLogViewer::InitLog()
 		cursor.beginEditBlock();
 		while (!in.atEnd()) {
 			QString line = in.readLine();
-			cursor.insertHtml(line);
+			cursor.insertText(line);
 			cursor.insertBlock();
 		}
 		cursor.endEditBlock();
@@ -136,6 +139,9 @@ void OBSLogViewer::AddLine(int type, const QString &str)
 	case LOG_ERROR:
 		msg = QString("<font color=\"#c00000\">%1</font>").arg(msg);
 		break;
+	default:
+		msg = QString("<font>%1</font>").arg(msg);
+		break;
 	}
 
 	QScrollBar *scroll = textArea->verticalScrollBar();