mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 16:55:07 +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;
|
||||
background-color: #FFFFFF;
|
||||
border: none;
|
||||
selection-background-color: #7b91b5;
|
||||
}
|
||||
|
||||
QLineEdit {
|
||||
|
@ -32,6 +33,26 @@ QPushButton#searchButton {
|
|||
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 {
|
||||
font-family: Helvetica, Arial, sans-serif;
|
||||
background: url(styles/txt-file.svg);
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <QDir>
|
||||
#include <QLineEdit>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QTextCursor>
|
||||
#include <QPushButton>
|
||||
#include <QSyntaxHighlighter>
|
||||
|
||||
|
@ -22,9 +23,10 @@
|
|||
const int TOP_BAR_HEIGHT = 46;
|
||||
const int INITIAL_WIDTH = 720;
|
||||
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_WIDTH = 20;
|
||||
const int SEARCH_TOGGLE_BUTTON_WIDTH = 50;
|
||||
const int SEARCH_TEXT_WIDTH = 240;
|
||||
const QColor HIGHLIGHT_COLOR = QColor("#3366CC");
|
||||
|
||||
|
@ -75,14 +77,32 @@ void BaseLogDialog::initControls() {
|
|||
// disable blue outline in Mac
|
||||
_searchTextBox->setAttribute(Qt::WA_MacShowFocusRect, false);
|
||||
_searchTextBox->setGeometry(_leftPad, ELEMENT_MARGIN, SEARCH_TEXT_WIDTH, ELEMENT_HEIGHT);
|
||||
_leftPad += SEARCH_TEXT_WIDTH + CHECKBOX_MARGIN;
|
||||
_leftPad += SEARCH_TEXT_WIDTH + BUTTON_MARGIN;
|
||||
_searchTextBox->show();
|
||||
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->setReadOnly(true);
|
||||
_logTextBox->show();
|
||||
_highlighter = new KeywordHighlighter(_logTextBox->document());
|
||||
connect(_logTextBox, SIGNAL(selectionChanged()), SLOT(updateSelection()));
|
||||
|
||||
}
|
||||
|
||||
|
@ -105,17 +125,68 @@ void BaseLogDialog::handleSearchButton() {
|
|||
}
|
||||
|
||||
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;
|
||||
_highlighter->keyword = searchText;
|
||||
_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() {
|
||||
_logTextBox->clear();
|
||||
_logTextBox->appendPlainText(getCurrentLog());
|
||||
_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) {
|
||||
keywordFormat.setForeground(HIGHLIGHT_COLOR);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ const int ELEMENT_MARGIN = 7;
|
|||
const int ELEMENT_HEIGHT = 32;
|
||||
const int CHECKBOX_MARGIN = 12;
|
||||
const int CHECKBOX_WIDTH = 140;
|
||||
const int BUTTON_MARGIN = 8;
|
||||
|
||||
class QPushButton;
|
||||
class QLineEdit;
|
||||
|
@ -35,8 +36,11 @@ public slots:
|
|||
void appendLogLine(QString logLine);
|
||||
|
||||
private slots:
|
||||
void updateSelection();
|
||||
void handleSearchButton();
|
||||
void handleSearchTextChanged(QString text);
|
||||
void toggleSearchPrev();
|
||||
void toggleSearchNext();
|
||||
|
||||
protected:
|
||||
int _leftPad { 0 };
|
||||
|
@ -49,6 +53,8 @@ private:
|
|||
QPushButton* _searchButton { nullptr };
|
||||
QLineEdit* _searchTextBox { nullptr };
|
||||
QPlainTextEdit* _logTextBox { nullptr };
|
||||
QPushButton* _searchPrevButton { nullptr };
|
||||
QPushButton* _searchNextButton { nullptr };
|
||||
QString _searchTerm;
|
||||
KeywordHighlighter* _highlighter { nullptr };
|
||||
|
||||
|
|
Loading…
Reference in a new issue