mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 04:37:48 +02:00
Toggle next for search on Log
This commit is contained in:
parent
3e52091dee
commit
c01d0b309e
2 changed files with 29 additions and 1 deletions
|
@ -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>
|
||||||
|
|
||||||
|
@ -25,6 +26,7 @@ const int INITIAL_HEIGHT = 480;
|
||||||
const int MINIMAL_WIDTH = 570;
|
const int MINIMAL_WIDTH = 570;
|
||||||
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_NEXT_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,9 +77,16 @@ 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;
|
||||||
_searchTextBox->show();
|
_searchTextBox->show();
|
||||||
connect(_searchTextBox, SIGNAL(textChanged(QString)), SLOT(handleSearchTextChanged(QString)));
|
connect(_searchTextBox, SIGNAL(textChanged(QString)), SLOT(handleSearchTextChanged(QString)));
|
||||||
|
|
||||||
|
_searchNextButton = new QPushButton(this);
|
||||||
|
_searchNextButton->setObjectName("searchNextButton");
|
||||||
|
_searchNextButton->setGeometry(_leftPad, ELEMENT_MARGIN, SEARCH_NEXT_BUTTON_WIDTH, ELEMENT_HEIGHT);
|
||||||
|
_leftPad += SEARCH_NEXT_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);
|
||||||
|
@ -105,11 +114,28 @@ void BaseLogDialog::handleSearchButton() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseLogDialog::handleSearchTextChanged(QString searchText) {
|
void BaseLogDialog::handleSearchTextChanged(QString searchText) {
|
||||||
|
QTextCursor searchCursor = _logTextBox->textCursor();
|
||||||
|
searchCursor.setPosition(0, QTextCursor::MoveAnchor);
|
||||||
|
_logTextBox->setTextCursor(searchCursor);
|
||||||
|
bool foundTerm = _logTextBox->find(searchText);
|
||||||
|
|
||||||
|
if (!foundTerm) {
|
||||||
|
searchCursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
|
||||||
|
}
|
||||||
|
|
||||||
_searchTerm = searchText;
|
_searchTerm = searchText;
|
||||||
_highlighter->keyword = searchText;
|
_highlighter->keyword = searchText;
|
||||||
_highlighter->rehighlight();
|
_highlighter->rehighlight();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BaseLogDialog::toggleSearchNext() {
|
||||||
|
QTextCursor searchCursor = _logTextBox->textCursor();
|
||||||
|
if (searchCursor.hasSelection()) {
|
||||||
|
QString selectedTerm = searchCursor.selectedText();
|
||||||
|
_logTextBox->find(selectedTerm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void BaseLogDialog::showLogData() {
|
void BaseLogDialog::showLogData() {
|
||||||
_logTextBox->clear();
|
_logTextBox->clear();
|
||||||
_logTextBox->appendPlainText(getCurrentLog());
|
_logTextBox->appendPlainText(getCurrentLog());
|
||||||
|
|
|
@ -37,6 +37,7 @@ public slots:
|
||||||
private slots:
|
private slots:
|
||||||
void handleSearchButton();
|
void handleSearchButton();
|
||||||
void handleSearchTextChanged(QString text);
|
void handleSearchTextChanged(QString text);
|
||||||
|
void toggleSearchNext();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int _leftPad { 0 };
|
int _leftPad { 0 };
|
||||||
|
@ -49,6 +50,7 @@ private:
|
||||||
QPushButton* _searchButton { nullptr };
|
QPushButton* _searchButton { nullptr };
|
||||||
QLineEdit* _searchTextBox { nullptr };
|
QLineEdit* _searchTextBox { nullptr };
|
||||||
QPlainTextEdit* _logTextBox { nullptr };
|
QPlainTextEdit* _logTextBox { nullptr };
|
||||||
|
QPushButton* _searchNextButton { nullptr };
|
||||||
QString _searchTerm;
|
QString _searchTerm;
|
||||||
KeywordHighlighter* _highlighter { nullptr };
|
KeywordHighlighter* _highlighter { nullptr };
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue