Mercurial > hg > easyhg
diff src/historywidget.cpp @ 555:a1d210c767ab find
Implement basic search function in both work and history tabs
author | Chris Cannam |
---|---|
date | Wed, 22 Feb 2012 14:54:30 +0000 |
parents | a17c06f773cd |
children | d932ce55c364 |
line wrap: on
line diff
--- a/src/historywidget.cpp Mon Feb 20 18:15:53 2012 +0000 +++ b/src/historywidget.cpp Wed Feb 22 14:54:30 2012 +0000 @@ -241,6 +241,7 @@ toFocus->ensureVisible(); } + updateSearchStatus(); connectSceneSignals(); } @@ -294,6 +295,38 @@ } } +void HistoryWidget::setSearchText(QString text) +{ + if (m_searchText == text) return; + m_searchText = text; + updateSearchStatus(); +} + +void HistoryWidget::updateSearchStatus() +{ + QGraphicsScene *scene = m_panned->scene(); + if (!scene) return; + + ChangesetItem *toFocus = 0; + + QList<QGraphicsItem *> items = scene->items(); + foreach (QGraphicsItem *it, items) { + + ChangesetItem *csit = dynamic_cast<ChangesetItem *>(it); + if (!csit) continue; + + bool matched = csit->setSearchText(m_searchText); + if (matched && (!toFocus || csit->row() < toFocus->row())) { + toFocus = csit; + } + csit->update(); + } + + if (toFocus) { + toFocus->ensureVisible(); + } +} + void HistoryWidget::connectSceneSignals() { ChangesetScene *scene = qobject_cast<ChangesetScene *>(m_panned->scene());