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)
search_next->setIcon(QIcon::fromTheme(QStringLiteral("go-down")));
connect(button_search, &QToolButton::toggled, this, [&](bool toggled) {
search_frame->setVisible(toggled);
search_line->setFocus();
});
connect(search_line, &QLineEdit::textChanged, [this](const QString &searchText) {
QPalette palette = this->palette();
QColor col = palette.color(QPalette::Base);
if (searchText.length() > 2) {
int ix = listWidget->currentRow();
int startIx = ix;
bool found = false;
QListWidgetItem *item;
while (!found && ix < listWidget->count()) {
while (!found) {
item = listWidget->item(ix);
if (item) {
if (item->text().contains(searchText)) {
listWidget->setCurrentRow(ix);
col.setGreen(qMin(255, static_cast<int>(col.green() * 1.5)));
palette.setColor(QPalette::Base,col);
found = true;
break;
}
}
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]() {
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