[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdelibs/kdeui
From:       Scott Wheeler <wheeler () kde ! org>
Date:       2004-04-01 0:05:27
Message-ID: 20040401000527.0DEBF99D9 () office ! kde ! org
[Download RAW message or body]

CVS commit by wheeler: 

Add a 200 milisecond delay before starting the search.  This prevents doing
multiple searches for each letter in a word when typing quickly.

I think I prefer it this way, but I'd appreciate feedback on this.


  M +25 -2     klistviewsearchline.cpp   1.3


--- kdelibs/kdeui/klistviewsearchline.cpp  #1.2:1.3
@@ -22,4 +22,6 @@
 #include <kdebug.h>
 
+#include <qtimer.h>
+
 class KListViewSearchLine::KListViewSearchLinePrivate
 {
@@ -29,5 +31,6 @@ public:
         caseSensitive(false),
         activeSearch(false),
-        keepParentsVisible(true) {}
+        keepParentsVisible(true),
+        queuedSearches(0) {}
     
     KListView *listView;
@@ -36,4 +39,5 @@ public:
     bool keepParentsVisible;
     QString search;
+    int queuedSearches;
     QValueList<int> searchColumns;
     QValueList<QListViewItem *> parents;
@@ -52,5 +56,5 @@ KListViewSearchLine::KListViewSearchLine
 
     connect(this, SIGNAL(textChanged(const QString &)),
-            this, SLOT(updateSearch(const QString &)));
+            this, SLOT(queueSearch(const QString &)));
 
     if(listView) {
@@ -174,4 +178,23 @@ bool KListViewSearchLine::itemMatches(co
 
 ////////////////////////////////////////////////////////////////////////////////
+// protected slots
+////////////////////////////////////////////////////////////////////////////////
+
+void KListViewSearchLine::queueSearch(const QString &search)
+{
+    d->queuedSearches++;
+    d->search = search;
+    QTimer::singleShot(200, this, SLOT(activateSearch()));
+}
+
+void KListViewSearchLine::activateSearch()
+{
+    d->queuedSearches--;
+
+    if(d->queuedSearches == 0)
+        updateSearch(d->search);
+}
+
+////////////////////////////////////////////////////////////////////////////////
 // private slots
 ////////////////////////////////////////////////////////////////////////////////


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic