diff --git a/src/gui/log/loglistview.cpp b/src/gui/log/loglistview.cpp index 249334283..919d677ae 100644 --- a/src/gui/log/loglistview.cpp +++ b/src/gui/log/loglistview.cpp @@ -81,7 +81,7 @@ namespace const QPen originalPen = painter->pen(); QPen coloredPen = originalPen; - coloredPen.setColor(Qt::darkGray); + coloredPen.setColor(index.data(BaseLogModel::TimeForegroundRole).value()); painter->setPen(coloredPen); const QString time = index.data(BaseLogModel::TimeRole).toString(); style->drawItemText(painter, textRect, option.displayAlignment, option.palette, (option.state & QStyle::State_Enabled), time); @@ -92,7 +92,7 @@ namespace style->drawItemText(painter, textRect.adjusted(separatorCoordinateX, 0, 0, 0), option.displayAlignment, option.palette , (option.state & QStyle::State_Enabled), SEPARATOR); - coloredPen.setColor(index.data(BaseLogModel::ForegroundRole).value()); + coloredPen.setColor(index.data(BaseLogModel::MessageForegroundRole).value()); painter->setPen(coloredPen); const int messageCoordinateX = separatorCoordinateX + horizontalAdvance(fontMetrics, SEPARATOR); style->drawItemText(painter, textRect.adjusted(messageCoordinateX, 0, 0, 0), option.displayAlignment, option.palette diff --git a/src/gui/log/logmodel.cpp b/src/gui/log/logmodel.cpp index e72be6d9e..098358e5e 100644 --- a/src/gui/log/logmodel.cpp +++ b/src/gui/log/logmodel.cpp @@ -35,6 +35,7 @@ #include #include "base/global.h" +#include "uithememanager.h" namespace { @@ -72,6 +73,7 @@ QVariant BaseLogModel::Message::type() const BaseLogModel::BaseLogModel(QObject *parent) : QAbstractListModel(parent) , m_messages(MAX_VISIBLE_MESSAGES) + , m_timeForeground(UIThemeManager::instance()->getColor(QLatin1String("Log.TimeStamp"), Qt::darkGray)) { } @@ -100,7 +102,9 @@ QVariant BaseLogModel::data(const QModelIndex &index, const int role) const return message.time(); case MessageRole: return message.message(); - case ForegroundRole: + case TimeForegroundRole: + return m_timeForeground; + case MessageForegroundRole: return message.foreground(); case TypeRole: return message.type(); @@ -134,6 +138,12 @@ void BaseLogModel::reset() LogMessageModel::LogMessageModel(QObject *parent) : BaseLogModel(parent) + , m_foregroundForMessageTypes { + {Log::NORMAL, UIThemeManager::instance()->getColor(QLatin1String("Log.Normal"), QApplication::palette().color(QPalette::WindowText))}, + {Log::INFO, UIThemeManager::instance()->getColor(QLatin1String("Log.Info"), Qt::blue)}, + {Log::WARNING, UIThemeManager::instance()->getColor(QLatin1String("Log.Warning"), QColor {255, 165, 0})}, // orange + {Log::CRITICAL, UIThemeManager::instance()->getColor(QLatin1String("Log.Critical"), Qt::red)} + } { for (const Log::Msg &msg : asConst(Logger::instance()->getMessages())) handleNewMessage(msg); @@ -144,32 +154,14 @@ void LogMessageModel::handleNewMessage(const Log::Msg &message) { const QString time = QDateTime::fromMSecsSinceEpoch(message.timestamp).toString(Qt::SystemLocaleShortDate); const QString messageText = message.message; - - QColor foreground; - switch (message.type) { - // The RGB QColor constructor is used for performance - case Log::NORMAL: - foreground = QApplication::palette().color(QPalette::WindowText); - break; - case Log::INFO: - foreground = QColor(0, 0, 255); // blue - break; - case Log::WARNING: - foreground = QColor(255, 165, 0); // orange - break; - case Log::CRITICAL: - foreground = QColor(255, 0, 0); // red - break; - default: - Q_ASSERT(false); - break; - } + const QColor foreground = m_foregroundForMessageTypes[message.type]; addNewMessage({time, messageText, foreground, message.type}); } LogPeerModel::LogPeerModel(QObject *parent) : BaseLogModel(parent) + , m_bannedPeerForeground(UIThemeManager::instance()->getColor(QLatin1String("Log.BannedPeer"), Qt::red)) { for (const Log::Peer &peer : asConst(Logger::instance()->getPeers())) handleNewMessage(peer); @@ -182,7 +174,6 @@ void LogPeerModel::handleNewMessage(const Log::Peer &peer) const QString message = peer.blocked ? tr("%1 was blocked due to %2", "0.0.0.0 was blocked due to reason").arg(peer.ip, peer.reason) : tr("%1 was banned", "0.0.0.0 was banned").arg(peer.ip); - const QColor foreground = Qt::red; - addNewMessage({time, message, foreground, Log::NORMAL}); + addNewMessage({time, message, m_bannedPeerForeground, Log::NORMAL}); } diff --git a/src/gui/log/logmodel.h b/src/gui/log/logmodel.h index a13abfdfc..4b405af5e 100644 --- a/src/gui/log/logmodel.h +++ b/src/gui/log/logmodel.h @@ -32,6 +32,8 @@ #include #include +#include +#include #include "base/logger.h" @@ -44,7 +46,8 @@ public: { TimeRole = Qt::UserRole, MessageRole, - ForegroundRole, + TimeForegroundRole, + MessageForegroundRole, TypeRole }; @@ -77,6 +80,7 @@ protected: private: boost::circular_buffer_space_optimized m_messages; + const QColor m_timeForeground; }; class LogMessageModel : public BaseLogModel @@ -89,6 +93,9 @@ public: private slots: void handleNewMessage(const Log::Msg &message); + +private: + const QHash m_foregroundForMessageTypes; }; class LogPeerModel : public BaseLogModel @@ -101,4 +108,7 @@ public: private slots: void handleNewMessage(const Log::Peer &peer); + +private: + const QColor m_bannedPeerForeground; };