From 884b5ad3a91fff896fb3d53e590fe26300b1c957 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Sat, 17 Oct 2009 19:24:05 +0000 Subject: [PATCH] add A search options widget, which later on will include Adam Kidder's search prototype from playground svn path=/trunk/KDE/kdebase/apps/; revision=1036776 --- src/CMakeLists.txt | 1 + src/dolphinmainwindow.cpp | 15 +++- src/dolphinmainwindow.h | 9 +++ src/search/dolphinsearchbox.cpp | 8 +- src/search/dolphinsearchbox.h | 47 ++++++------ .../dolphinsearchoptionsconfigurator.cpp | 73 +++++++++++++++++++ src/search/dolphinsearchoptionsconfigurator.h | 34 +++++++++ 7 files changed, 159 insertions(+), 28 deletions(-) create mode 100644 src/search/dolphinsearchoptionsconfigurator.cpp create mode 100644 src/search/dolphinsearchoptionsconfigurator.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 180170fbd..429695f5d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -122,6 +122,7 @@ set(dolphin_SRCS panels/folders/folderspanel.cpp panels/folders/paneltreeview.cpp search/dolphinsearchbox.cpp + search/dolphinsearchoptionsconfigurator.cpp settings/behaviorsettingspage.cpp settings/columnviewsettingspage.cpp settings/contextmenusettingspage.cpp diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 6134632ae..b16fb7f2a 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -28,6 +28,7 @@ #include "dolphinapplication.h" #include "dolphinnewmenu.h" #include "search/dolphinsearchbox.h" +#include "search/dolphinsearchoptionsconfigurator.h" #include "settings/dolphinsettings.h" #include "settings/dolphinsettingsdialog.h" #include "dolphinviewcontainer.h" @@ -109,6 +110,7 @@ DolphinMainWindow::DolphinMainWindow(int id) : m_activeViewContainer(0), m_centralWidgetLayout(0), m_searchBox(0), + m_searchOptionsConfigurator(0), m_id(id), m_tabIndex(0), m_viewTab(), @@ -983,6 +985,11 @@ void DolphinMainWindow::slotTabMoved(int from, int to) m_tabIndex = m_tabBar->currentIndex(); } +void DolphinMainWindow::slotSearchBoxTextChanged(const QString& text) +{ + m_searchOptionsConfigurator->setVisible(!text.isEmpty()); +} + void DolphinMainWindow::init() { DolphinSettings& settings = DolphinSettings::instance(); @@ -1023,6 +1030,9 @@ void DolphinMainWindow::init() connect(this, SIGNAL(urlChanged(const KUrl&)), m_remoteEncoding, SLOT(slotAboutToOpenUrl())); + m_searchOptionsConfigurator = new DolphinSearchOptionsConfigurator(this); + m_searchOptionsConfigurator->hide(); + m_tabBar = new KTabBar(this); m_tabBar->setMovable(true); m_tabBar->setTabsClosable(true); @@ -1049,8 +1059,9 @@ void DolphinMainWindow::init() m_centralWidgetLayout = new QVBoxLayout(centralWidget); m_centralWidgetLayout->setSpacing(0); m_centralWidgetLayout->setMargin(0); + m_centralWidgetLayout->addWidget(m_searchOptionsConfigurator); m_centralWidgetLayout->addWidget(m_tabBar); - m_centralWidgetLayout->addWidget(m_viewTab[m_tabIndex].splitter); + m_centralWidgetLayout->addWidget(m_viewTab[m_tabIndex].splitter, 1); setCentralWidget(centralWidget); setupDockWidgets(); @@ -1060,6 +1071,8 @@ void DolphinMainWindow::init() m_searchBox->setParent(toolBar("searchToolBar")); m_searchBox->show(); + connect(m_searchBox, SIGNAL(textChanged(const QString&)), + this, SLOT(slotSearchBoxTextChanged(const QString&))); stateChanged("new_file"); diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index d5bd1c59b..223b0cb3f 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -41,6 +41,7 @@ class KAction; class DolphinViewActionHandler; class DolphinApplication; class DolphinSearchBox; +class DolphinSearchOptionsConfigurator; class DolphinSettingsDialog; class DolphinViewContainer; class DolphinRemoteEncoding; @@ -381,6 +382,13 @@ private slots: */ void slotTabMoved(int from, int to); + /** + * Is connected to the searchbox signal 'textEdited' and + * takes care to make the search options configurator visible + * if a search text has been entered. + */ + void slotSearchBoxTextChanged(const QString& text); + private: DolphinMainWindow(int id); void init(); @@ -463,6 +471,7 @@ private: DolphinViewContainer* m_activeViewContainer; QVBoxLayout* m_centralWidgetLayout; DolphinSearchBox* m_searchBox; + DolphinSearchOptionsConfigurator* m_searchOptionsConfigurator; int m_id; struct ViewTab diff --git a/src/search/dolphinsearchbox.cpp b/src/search/dolphinsearchbox.cpp index d224575ea..312bfb1cb 100644 --- a/src/search/dolphinsearchbox.cpp +++ b/src/search/dolphinsearchbox.cpp @@ -261,8 +261,8 @@ DolphinSearchBox::DolphinSearchBox(QWidget* parent) : m_searchInput->setClickMessage(i18nc("@label:textbox", "Search...")); m_searchInput->installEventFilter(this); hLayout->addWidget(m_searchInput); - connect(m_searchInput, SIGNAL(textEdited(const QString&)), - this, SLOT(slotTextEdited(const QString&))); + connect(m_searchInput, SIGNAL(textChanged(const QString&)), + this, SIGNAL(textChanged(const QString&))); connect(m_searchInput, SIGNAL(returnPressed()), this, SLOT(emitSearchSignal())); @@ -311,8 +311,4 @@ void DolphinSearchBox::emitSearchSignal() emit search(KUrl("nepomuksearch:/" + m_searchInput->text())); } -void DolphinSearchBox::slotTextEdited(const QString& text) -{ -} - #include "dolphinsearchbox.moc" diff --git a/src/search/dolphinsearchbox.h b/src/search/dolphinsearchbox.h index 93c033bb8..2e4c6b85a 100644 --- a/src/search/dolphinsearchbox.h +++ b/src/search/dolphinsearchbox.h @@ -37,26 +37,27 @@ class QToolButton; class DolphinSearchCompleter : public QObject { Q_OBJECT - public: - DolphinSearchCompleter(KLineEdit *linedit); - - public slots: - void highlighted(const QModelIndex& index); - void activated(const QModelIndex& index); - void slotTextEdited(const QString &text); - - private: - void addCompletionItem(const QString& displayed, const QString& usedForCompletition, const QString& description = QString(), const QString& toolTip = QString(), const KIcon& icon = KIcon()); - - void findText(int* wordStart, int* wordEnd, QString* newWord, int cursorPos, const QString &input); - - private: - KLineEdit* q; - QCompleter* m_completer; - QStandardItemModel* m_completionModel; - QString m_userText; - int m_wordStart; - int m_wordEnd; + +public: + DolphinSearchCompleter(KLineEdit *linedit); + +public slots: + void highlighted(const QModelIndex& index); + void activated(const QModelIndex& index); + void slotTextEdited(const QString &text); + +private: + void addCompletionItem(const QString& displayed, const QString& usedForCompletition, const QString& description = QString(), const QString& toolTip = QString(), const KIcon& icon = KIcon()); + + void findText(int* wordStart, int* wordEnd, QString* newWord, int cursorPos, const QString &input); + +private: + KLineEdit* q; + QCompleter* m_completer; + QStandardItemModel* m_completionModel; + QString m_userText; + int m_wordStart; + int m_wordEnd; }; /** @@ -82,9 +83,13 @@ signals: */ void search(const KUrl& url); + /** + * Is emitted if the text of the searchbox has been changed. + */ + void textChanged(const QString& text); + private slots: void emitSearchSignal(); - void slotTextEdited(const QString& text); private: KLineEdit* m_searchInput; diff --git a/src/search/dolphinsearchoptionsconfigurator.cpp b/src/search/dolphinsearchoptionsconfigurator.cpp new file mode 100644 index 000000000..5e270d53f --- /dev/null +++ b/src/search/dolphinsearchoptionsconfigurator.cpp @@ -0,0 +1,73 @@ +/*************************************************************************** + * 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 "dolphinsearchoptionsconfigurator.h" + +#include +#include + +#include +#include +#include +#include +#include + +DolphinSearchOptionsConfigurator::DolphinSearchOptionsConfigurator(QWidget* parent) : + QWidget(parent) +{ + QVBoxLayout* vBoxLayout = new QVBoxLayout(this); + + // add "search" configuration + QLabel* searchLabel = new QLabel(i18nc("@label", "Search:")); + + KComboBox* searchFromBox = new KComboBox(); + searchFromBox->addItem(i18nc("label", "Everywhere")); + searchFromBox->addItem(i18nc("label", "From Here")); + + // add "what" configuration + QLabel* whatLabel = new QLabel(i18nc("@label", "What:")); + + KComboBox* searchWhatBox = new KComboBox(); + searchWhatBox->addItem(i18nc("label", "All")); + searchWhatBox->addItem(i18nc("label", "Images")); + searchWhatBox->addItem(i18nc("label", "Texts")); + searchWhatBox->addItem(i18nc("label", "File Names")); + + QWidget* filler = new QWidget(); + + // add button "Save" + QPushButton* saveButton = new QPushButton(); + saveButton->setText(i18nc("@action:button", "Save")); + + QHBoxLayout* hBoxLayout = new QHBoxLayout(this); + hBoxLayout->addWidget(searchLabel); + hBoxLayout->addWidget(searchFromBox); + hBoxLayout->addWidget(whatLabel); + hBoxLayout->addWidget(searchWhatBox); + hBoxLayout->addWidget(filler, 1); + hBoxLayout->addWidget(saveButton); + + vBoxLayout->addLayout(hBoxLayout); +} + +DolphinSearchOptionsConfigurator::~DolphinSearchOptionsConfigurator() +{ +} + +#include "dolphinsearchoptionsconfigurator.moc" diff --git a/src/search/dolphinsearchoptionsconfigurator.h b/src/search/dolphinsearchoptionsconfigurator.h new file mode 100644 index 000000000..9b5a70b03 --- /dev/null +++ b/src/search/dolphinsearchoptionsconfigurator.h @@ -0,0 +1,34 @@ +/*************************************************************************** + * 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 DOLPHINSEARCHOPTIONSCONFIGURATOR_H +#define DOLPHINSEARCHOPTIONSCONFIGURATOR_H + +#include + +class DolphinSearchOptionsConfigurator : public QWidget +{ + Q_OBJECT + +public: + DolphinSearchOptionsConfigurator(QWidget* parent = 0); + virtual ~DolphinSearchOptionsConfigurator(); +}; + +#endif -- 2.47.3