┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/search/dolphinsearchbox.cpp
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2010-10-10 16:13:24 +0000
committerPeter Penz <[email protected]>2010-10-10 16:13:24 +0000
commit717a665c4e6c0c9455ed46163216e7525f36ff87 (patch)
tree003290f7efd9c5095ecfc7ee47f284979d0068dc /src/search/dolphinsearchbox.cpp
parent35f8c9d7b077ffff65ad23a5b1813a72465f5bd2 (diff)
Automatically start the searching if the user did not change the search-text for at least a second.
svn path=/trunk/KDE/kdebase/apps/; revision=1184510
Diffstat (limited to 'src/search/dolphinsearchbox.cpp')
-rw-r--r--src/search/dolphinsearchbox.cpp34
1 files changed, 30 insertions, 4 deletions
diff --git a/src/search/dolphinsearchbox.cpp b/src/search/dolphinsearchbox.cpp
index 644736952..f12df73f3 100644
--- a/src/search/dolphinsearchbox.cpp
+++ b/src/search/dolphinsearchbox.cpp
@@ -34,6 +34,7 @@
#include <QKeyEvent>
#include <QLabel>
#include <QPushButton>
+#include <QTimer>
#include <QToolButton>
#include <QVBoxLayout>
@@ -66,7 +67,8 @@ DolphinSearchBox::DolphinSearchBox(QWidget* parent) :
m_filterButton(0),
m_filterWidgetsLayout(0),
m_filterWidgets(),
- m_searchPath()
+ m_searchPath(),
+ m_startSearchTimer(0)
{
}
@@ -156,6 +158,7 @@ void DolphinSearchBox::keyReleaseEvent(QKeyEvent* event)
void DolphinSearchBox::emitSearchSignal()
{
+ m_startSearchTimer->stop();
m_startedSearching = true;
emit search(m_searchInput->text());
}
@@ -167,6 +170,22 @@ void DolphinSearchBox::slotConfigurationChanged()
}
}
+void DolphinSearchBox::slotSearchTextChanged(const QString& text)
+{
+ if (text.isEmpty()) {
+ m_startSearchTimer->stop();
+ } else {
+ m_startSearchTimer->start();
+ }
+ emit searchTextChanged(text);
+}
+
+void DolphinSearchBox::slotReturnPressed(const QString& text)
+{
+ emitSearchSignal();
+ emit returnPressed(text);
+}
+
void DolphinSearchBox::setFilterWidgetsVisible(bool visible)
{
#ifdef HAVE_NEPOMUK
@@ -241,10 +260,10 @@ void DolphinSearchBox::init()
m_searchInput = new KLineEdit(this);
m_searchInput->setClearButtonShown(true);
m_searchInput->setFont(KGlobalSettings::generalFont());
- connect(m_searchInput, SIGNAL(returnPressed()),
- this, SLOT(emitSearchSignal()));
+ connect(m_searchInput, SIGNAL(returnPressed(QString)),
+ this, SLOT(slotReturnPressed(QString)));
connect(m_searchInput, SIGNAL(textChanged(QString)),
- this, SIGNAL(searchTextChanged(QString)));
+ this, SLOT(slotSearchTextChanged(QString)));
// Apply layout for the search input
QHBoxLayout* searchInputLayout = new QHBoxLayout();
@@ -304,6 +323,13 @@ void DolphinSearchBox::init()
searchLabel->setBuddy(m_searchInput);
loadSettings();
+
+ // The searching should be started automatically after the user did not change
+ // the text within one second
+ m_startSearchTimer = new QTimer(this);
+ m_startSearchTimer->setSingleShot(true);
+ m_startSearchTimer->setInterval(1000);
+ connect(m_startSearchTimer, SIGNAL(timeout()), this, SLOT(emitSearchSignal()));
}
bool DolphinSearchBox::isSearchPathIndexed() const