]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/search/dolphinsearchbox.cpp
DolphinView: get rid of writeStateChanged signal in setActive()
[dolphin.git] / src / search / dolphinsearchbox.cpp
index b44f19092b6f28cffed82e805d455d6bbe9bc9de..a3cec6fe7e1ea4ea55e51d34a11943cab2d2a38e 100644 (file)
@@ -60,7 +60,9 @@ DolphinSearchBox::~DolphinSearchBox()
 
 void DolphinSearchBox::setText(const QString &text)
 {
-    m_searchInput->setText(text);
+    if (m_searchInput->text() != text) {
+        m_searchInput->setText(text);
+    }
 }
 
 QString DolphinSearchBox::text() const
@@ -201,7 +203,7 @@ void DolphinSearchBox::keyReleaseEvent(QKeyEvent *event)
     QWidget::keyReleaseEvent(event);
     if (event->key() == Qt::Key_Escape) {
         if (m_searchInput->text().isEmpty()) {
-            Q_EMIT closeRequest();
+            emitCloseRequest();
         } else {
             m_searchInput->clear();
         }
@@ -261,7 +263,9 @@ void DolphinSearchBox::slotConfigurationChanged()
 void DolphinSearchBox::slotSearchTextChanged(const QString &text)
 {
     if (text.isEmpty()) {
-        m_startSearchTimer->stop();
+        // Restore URL when search box is cleared by closing and reopening the box.
+        emitCloseRequest();
+        Q_EMIT openRequest();
     } else {
         m_startSearchTimer->start();
     }
@@ -270,6 +274,10 @@ void DolphinSearchBox::slotSearchTextChanged(const QString &text)
 
 void DolphinSearchBox::slotReturnPressed()
 {
+    if (m_searchInput->text().isEmpty()) {
+        return;
+    }
+
     emitSearchRequest();
     Q_EMIT focusViewRequest();
 }
@@ -327,7 +335,7 @@ void DolphinSearchBox::init()
 {
     // Create search box
     m_searchInput = new QLineEdit(this);
-    m_searchInput->setPlaceholderText(i18n("Search..."));
+    m_searchInput->setPlaceholderText(i18n("Search"));
     m_searchInput->installEventFilter(this);
     m_searchInput->setClearButtonEnabled(true);
     m_searchInput->setFont(QFontDatabase::systemFont(QFontDatabase::GeneralFont));
@@ -443,10 +451,10 @@ void DolphinSearchBox::init()
     loadSettings();
 
     // The searching should be started automatically after the user did not change
-    // the text within one second
+    // the text for a while
     m_startSearchTimer = new QTimer(this);
     m_startSearchTimer->setSingleShot(true);
-    m_startSearchTimer->setInterval(1000);
+    m_startSearchTimer->setInterval(500);
     connect(m_startSearchTimer, &QTimer::timeout, this, &DolphinSearchBox::emitSearchRequest);
 }
 
@@ -496,10 +504,7 @@ void DolphinSearchBox::updateFromQuery(const DolphinQuery &query)
         setSearchPath(QUrl::fromLocalFile(QDir::homePath()));
     }
 
-    // If the input box has focus, do not update to avoid messing with user typing
-    if (!m_searchInput->hasFocus()) {
-        setText(query.text());
-    }
+    setText(query.text());
 
     if (query.hasContentSearch()) {
         m_contentButton->setChecked(true);
@@ -534,3 +539,5 @@ bool DolphinSearchBox::isIndexingEnabled() const
     return false;
 #endif
 }
+
+#include "moc_dolphinsearchbox.cpp"