From: Peter Penz Date: Mon, 19 Jan 2009 14:25:08 +0000 (+0000) Subject: Use a custom SearchWidget instead directly using a KLineEdit. Currently the DolphinSe... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/d85a6ec6dd3a30784c07636a77ee502dd5dae4a2?ds=sidebyside Use a custom SearchWidget instead directly using a KLineEdit. Currently the DolphinSearchWidget acts as "playground" to test some ideas. If it works well it might be a good idea moving this widget as KSearchBox (?) to kdelibs, so that it can be used by the file dialog or other applications. svn path=/trunk/KDE/kdebase/apps/; revision=913572 --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 03cd1ff0d..061786ffc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -94,6 +94,7 @@ set(dolphin_SRCS dolphinmainwindow.cpp dolphinnewmenu.cpp dolphinviewcontainer.cpp + dolphinsearchbox.cpp dolphinstatusbar.cpp dolphindirlister.cpp dolphincontextmenu.cpp diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 24e1a1f97..70c287869 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -28,6 +28,7 @@ #include "dolphinnewmenu.h" #include "settings/dolphinsettings.h" #include "settings/dolphinsettingsdialog.h" +#include "dolphinsearchbox.h" #include "dolphinstatusbar.h" #include "dolphinviewcontainer.h" #include "panels/folders/folderspanel.h" @@ -92,7 +93,7 @@ DolphinMainWindow::DolphinMainWindow(int id) : m_tabBar(0), m_activeViewContainer(0), m_centralWidgetLayout(0), - m_searchBar(0), + m_searchBox(0), m_id(id), m_tabIndex(0), m_viewTab(), @@ -843,10 +844,9 @@ void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent* event, bool& can canDecode = KUrl::List::canDecode(event->mimeData()); } -void DolphinMainWindow::searchItems() +void DolphinMainWindow::searchItems(const KUrl& url) { - const QString nepomukString = "nepomuksearch:/" + m_searchBar->text(); - m_activeViewContainer->setUrl(KUrl(nepomukString)); + m_activeViewContainer->setUrl(url); } @@ -911,9 +911,8 @@ void DolphinMainWindow::init() setupGUI(Keys | Save | Create | ToolBar); - m_searchBar->setParent(toolBar("searchToolBar")); - m_searchBar->setFont(KGlobalSettings::generalFont()); - m_searchBar->show(); + m_searchBox->setParent(toolBar("searchToolBar")); + m_searchBox->show(); stateChanged("new_file"); @@ -1124,15 +1123,13 @@ void DolphinMainWindow::setupActions() connect(openInNewWindow, SIGNAL(triggered()), this, SLOT(openInNewWindow())); // 'Search' toolbar - m_searchBar = new KLineEdit(this); - m_searchBar->setMinimumWidth(150); - m_searchBar->setClearButtonShown(true); - connect(m_searchBar, SIGNAL(returnPressed()), this, SLOT(searchItems())); + m_searchBox = new DolphinSearchBox(this); + connect(m_searchBox, SIGNAL(search(KUrl)), this, SLOT(searchItems(KUrl))); KAction* search = new KAction(this); actionCollection()->addAction("search_bar", search); search->setText(i18nc("@action:inmenu", "Search Bar")); - search->setDefaultWidget(m_searchBar); + search->setDefaultWidget(m_searchBox); search->setShortcutConfigurable(false); } diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index 9939117b7..d65a7acff 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -39,9 +39,9 @@ typedef KIO::FileUndoManager::CommandType CommandType; class KAction; class DolphinViewActionHandler; class DolphinApplication; +class DolphinSearchBox; class DolphinSettingsDialog; class DolphinViewContainer; -class KLineEdit; class KNewMenu; class KTabBar; class KUrl; @@ -362,9 +362,10 @@ private slots: void slotTestCanDecode(const QDragMoveEvent* event, bool& accept); /** - * Searchs items that match to the text entered in the search bar. + * Is connected with the Dolphin search box and searchs items that + * match to the text entered in the search bar. */ - void searchItems(); + void searchItems(const KUrl& url); private: DolphinMainWindow(int id); @@ -426,7 +427,7 @@ private: KTabBar* m_tabBar; DolphinViewContainer* m_activeViewContainer; QVBoxLayout* m_centralWidgetLayout; - KLineEdit* m_searchBar; + DolphinSearchBox* m_searchBox; int m_id; struct ViewTab diff --git a/src/dolphinsearchbox.cpp b/src/dolphinsearchbox.cpp new file mode 100644 index 000000000..4263aacf6 --- /dev/null +++ b/src/dolphinsearchbox.cpp @@ -0,0 +1,76 @@ +/*************************************************************************** + * Copyright (C) 2009 by Peter Penz * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ +#include "dolphinsearchbox.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +DolphinSearchBox::DolphinSearchBox(QWidget* parent) : + QWidget(parent), + m_searchButton(0), + m_searchInput(0) +{ + QHBoxLayout* hLayout = new QHBoxLayout(this); + hLayout->setMargin(0); + + m_searchButton = new QToolButton(this); + m_searchButton->setAutoRaise(true); + m_searchButton->setIcon(KIcon("nepomuk")); + m_searchButton->setToolTip(i18nc("@info:tooltip", "Search")); + hLayout->addWidget(m_searchButton); + + connect(m_searchButton, SIGNAL(clicked()), + this, SLOT(emitSearchSignal())); + + m_searchInput = new KLineEdit(this); + m_searchInput->setLayoutDirection(Qt::LeftToRight); + m_searchInput->setClearButtonShown(true); + m_searchInput->setMinimumWidth(150); + hLayout->addWidget(m_searchInput); + + connect(m_searchInput, SIGNAL(returnPressed()), + this, SLOT(emitSearchSignal())); +} + +DolphinSearchBox::~DolphinSearchBox() +{ +} + +bool DolphinSearchBox::event(QEvent* event) +{ + if (event->type() == QEvent::Polish) { + m_searchInput->setFont(KGlobalSettings::generalFont()); + } + return QWidget::event(event); +} + +void DolphinSearchBox::emitSearchSignal() +{ + emit search(KUrl("nepomuksearch:/" + m_searchInput->text())); +} + +#include "dolphinsearchbox.moc" diff --git a/src/dolphinsearchbox.h b/src/dolphinsearchbox.h new file mode 100644 index 000000000..3d25ef4f5 --- /dev/null +++ b/src/dolphinsearchbox.h @@ -0,0 +1,58 @@ +/*************************************************************************** + * Copyright (C) 2009 by Peter Penz * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ +#ifndef DOLPHINSEARCHBOX_H +#define DOLPHINSEARCHBOX_H + +#include + +class KLineEdit; +class KUrl; +class QToolButton; + +/** + * @brief Input box for searching files with Nepomuk. + */ +class DolphinSearchBox : public QWidget +{ + Q_OBJECT + +public: + DolphinSearchBox(QWidget* parent = 0); + virtual ~DolphinSearchBox(); + +protected: + virtual bool event(QEvent* event); + +signals: + /** + * Is emitted when the user pressed Return or Enter + * and provides the Nepomuk URL that should be used + * for searching. + */ + void search(const KUrl& url); + +private slots: + void emitSearchSignal(); + +private: + QToolButton* m_searchButton; + KLineEdit* m_searchInput; +}; + +#endif