Refresh custom colors once color scheme is changed
[qBittorrent.git] / src / gui / log / logmodel.h
blob7056d25f00199e55d23f988460708fd759dda0d3
1 /*
2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2024 Vladimir Golovnev <glassez@yandex.ru>
4 * Copyright (C) 2020 Prince Gupta <jagannatharjun11@gmail.com>
5 * Copyright (C) 2019 sledgehammer999 <hammered999@gmail.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * In addition, as a special exception, the copyright holders give permission to
22 * link this program with the OpenSSL project's "OpenSSL" library (or with
23 * modified versions of it that use the same license as the "OpenSSL" library),
24 * and distribute the linked executables. You must obey the GNU General Public
25 * License in all respects for all of the code used other than "OpenSSL". If you
26 * modify file(s), you may extend this exception to your version of the file(s),
27 * but you are not obligated to do so. If you do not wish to do so, delete this
28 * exception statement from your version.
31 #pragma once
33 #include <boost/circular_buffer.hpp>
35 #include <QAbstractListModel>
36 #include <QColor>
37 #include <QHash>
39 #include "base/logger.h"
41 class BaseLogModel : public QAbstractListModel
43 Q_DISABLE_COPY_MOVE(BaseLogModel)
45 public:
46 enum MessageTypeRole
48 TimeRole = Qt::UserRole,
49 MessageRole,
50 TimeForegroundRole,
51 MessageForegroundRole,
52 TypeRole
55 explicit BaseLogModel(QObject *parent = nullptr);
57 int rowCount(const QModelIndex &parent = {}) const override;
58 int columnCount(const QModelIndex &parent = {}) const override;
59 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
60 void reset();
62 protected:
63 class Message
65 public:
66 Message(const QString &time, const QString &message, Log::MsgType type);
68 QString time() const;
69 QString message() const;
70 Log::MsgType type() const;
72 private:
73 QString m_time;
74 QString m_message;
75 Log::MsgType m_type;
78 void addNewMessage(const Message &message);
79 virtual QColor messageForeground(const Message &message) const = 0;
80 virtual void onUIThemeChanged();
82 private:
83 void loadColors();
85 boost::circular_buffer_space_optimized<Message> m_messages;
86 QColor m_timeForeground;
89 class LogMessageModel : public BaseLogModel
91 Q_OBJECT
92 Q_DISABLE_COPY_MOVE(LogMessageModel)
94 public:
95 explicit LogMessageModel(QObject *parent = nullptr);
97 private slots:
98 void handleNewMessage(const Log::Msg &message);
100 private:
101 QColor messageForeground(const Message &message) const override;
102 void onUIThemeChanged() override;
103 void loadColors();
105 QHash<int, QColor> m_foregroundForMessageTypes;
108 class LogPeerModel : public BaseLogModel
110 Q_OBJECT
111 Q_DISABLE_COPY_MOVE(LogPeerModel)
113 public:
114 explicit LogPeerModel(QObject *parent = nullptr);
116 private slots:
117 void handleNewMessage(const Log::Peer &peer);
119 private:
120 QColor messageForeground(const Message &message) const override;
121 void onUIThemeChanged() override;
122 void loadColors();
124 QColor m_bannedPeerForeground;