mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-29 21:03:17 +02:00
Merge pull request #9677 from kunalgosar/logFilter
Revamped Search Feature on Log Window
This commit is contained in:
commit
0cdcee33d8
3 changed files with 100 additions and 2 deletions
|
@ -7,6 +7,7 @@ QPlainTextEdit {
|
||||||
color: #333333;
|
color: #333333;
|
||||||
background-color: #FFFFFF;
|
background-color: #FFFFFF;
|
||||||
border: none;
|
border: none;
|
||||||
|
selection-background-color: #7b91b5;
|
||||||
}
|
}
|
||||||
|
|
||||||
QLineEdit {
|
QLineEdit {
|
||||||
|
@ -32,6 +33,26 @@ QPushButton#searchButton {
|
||||||
border-bottom-left-radius: 9px;
|
border-bottom-left-radius: 9px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPushButton#searchNextButton {
|
||||||
|
font-family: Helvetica, Arial, sans-serif;
|
||||||
|
text-align: center;
|
||||||
|
background-color: #CCCCCC;
|
||||||
|
color: #3d3d3d;
|
||||||
|
border-width: 0;
|
||||||
|
border-radius: 9px;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPushButton#searchPrevButton {
|
||||||
|
font-family: Helvetica, Arial, sans-serif;
|
||||||
|
text-align: center;
|
||||||
|
background-color: #CCCCCC;
|
||||||
|
color: #3d3d3d;
|
||||||
|
border-width: 0;
|
||||||
|
border-radius: 9px;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
QPushButton#revealLogButton {
|
QPushButton#revealLogButton {
|
||||||
font-family: Helvetica, Arial, sans-serif;
|
font-family: Helvetica, Arial, sans-serif;
|
||||||
background: url(styles/txt-file.svg);
|
background: url(styles/txt-file.svg);
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QPlainTextEdit>
|
#include <QPlainTextEdit>
|
||||||
|
#include <QTextCursor>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QSyntaxHighlighter>
|
#include <QSyntaxHighlighter>
|
||||||
|
|
||||||
|
@ -22,9 +23,10 @@
|
||||||
const int TOP_BAR_HEIGHT = 46;
|
const int TOP_BAR_HEIGHT = 46;
|
||||||
const int INITIAL_WIDTH = 720;
|
const int INITIAL_WIDTH = 720;
|
||||||
const int INITIAL_HEIGHT = 480;
|
const int INITIAL_HEIGHT = 480;
|
||||||
const int MINIMAL_WIDTH = 570;
|
const int MINIMAL_WIDTH = 700;
|
||||||
const int SEARCH_BUTTON_LEFT = 25;
|
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_TEXT_WIDTH = 240;
|
const int SEARCH_TEXT_WIDTH = 240;
|
||||||
const QColor HIGHLIGHT_COLOR = QColor("#3366CC");
|
const QColor HIGHLIGHT_COLOR = QColor("#3366CC");
|
||||||
|
|
||||||
|
@ -75,14 +77,32 @@ void BaseLogDialog::initControls() {
|
||||||
// disable blue outline in Mac
|
// disable blue outline in Mac
|
||||||
_searchTextBox->setAttribute(Qt::WA_MacShowFocusRect, false);
|
_searchTextBox->setAttribute(Qt::WA_MacShowFocusRect, false);
|
||||||
_searchTextBox->setGeometry(_leftPad, ELEMENT_MARGIN, SEARCH_TEXT_WIDTH, ELEMENT_HEIGHT);
|
_searchTextBox->setGeometry(_leftPad, ELEMENT_MARGIN, SEARCH_TEXT_WIDTH, ELEMENT_HEIGHT);
|
||||||
_leftPad += SEARCH_TEXT_WIDTH + CHECKBOX_MARGIN;
|
_leftPad += SEARCH_TEXT_WIDTH + BUTTON_MARGIN;
|
||||||
_searchTextBox->show();
|
_searchTextBox->show();
|
||||||
connect(_searchTextBox, SIGNAL(textChanged(QString)), SLOT(handleSearchTextChanged(QString)));
|
connect(_searchTextBox, SIGNAL(textChanged(QString)), SLOT(handleSearchTextChanged(QString)));
|
||||||
|
connect(_searchTextBox, SIGNAL(returnPressed()), SLOT(toggleSearchNext()));
|
||||||
|
|
||||||
|
_searchPrevButton = new QPushButton(this);
|
||||||
|
_searchPrevButton->setObjectName("searchPrevButton");
|
||||||
|
_searchPrevButton->setGeometry(_leftPad, ELEMENT_MARGIN, SEARCH_TOGGLE_BUTTON_WIDTH, ELEMENT_HEIGHT);
|
||||||
|
_searchPrevButton->setText("Prev");
|
||||||
|
_leftPad += SEARCH_TOGGLE_BUTTON_WIDTH + BUTTON_MARGIN;
|
||||||
|
_searchPrevButton->show();
|
||||||
|
connect(_searchPrevButton, SIGNAL(clicked()), SLOT(toggleSearchPrev()));
|
||||||
|
|
||||||
|
_searchNextButton = new QPushButton(this);
|
||||||
|
_searchNextButton->setObjectName("searchNextButton");
|
||||||
|
_searchNextButton->setGeometry(_leftPad, ELEMENT_MARGIN, SEARCH_TOGGLE_BUTTON_WIDTH, ELEMENT_HEIGHT);
|
||||||
|
_searchNextButton->setText("Next");
|
||||||
|
_leftPad += SEARCH_TOGGLE_BUTTON_WIDTH + CHECKBOX_MARGIN;
|
||||||
|
_searchNextButton->show();
|
||||||
|
connect(_searchNextButton, SIGNAL(clicked()), SLOT(toggleSearchNext()));
|
||||||
|
|
||||||
_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 KeywordHighlighter(_logTextBox->document());
|
||||||
|
connect(_logTextBox, SIGNAL(selectionChanged()), SLOT(updateSelection()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,17 +125,68 @@ void BaseLogDialog::handleSearchButton() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseLogDialog::handleSearchTextChanged(QString searchText) {
|
void BaseLogDialog::handleSearchTextChanged(QString searchText) {
|
||||||
|
if (searchText.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QTextCursor cursor = _logTextBox->textCursor();
|
||||||
|
if (cursor.hasSelection()) {
|
||||||
|
QString selectedTerm = cursor.selectedText();
|
||||||
|
if (selectedTerm == searchText) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor.setPosition(0, QTextCursor::MoveAnchor);
|
||||||
|
_logTextBox->setTextCursor(cursor);
|
||||||
|
bool foundTerm = _logTextBox->find(searchText);
|
||||||
|
|
||||||
|
if (!foundTerm) {
|
||||||
|
cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
|
||||||
|
_logTextBox->setTextCursor(cursor);
|
||||||
|
}
|
||||||
|
|
||||||
_searchTerm = searchText;
|
_searchTerm = searchText;
|
||||||
_highlighter->keyword = searchText;
|
_highlighter->keyword = searchText;
|
||||||
_highlighter->rehighlight();
|
_highlighter->rehighlight();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BaseLogDialog::toggleSearchPrev() {
|
||||||
|
QTextCursor searchCursor = _logTextBox->textCursor();
|
||||||
|
if (searchCursor.hasSelection()) {
|
||||||
|
QString selectedTerm = searchCursor.selectedText();
|
||||||
|
_logTextBox->find(selectedTerm, QTextDocument::FindBackward);
|
||||||
|
} else {
|
||||||
|
handleSearchTextChanged(_searchTextBox->text());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseLogDialog::toggleSearchNext() {
|
||||||
|
QTextCursor searchCursor = _logTextBox->textCursor();
|
||||||
|
if (searchCursor.hasSelection()) {
|
||||||
|
QString selectedTerm = searchCursor.selectedText();
|
||||||
|
_logTextBox->find(selectedTerm);
|
||||||
|
} else {
|
||||||
|
handleSearchTextChanged(_searchTextBox->text());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void BaseLogDialog::showLogData() {
|
void BaseLogDialog::showLogData() {
|
||||||
_logTextBox->clear();
|
_logTextBox->clear();
|
||||||
_logTextBox->appendPlainText(getCurrentLog());
|
_logTextBox->appendPlainText(getCurrentLog());
|
||||||
_logTextBox->ensureCursorVisible();
|
_logTextBox->ensureCursorVisible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BaseLogDialog::updateSelection() {
|
||||||
|
QTextCursor cursor = _logTextBox->textCursor();
|
||||||
|
if (cursor.hasSelection()) {
|
||||||
|
QString selectionTerm = cursor.selectedText();
|
||||||
|
if (QString::compare(selectionTerm, _searchTextBox->text(), Qt::CaseInsensitive) != 0) {
|
||||||
|
_searchTextBox->setText(selectionTerm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
KeywordHighlighter::KeywordHighlighter(QTextDocument* parent) : QSyntaxHighlighter(parent) {
|
KeywordHighlighter::KeywordHighlighter(QTextDocument* parent) : QSyntaxHighlighter(parent) {
|
||||||
keywordFormat.setForeground(HIGHLIGHT_COLOR);
|
keywordFormat.setForeground(HIGHLIGHT_COLOR);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ const int ELEMENT_MARGIN = 7;
|
||||||
const int ELEMENT_HEIGHT = 32;
|
const int ELEMENT_HEIGHT = 32;
|
||||||
const int CHECKBOX_MARGIN = 12;
|
const int CHECKBOX_MARGIN = 12;
|
||||||
const int CHECKBOX_WIDTH = 140;
|
const int CHECKBOX_WIDTH = 140;
|
||||||
|
const int BUTTON_MARGIN = 8;
|
||||||
|
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
|
@ -35,8 +36,11 @@ public slots:
|
||||||
void appendLogLine(QString logLine);
|
void appendLogLine(QString logLine);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void updateSelection();
|
||||||
void handleSearchButton();
|
void handleSearchButton();
|
||||||
void handleSearchTextChanged(QString text);
|
void handleSearchTextChanged(QString text);
|
||||||
|
void toggleSearchPrev();
|
||||||
|
void toggleSearchNext();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int _leftPad { 0 };
|
int _leftPad { 0 };
|
||||||
|
@ -49,6 +53,8 @@ private:
|
||||||
QPushButton* _searchButton { nullptr };
|
QPushButton* _searchButton { nullptr };
|
||||||
QLineEdit* _searchTextBox { nullptr };
|
QLineEdit* _searchTextBox { nullptr };
|
||||||
QPlainTextEdit* _logTextBox { nullptr };
|
QPlainTextEdit* _logTextBox { nullptr };
|
||||||
|
QPushButton* _searchPrevButton { nullptr };
|
||||||
|
QPushButton* _searchNextButton { nullptr };
|
||||||
QString _searchTerm;
|
QString _searchTerm;
|
||||||
KeywordHighlighter* _highlighter { nullptr };
|
KeywordHighlighter* _highlighter { nullptr };
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue