Commit b9fa9d61 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Fix text edit search, highlight search line background to reflect status (found/not found)

parent 900516da
Pipeline #50404 passed with stage
in 10 minutes and 20 seconds
...@@ -117,24 +117,41 @@ TextBasedEdit::TextBasedEdit(QWidget *parent) ...@@ -117,24 +117,41 @@ TextBasedEdit::TextBasedEdit(QWidget *parent)
search_next->setIcon(QIcon::fromTheme(QStringLiteral("go-down"))); search_next->setIcon(QIcon::fromTheme(QStringLiteral("go-down")));
connect(button_search, &QToolButton::toggled, this, [&](bool toggled) { connect(button_search, &QToolButton::toggled, this, [&](bool toggled) {
search_frame->setVisible(toggled); search_frame->setVisible(toggled);
search_line->setFocus();
}); });
connect(search_line, &QLineEdit::textChanged, [this](const QString &searchText) { connect(search_line, &QLineEdit::textChanged, [this](const QString &searchText) {
QPalette palette = this->palette();
QColor col = palette.color(QPalette::Base);
if (searchText.length() > 2) { if (searchText.length() > 2) {
int ix = listWidget->currentRow(); int ix = listWidget->currentRow();
int startIx = ix;
bool found = false; bool found = false;
QListWidgetItem *item; QListWidgetItem *item;
while (!found && ix < listWidget->count()) { while (!found) {
item = listWidget->item(ix); item = listWidget->item(ix);
if (item) { if (item) {
if (item->text().contains(searchText)) { if (item->text().contains(searchText)) {
listWidget->setCurrentRow(ix); listWidget->setCurrentRow(ix);
col.setGreen(qMin(255, static_cast<int>(col.green() * 1.5)));
palette.setColor(QPalette::Base,col);
found = true; found = true;
break; break;
} }
} }
ix++; ix++;
if (ix >= listWidget->count()) {
// Reached end, start again on top
ix = 0;
}
if (ix == startIx) {
// Loop over, abort
col.setRed(qMin(255, static_cast<int>(col.red() * 1.5)));
palette.setColor(QPalette::Base,col);
break;
}
} }
} }
search_line->setPalette(palette);
}); });
connect(search_next, &QToolButton::clicked, [this]() { connect(search_next, &QToolButton::clicked, [this]() {
const QString searchText = search_line->text(); const QString searchText = search_line->text();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment