From 63aea62c89341dfc61d14f8ca19361591ea91612 Mon Sep 17 00:00:00 2001 From: Ivan Pelipenko Date: Fri, 22 Jan 2021 18:02:53 +0300 Subject: [PATCH] LogView changes - registerCategory() now take two QBrush: text and background. If NoBrush the no changes in colors --- CMakeLists.txt | 4 ++-- libs/application/logview.cpp | 16 ++++++++++------ libs/application/logview.h | 9 ++++++--- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ed68802..1f2ce01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.0) cmake_policy(SET CMP0017 NEW) # need include() with .cmake project(qad) set(qad_MAJOR 1) -set(qad_MINOR 14) -set(qad_REVISION 4) +set(qad_MINOR 15) +set(qad_REVISION 0) set(qad_SUFFIX ) set(qad_COMPANY SHS) set(qad_DOMAIN org.SHS) diff --git a/libs/application/logview.cpp b/libs/application/logview.cpp index fff32d8..8b4d075 100644 --- a/libs/application/logview.cpp +++ b/libs/application/logview.cpp @@ -97,7 +97,7 @@ int LogView::linesLimit() const { } -void LogView::registerCategory(const QString & label, QString keyword, const QImage & icon, QColor color, bool bold) { +void LogView::registerCategory(const QString & label, QString keyword, const QImage & icon, QBrush text_brush, QBrush background, bool bold) { QRegularExpression regexp(keyword, #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) QRegularExpression::PatternOptions(QRegularExpression::CaseInsensitiveOption) @@ -105,18 +105,19 @@ void LogView::registerCategory(const QString & label, QString keyword, const QIm Qt::CaseInsensitive #endif ); - registerCategory(label, regexp, icon, color, bold); + registerCategory(label, regexp, icon, text_brush, background, bold); } -void LogView::registerCategory(const QString & label, QRegularExpression regexp, const QImage & icon, QColor color, bool bold) { +void LogView::registerCategory(const QString & label, QRegularExpression regexp, const QImage & icon, QBrush text_brush, QBrush background, bool bold) { if (!regexp.isValid() || regexp.pattern().isEmpty()) return; removeCategory(regexp); Category c; c.regexp = regexp; c.label = label; c.image = icon; - c.color = color; + c.text_brush = text_brush; + c.background = background; c.bold = bold; c.makeIcon(iconImageSize(), preferredIconSize(1., this)); categories.append(c); @@ -223,7 +224,10 @@ void LogView::newLine(const QString & keyword) { if (matched) { QTextCharFormat cf = def_cf; QTextBlockFormat bf = def_bf; - bf.setBackground(c.color); + if (c.text_brush != Qt::NoBrush) + cf.setForeground(c.text_brush); + if (c.background != Qt::NoBrush) + bf.setBackground(c.background); if (c.bold) cf.setFontWeight(QFont::Bold); tc.setCharFormat(cf); @@ -246,8 +250,8 @@ void LogView::newLine(const QString & keyword) { if (isFilterVisible()) filterBlock(tc.block(), fs, regexp); tc.movePosition(QTextCursor::End); - tc.insertBlock(); tc.setCharFormat(def_cf); + tc.insertBlock(); tc.setBlockFormat(def_bf); } diff --git a/libs/application/logview.h b/libs/application/logview.h index 46cd1ef..490bb01 100644 --- a/libs/application/logview.h +++ b/libs/application/logview.h @@ -60,13 +60,15 @@ public: void registerCategory(const QString & label, QString keyword = QString(), const QImage & icon = QImage(), - QColor color = QColor(), + QBrush text_brush = Qt::NoBrush, + QBrush background = Qt::NoBrush, bool bold = false); void registerCategory(const QString & label, QRegularExpression regexp, const QImage & icon = QImage(), - QColor color = QColor(), + QBrush text_brush = Qt::NoBrush, + QBrush background = Qt::NoBrush, bool bold = false); void removeCategory(QString keyword); void removeCategory(QRegularExpression regexp); @@ -83,7 +85,8 @@ private: QRegularExpression regexp; QImage image, icon_image; QIcon icon; - QColor color; + QBrush text_brush; + QBrush background; bool bold; inline bool operator ==(const Category & it) const {return (regexp.pattern() == it.regexp.pattern());} };