mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-08 08:22:09 +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 <QLineEdit>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QTextCursor>
|
||||
#include <QPushButton>
|
||||
#include <QSyntaxHighlighter>
|
||||
|
||||
|
@ -25,6 +26,7 @@ const int INITIAL_HEIGHT = 480;
|
|||
const int MINIMAL_WIDTH = 570;
|
||||
const int SEARCH_BUTTON_LEFT = 25;
|
||||
const int SEARCH_BUTTON_WIDTH = 20;
|
||||
const int SEARCH_NEXT_BUTTON_WIDTH = 50;
|
||||
const int SEARCH_TEXT_WIDTH = 240;
|
||||
const QColor HIGHLIGHT_COLOR = QColor("#3366CC");
|
||||
|
||||
|
@ -75,9 +77,16 @@ 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;
|
||||
_searchTextBox->show();
|
||||
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->setReadOnly(true);
|
||||
|
@ -105,11 +114,28 @@ void BaseLogDialog::handleSearchButton() {
|
|||
}
|
||||
|
||||
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;
|
||||
_highlighter->keyword = searchText;
|
||||
_highlighter->rehighlight();
|
||||
}
|
||||
|
||||
void BaseLogDialog::toggleSearchNext() {
|
||||
QTextCursor searchCursor = _logTextBox->textCursor();
|
||||
if (searchCursor.hasSelection()) {
|
||||
QString selectedTerm = searchCursor.selectedText();
|
||||
_logTextBox->find(selectedTerm);
|
||||
}
|
||||
}
|
||||
|
||||
void BaseLogDialog::showLogData() {
|
||||
_logTextBox->clear();
|
||||
_logTextBox->appendPlainText(getCurrentLog());
|
||||
|
|
|
@ -37,6 +37,7 @@ public slots:
|
|||
private slots:
|
||||
void handleSearchButton();
|
||||
void handleSearchTextChanged(QString text);
|
||||
void toggleSearchNext();
|
||||
|
||||
protected:
|
||||
int _leftPad { 0 };
|
||||
|
@ -49,6 +50,7 @@ private:
|
|||
QPushButton* _searchButton { nullptr };
|
||||
QLineEdit* _searchTextBox { nullptr };
|
||||
QPlainTextEdit* _logTextBox { nullptr };
|
||||
QPushButton* _searchNextButton { nullptr };
|
||||
QString _searchTerm;
|
||||
KeywordHighlighter* _highlighter { nullptr };
|
||||
|
||||
|
|
Loading…
Reference in a new issue