mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-23 13:04:23 +00:00
Allow changing log colors from config.json
This commit is contained in:
parent
2c100feb35
commit
cce8f178e4
@ -81,7 +81,7 @@ namespace
|
||||
|
||||
const QPen originalPen = painter->pen();
|
||||
QPen coloredPen = originalPen;
|
||||
coloredPen.setColor(Qt::darkGray);
|
||||
coloredPen.setColor(index.data(BaseLogModel::TimeForegroundRole).value<QColor>());
|
||||
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<QColor>());
|
||||
coloredPen.setColor(index.data(BaseLogModel::MessageForegroundRole).value<QColor>());
|
||||
painter->setPen(coloredPen);
|
||||
const int messageCoordinateX = separatorCoordinateX + horizontalAdvance(fontMetrics, SEPARATOR);
|
||||
style->drawItemText(painter, textRect.adjusted(messageCoordinateX, 0, 0, 0), option.displayAlignment, option.palette
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include <QPalette>
|
||||
|
||||
#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});
|
||||
}
|
||||
|
@ -32,6 +32,8 @@
|
||||
#include <boost/circular_buffer.hpp>
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QColor>
|
||||
#include <QHash>
|
||||
|
||||
#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<Message> 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<int, QColor> m_foregroundForMessageTypes;
|
||||
};
|
||||
|
||||
class LogPeerModel : public BaseLogModel
|
||||
@ -101,4 +108,7 @@ public:
|
||||
|
||||
private slots:
|
||||
void handleNewMessage(const Log::Peer &peer);
|
||||
|
||||
private:
|
||||
const QColor m_bannedPeerForeground;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user