Mercurial > hg > easyhg
diff src/historywidget.cpp @ 559:95877ad67d3e
Merge from branch "find"
author | Chris Cannam |
---|---|
date | Mon, 27 Feb 2012 17:08:47 +0000 |
parents | d932ce55c364 |
children | 533519ebc0cb |
line wrap: on
line diff
--- a/src/historywidget.cpp Fri Feb 17 10:58:41 2012 +0000 +++ b/src/historywidget.cpp Mon Feb 27 17:08:47 2012 +0000 @@ -23,6 +23,7 @@ #include "grapher.h" #include "debug.h" #include "uncommitteditem.h" +#include "findwidget.h" #include <iostream> @@ -55,11 +56,21 @@ settings.beginGroup("Presentation"); bool showClosed = (settings.value("showclosedbranches", false).toBool()); + QWidget *opts = new QWidget; + QGridLayout *optLayout = new QGridLayout(opts); + optLayout->setMargin(0); + layout->addWidget(opts, ++row, 0, 1, 2); + + m_findWidget = new FindWidget(this); + optLayout->addWidget(m_findWidget, 0, 0, Qt::AlignLeft); + connect(m_findWidget, SIGNAL(findTextChanged(QString)), + this, SLOT(setSearchText(QString))); + m_showClosedBranches = new QCheckBox(tr("Show closed branches"), this); m_showClosedBranches->setChecked(showClosed); connect(m_showClosedBranches, SIGNAL(toggled(bool)), this, SLOT(showClosedChanged(bool))); - layout->addWidget(m_showClosedBranches, ++row, 0, Qt::AlignLeft); + optLayout->addWidget(m_showClosedBranches, 0, 1, Qt::AlignRight); m_showClosedBranches->hide(); setLayout(layout); @@ -241,6 +252,7 @@ toFocus->ensureVisible(); } + updateSearchStatus(); connectSceneSignals(); } @@ -294,6 +306,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());