Files
frelay/Gui/Control/LogControl.h

66 lines
1.3 KiB
C
Raw Permalink Normal View History

#ifndef LOGCONTROL_H
2025-06-15 14:31:54 +08:00
#define LOGCONTROL_H
#include <QBrush>
#include <QGuiApplication>
#include <QMap>
#include <QMutex>
2025-06-15 14:31:54 +08:00
#include <QStandardItemModel>
#include <QStyleHints>
2025-06-15 14:31:54 +08:00
#include <QWidget>
namespace Ui {
class LogPrint;
}
enum PrintType { PT_INFO, PT_WARN, PT_ERROR, PT_DEBUG };
struct LogEntry {
QString message;
PrintType level;
};
2025-06-15 14:31:54 +08:00
class LogPrint : public QWidget
{
Q_OBJECT
public:
explicit LogPrint(QWidget* parent = nullptr);
~LogPrint();
public slots:
2025-06-15 14:31:54 +08:00
void Info(const QString& message);
void Warn(const QString& message);
void Error(const QString& message);
void Debug(const QString& message);
public:
std::string now_str();
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
void ColorChange(Qt::ColorScheme scheme);
#endif
2025-06-15 14:31:54 +08:00
private:
void InitControl();
void InitColor();
void RePrintLog();
void Print(const QString& message, PrintType type, bool recordHis = true);
2025-06-15 14:31:54 +08:00
private:
QMutex mutex_;
bool isLightMode_{true};
2025-06-15 14:31:54 +08:00
Ui::LogPrint* ui;
QMap<PrintType, QBrush> lightMap_;
QMap<PrintType, QBrush> darkMap_;
QVector<LogEntry> logEntries_;
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
QStyleHints* styleHints_{};
#endif
2025-06-15 14:31:54 +08:00
QStandardItemModel* model_;
};
#endif // LOGCONTROL_H