Add color lines button

Signed-off-by: Yihe Li <winmikedows@hotmail.com>
This commit is contained in:
Yihe Li
2025-04-15 05:07:56 +08:00
parent 4ac6a0629b
commit 1ee1bab067
7 changed files with 55 additions and 2 deletions

View File

@ -60,6 +60,14 @@ void LogView::setWordWrap(bool wrapping)
}
}
void LogView::setColorLines(bool colorLines)
{
if (m_colorLines == colorLines)
return;
m_colorLines = colorLines;
repopulate();
}
void LogView::setModel(QAbstractItemModel* model)
{
if (m_model) {
@ -130,11 +138,11 @@ void LogView::rowsInserted(const QModelIndex& parent, int first, int last)
format.setFont(font.value<QFont>());
}
auto fg = m_model->data(idx, Qt::ForegroundRole);
if (fg.isValid()) {
if (fg.isValid() && m_colorLines) {
format.setForeground(fg.value<QColor>());
}
auto bg = m_model->data(idx, Qt::BackgroundRole);
if (bg.isValid()) {
if (bg.isValid() && m_colorLines) {
format.setBackground(bg.value<QColor>());
}
cursor.movePosition(QTextCursor::End);

View File

@ -15,6 +15,7 @@ class LogView : public QPlainTextEdit {
public slots:
void setWordWrap(bool wrapping);
void setColorLines(bool colorLines);
void findNext(const QString& what, bool reverse);
void scrollToBottom();
@ -32,4 +33,5 @@ class LogView : public QPlainTextEdit {
QTextCharFormat* m_defaultFormat = nullptr;
bool m_scroll = false;
bool m_scrolling = false;
bool m_colorLines = true;
};