void DolphinSearchBox::setText(const QString &text)
{
- m_searchInput->setText(text);
+ if (m_searchInput->text() != text) {
+ m_searchInput->setText(text);
+ }
}
QString DolphinSearchBox::text() const
QWidget::keyReleaseEvent(event);
if (event->key() == Qt::Key_Escape) {
if (m_searchInput->text().isEmpty()) {
- Q_EMIT closeRequest();
+ emitCloseRequest();
} else {
m_searchInput->clear();
}
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();
}
void DolphinSearchBox::slotReturnPressed()
{
+ if (m_searchInput->text().isEmpty()) {
+ return;
+ }
+
emitSearchRequest();
Q_EMIT focusViewRequest();
}
{
// 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));
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);
}
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);
return false;
#endif
}
+
+#include "moc_dolphinsearchbox.cpp"