mirror of
https://github.com/overte-org/overte.git
synced 2025-04-14 10:47:09 +02:00
bolding timestamps on log
This commit is contained in:
parent
494b602d4c
commit
a974282bdf
3 changed files with 36 additions and 13 deletions
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
QPlainTextEdit {
|
QPlainTextEdit {
|
||||||
font-family: Inconsolata, Lucida Console, Andale Mono, Monaco;
|
font-family: Courier New, Courier, Monotype;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
padding-left: 28px;
|
padding-left: 28px;
|
||||||
padding-top: 7px;
|
padding-top: 7px;
|
||||||
|
@ -11,7 +11,7 @@ QPlainTextEdit {
|
||||||
}
|
}
|
||||||
|
|
||||||
QLineEdit {
|
QLineEdit {
|
||||||
font-family: Inconsolata, Lucida Console, Andale Mono, Monaco;
|
font-family: Courier New, Courier, Monotype;
|
||||||
padding-left: 7px;
|
padding-left: 7px;
|
||||||
background-color: #CCCCCC;
|
background-color: #CCCCCC;
|
||||||
border-width: 0;
|
border-width: 0;
|
||||||
|
|
|
@ -28,17 +28,22 @@ const int SEARCH_BUTTON_LEFT = 25;
|
||||||
const int SEARCH_BUTTON_WIDTH = 20;
|
const int SEARCH_BUTTON_WIDTH = 20;
|
||||||
const int SEARCH_TOGGLE_BUTTON_WIDTH = 50;
|
const int SEARCH_TOGGLE_BUTTON_WIDTH = 50;
|
||||||
const int SEARCH_TEXT_WIDTH = 240;
|
const int SEARCH_TEXT_WIDTH = 240;
|
||||||
|
const int TIME_STAMP_LENGTH = 16;
|
||||||
const QColor HIGHLIGHT_COLOR = QColor("#3366CC");
|
const QColor HIGHLIGHT_COLOR = QColor("#3366CC");
|
||||||
|
const QColor BOLD_COLOR = QColor("#445c8c");
|
||||||
|
const QString BOLD_PATTERN = "\\[\\d*\\/.*:\\d*:\\d*\\]";
|
||||||
|
|
||||||
class KeywordHighlighter : public QSyntaxHighlighter {
|
class Highlighter : public QSyntaxHighlighter {
|
||||||
public:
|
public:
|
||||||
KeywordHighlighter(QTextDocument* parent = nullptr);
|
Highlighter(QTextDocument* parent = nullptr);
|
||||||
|
void setBold(int indexToBold);
|
||||||
QString keyword;
|
QString keyword;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void highlightBlock(const QString& text) override;
|
void highlightBlock(const QString& text) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QTextCharFormat boldFormat;
|
||||||
QTextCharFormat keywordFormat;
|
QTextCharFormat keywordFormat;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -101,9 +106,8 @@ void BaseLogDialog::initControls() {
|
||||||
_logTextBox = new QPlainTextEdit(this);
|
_logTextBox = new QPlainTextEdit(this);
|
||||||
_logTextBox->setReadOnly(true);
|
_logTextBox->setReadOnly(true);
|
||||||
_logTextBox->show();
|
_logTextBox->show();
|
||||||
_highlighter = new KeywordHighlighter(_logTextBox->document());
|
_highlighter = new Highlighter(_logTextBox->document());
|
||||||
connect(_logTextBox, SIGNAL(selectionChanged()), SLOT(updateSelection()));
|
connect(_logTextBox, SIGNAL(selectionChanged()), SLOT(updateSelection()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseLogDialog::showEvent(QShowEvent* event) {
|
void BaseLogDialog::showEvent(QShowEvent* event) {
|
||||||
|
@ -116,7 +120,9 @@ void BaseLogDialog::resizeEvent(QResizeEvent* event) {
|
||||||
|
|
||||||
void BaseLogDialog::appendLogLine(QString logLine) {
|
void BaseLogDialog::appendLogLine(QString logLine) {
|
||||||
if (logLine.contains(_searchTerm, Qt::CaseInsensitive)) {
|
if (logLine.contains(_searchTerm, Qt::CaseInsensitive)) {
|
||||||
|
int indexToBold = _logTextBox->document()->characterCount();
|
||||||
_logTextBox->appendPlainText(logLine.trimmed());
|
_logTextBox->appendPlainText(logLine.trimmed());
|
||||||
|
_highlighter->setBold(indexToBold);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,6 +181,7 @@ void BaseLogDialog::showLogData() {
|
||||||
_logTextBox->clear();
|
_logTextBox->clear();
|
||||||
_logTextBox->appendPlainText(getCurrentLog());
|
_logTextBox->appendPlainText(getCurrentLog());
|
||||||
_logTextBox->ensureCursorVisible();
|
_logTextBox->ensureCursorVisible();
|
||||||
|
_highlighter->rehighlight();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseLogDialog::updateSelection() {
|
void BaseLogDialog::updateSelection() {
|
||||||
|
@ -187,16 +194,28 @@ void BaseLogDialog::updateSelection() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KeywordHighlighter::KeywordHighlighter(QTextDocument* parent) : QSyntaxHighlighter(parent) {
|
Highlighter::Highlighter(QTextDocument* parent) : QSyntaxHighlighter(parent) {
|
||||||
|
boldFormat.setFontWeight(75);
|
||||||
|
boldFormat.setForeground(BOLD_COLOR);
|
||||||
keywordFormat.setForeground(HIGHLIGHT_COLOR);
|
keywordFormat.setForeground(HIGHLIGHT_COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeywordHighlighter::highlightBlock(const QString& text) {
|
void Highlighter::highlightBlock(const QString& text) {
|
||||||
|
QRegExp expression(BOLD_PATTERN);
|
||||||
|
|
||||||
|
int index = text.indexOf(expression, 0);
|
||||||
|
|
||||||
|
while (index >= 0) {
|
||||||
|
int length = expression.matchedLength();
|
||||||
|
setFormat(index, length, boldFormat);
|
||||||
|
index = text.indexOf(expression, index + length);
|
||||||
|
}
|
||||||
|
|
||||||
if (keyword.isNull() || keyword.isEmpty()) {
|
if (keyword.isNull() || keyword.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int index = text.indexOf(keyword, 0, Qt::CaseInsensitive);
|
index = text.indexOf(keyword, 0, Qt::CaseInsensitive);
|
||||||
int length = keyword.length();
|
int length = keyword.length();
|
||||||
|
|
||||||
while (index >= 0) {
|
while (index >= 0) {
|
||||||
|
@ -204,3 +223,7 @@ void KeywordHighlighter::highlightBlock(const QString& text) {
|
||||||
index = text.indexOf(keyword, index + length, Qt::CaseInsensitive);
|
index = text.indexOf(keyword, index + length, Qt::CaseInsensitive);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Highlighter::setBold(int indexToBold) {
|
||||||
|
setFormat(indexToBold, TIME_STAMP_LENGTH, boldFormat);
|
||||||
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ const int BUTTON_MARGIN = 8;
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
class QPlainTextEdit;
|
class QPlainTextEdit;
|
||||||
class KeywordHighlighter;
|
class Highlighter;
|
||||||
|
|
||||||
class BaseLogDialog : public QDialog {
|
class BaseLogDialog : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -56,7 +56,7 @@ private:
|
||||||
QPushButton* _searchPrevButton { nullptr };
|
QPushButton* _searchPrevButton { nullptr };
|
||||||
QPushButton* _searchNextButton { nullptr };
|
QPushButton* _searchNextButton { nullptr };
|
||||||
QString _searchTerm;
|
QString _searchTerm;
|
||||||
KeywordHighlighter* _highlighter { nullptr };
|
Highlighter* _highlighter { nullptr };
|
||||||
|
|
||||||
void initControls();
|
void initControls();
|
||||||
void showLogData();
|
void showLogData();
|
||||||
|
|
Loading…
Reference in a new issue