This repository has been archived by the owner. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b69a4b9
commit 8d8ff91
Showing
6 changed files
with
485 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include "eventlog.h" | ||
|
||
EventLog::EventLog(QWidget *parent) : QPlainTextEdit (parent), | ||
m_useTimestamp(true) | ||
{ | ||
|
||
} | ||
|
||
|
||
void EventLog::setTimestamp(bool state) | ||
{ | ||
m_useTimestamp = state; | ||
} | ||
|
||
|
||
void EventLog::addMessageToBoard(const QString &message, QBrush brush) | ||
{ | ||
QTextCharFormat textFormat = this->currentCharFormat(); | ||
textFormat.setForeground(brush); | ||
this->setCurrentCharFormat(textFormat); | ||
this->appendPlainText(message); | ||
this->verticalScrollBar()->setValue(this->verticalScrollBar()->maximum()); | ||
} | ||
|
||
|
||
void EventLog::on_log(EventLogType type, const QString &message) | ||
{ | ||
auto brush = QBrush(); | ||
|
||
if (type == EventLogType::Notify) { | ||
brush.setColor(Qt::black); | ||
} | ||
else if (type == EventLogType::Log) { | ||
brush.setColor(Qt::gray); | ||
} | ||
else if (type == EventLogType::Warn) { | ||
brush.setColor(Qt::red); | ||
} | ||
|
||
QString logMessage = message; | ||
if (m_useTimestamp) { | ||
QString timestamp = QDateTime::currentDateTime().toString("[yyyyMMdd hh:mm:ss]"); | ||
logMessage = timestamp + " " + logMessage; | ||
} | ||
|
||
addMessageToBoard(logMessage, brush); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef EVENTLOG_H | ||
#define EVENTLOG_H | ||
|
||
#include <QObject> | ||
#include <QWidget> | ||
#include <QPlainTextEdit> | ||
#include <QScrollBar> | ||
#include <QDateTime> | ||
|
||
|
||
enum class EventLogType {Notify, Log, Warn}; | ||
|
||
class EventLog : public QPlainTextEdit | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit EventLog(QWidget *parent = nullptr); | ||
void setTimestamp(bool state); | ||
|
||
private: | ||
bool m_useTimestamp; | ||
void addMessageToBoard(const QString &message, QBrush brush); | ||
|
||
public slots: | ||
void on_log(EventLogType type, const QString &message); | ||
}; | ||
|
||
#endif // EVENTLOG_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.