LogView changes - registerCategory() now take two QBrush: text and background. If NoBrush the no changes in colors

This commit is contained in:
2021-01-22 18:02:53 +03:00
parent 9ba018b868
commit 63aea62c89
3 changed files with 18 additions and 11 deletions

View File

@@ -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)

View File

@@ -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);
}

View File

@@ -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());}
};