diff src/changesetitem.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 b5a342a71218
children 533519ebc0cb
line wrap: on
line diff
--- a/src/changesetitem.cpp	Mon Feb 20 18:15:53 2012 +0000
+++ b/src/changesetitem.cpp	Wed Feb 22 14:54:30 2012 +0000
@@ -38,7 +38,7 @@
 ChangesetItem::ChangesetItem(Changeset *cs) :
     m_changeset(cs), m_detail(0),
     m_showBranch(false), m_column(0), m_row(0), m_wide(false),
-    m_current(false), m_closing(false), m_new(false)
+    m_current(false), m_closing(false), m_new(false), m_searchMatches(false)
 {
     m_font = QFont();
     m_font.setPixelSize(11);
@@ -91,6 +91,15 @@
     emit detailHidden();
 }    
 
+bool
+ChangesetItem::setSearchText(QString text)
+{
+    m_searchText = text;
+    m_searchMatches = (m_changeset->comment().contains
+                       (text, Qt::CaseInsensitive));
+    return m_searchMatches;
+}
+
 void
 ChangesetItem::mousePressEvent(QGraphicsSceneMouseEvent *e)
 {
@@ -296,6 +305,17 @@
     bool showText = (scale >= 0.2);
     bool showProperLines = (scale >= 0.1);
 
+    if (m_searchText != "") {
+        if (m_searchMatches) {
+            userColour = QColor("#008400");
+            showProperLines = true;
+            showText = true;
+        } else {
+            branchColour = Qt::gray;
+            userColour = Qt::gray;
+        }
+    }
+
     if (!showProperLines) {
 	paint->setPen(QPen(branchColour, 0));
     } else {
@@ -452,6 +472,8 @@
 
     paint->setFont(f);
 
+    if (m_searchMatches) paint->setPen(userColour);
+
     for (int i = 0; i < lines.size(); ++i) {
 	paint->drawText(x0 + 3, i * fh + fh + fm.ascent(), lines[i].trimmed());
     }