]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Use a custom SearchWidget instead directly using a KLineEdit. Currently the DolphinSe...
authorPeter Penz <peter.penz19@gmail.com>
Mon, 19 Jan 2009 14:25:08 +0000 (14:25 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Mon, 19 Jan 2009 14:25:08 +0000 (14:25 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=913572

src/CMakeLists.txt
src/dolphinmainwindow.cpp
src/dolphinmainwindow.h
src/dolphinsearchbox.cpp [new file with mode: 0644]
src/dolphinsearchbox.h [new file with mode: 0644]

index 03cd1ff0d10772a5f599e093cf35f99047331da1..061786ffceb3ac0fc5db48324b6371a399ce587c 100644 (file)
@@ -94,6 +94,7 @@ set(dolphin_SRCS
     dolphinmainwindow.cpp
     dolphinnewmenu.cpp
     dolphinviewcontainer.cpp
     dolphinmainwindow.cpp
     dolphinnewmenu.cpp
     dolphinviewcontainer.cpp
+    dolphinsearchbox.cpp
     dolphinstatusbar.cpp
     dolphindirlister.cpp
     dolphincontextmenu.cpp
     dolphinstatusbar.cpp
     dolphindirlister.cpp
     dolphincontextmenu.cpp
index 24e1a1f97d0bfea7b32dd3b9e39cfd252df12be9..70c28786929970fce6ef6947d6b13c5465046884 100644 (file)
@@ -28,6 +28,7 @@
 #include "dolphinnewmenu.h"
 #include "settings/dolphinsettings.h"
 #include "settings/dolphinsettingsdialog.h"
 #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"
 #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_tabBar(0),
     m_activeViewContainer(0),
     m_centralWidgetLayout(0),
-    m_searchBar(0),
+    m_searchBox(0),
     m_id(id),
     m_tabIndex(0),
     m_viewTab(),
     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());
 }
 
     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);
 
 
     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");
 
 
     stateChanged("new_file");
 
@@ -1124,15 +1123,13 @@ void DolphinMainWindow::setupActions()
     connect(openInNewWindow, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
 
     // 'Search' toolbar
     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"));
 
     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);
 }
 
     search->setShortcutConfigurable(false);
 }
 
index 9939117b7b1582417718b2b12f23f7a8a97b5289..d65a7acffae1e7ff1562d4ba2aafefd0e7808c76 100644 (file)
@@ -39,9 +39,9 @@ typedef KIO::FileUndoManager::CommandType CommandType;
 class KAction;
 class DolphinViewActionHandler;
 class DolphinApplication;
 class KAction;
 class DolphinViewActionHandler;
 class DolphinApplication;
+class DolphinSearchBox;
 class DolphinSettingsDialog;
 class DolphinViewContainer;
 class DolphinSettingsDialog;
 class DolphinViewContainer;
-class KLineEdit;
 class KNewMenu;
 class KTabBar;
 class KUrl;
 class KNewMenu;
 class KTabBar;
 class KUrl;
@@ -362,9 +362,10 @@ private slots:
     void slotTestCanDecode(const QDragMoveEvent* event, bool& accept);
 
     /**
     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);
 
 private:
     DolphinMainWindow(int id);
@@ -426,7 +427,7 @@ private:
     KTabBar* m_tabBar;
     DolphinViewContainer* m_activeViewContainer;
     QVBoxLayout* m_centralWidgetLayout;
     KTabBar* m_tabBar;
     DolphinViewContainer* m_activeViewContainer;
     QVBoxLayout* m_centralWidgetLayout;
-    KLineEdit* m_searchBar;
+    DolphinSearchBox* m_searchBox;
     int m_id;
 
     struct ViewTab
     int m_id;
 
     struct ViewTab
diff --git a/src/dolphinsearchbox.cpp b/src/dolphinsearchbox.cpp
new file mode 100644 (file)
index 0000000..4263aac
--- /dev/null
@@ -0,0 +1,76 @@
+/***************************************************************************
+ *   Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at>                  *
+ *                                                                         *
+ *   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 <kdialog.h>
+#include <kglobalsettings.h>
+#include <klineedit.h>
+#include <klocale.h>
+#include <kicon.h>
+#include <kiconloader.h>
+
+#include <QEvent>
+#include <QHBoxLayout>
+#include <QToolButton>
+
+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 (file)
index 0000000..3d25ef4
--- /dev/null
@@ -0,0 +1,58 @@
+/***************************************************************************
+ *   Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at>                  *
+ *                                                                         *
+ *   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 <QWidget>
+
+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