Change searchbar background color to red(ish) when no match found

This commit is contained in:
Christian Surlykke
2013-01-17 17:02:51 +01:00
parent e67682a663
commit c3d72a638a
4 changed files with 34 additions and 8 deletions
+7 -6
View File
@@ -48,12 +48,13 @@ void HistorySearch::search() {
} else {
found = search(0, 0, m_startColumn, m_startLine) || search(m_startColumn, m_startLine, -1, m_emulation->lineCount());
}
}
if (found) {
emit matchFound(m_foundStartColumn, m_foundStartLine, m_foundEndColumn, m_foundEndLine);
} else {
emit noMatchFound();
if (found) {
emit matchFound(m_foundStartColumn, m_foundStartLine, m_foundEndColumn, m_foundEndLine);
}
else {
emit noMatchFound();
}
}
deleteLater();
+24 -2
View File
@@ -67,6 +67,13 @@ void SearchBar::toggleShown()
isHidden() ? show() : hide();
}
void SearchBar::noMatchFound()
{
QPalette palette;
palette.setColor(widget.searchTextEdit->backgroundRole(), QColor(255, 128, 128));
widget.searchTextEdit->setPalette(palette);
}
void SearchBar::searchTextChanged()
{
m_regExp = QRegExp(widget.searchTextEdit->text());
@@ -77,8 +84,13 @@ void SearchBar::searchTextChanged()
if (! m_matchCaseMenuEntry->isChecked()) {
m_regExp.setCaseSensitivity(Qt::CaseInsensitive);
}
emit search(m_regExp, true, false);
clearBackgroundColor();
if (!m_regExp.isEmpty())
{
emit search(m_regExp, true, false);
}
}
void SearchBar::keyReleaseEvent(QKeyEvent* keyEvent)
@@ -102,10 +114,20 @@ void SearchBar::keyReleaseEvent(QKeyEvent* keyEvent)
void SearchBar::findNext()
{
clearBackgroundColor();
emit search(m_regExp, true, true);
}
void SearchBar::findPrevious()
{
clearBackgroundColor();
emit search(m_regExp, false, false);
}
void SearchBar::clearBackgroundColor()
{
QPalette p;
p.setColor(QPalette::Base, Qt::white);
widget.searchTextEdit->setPalette(p);
}
+2
View File
@@ -34,6 +34,7 @@ public:
public slots:
void toggleShown();
void noMatchFound();
signals:
void search(QRegExp regexp, bool forwards, bool skip);
@@ -45,6 +46,7 @@ private slots:
void searchTextChanged();
void findNext();
void findPrevious();
void clearBackgroundColor();
private:
QRegExp m_regExp;
+1
View File
@@ -148,6 +148,7 @@ void QTermWidget::search(QRegExp regexp, bool forwards, bool next)
new HistorySearch(m_impl->m_session->emulation(), regexp, forwards, startColumn, startLine, this);
connect(historySearch, SIGNAL(matchFound(int, int, int, int)), this, SLOT(matchFound(int, int, int, int)));
connect(historySearch, SIGNAL(noMatchFound()), this, SLOT(noMatchFound()));
connect(historySearch, SIGNAL(noMatchFound()), m_searchBar, SLOT(noMatchFound()));
historySearch->search();
}