From: Peter Penz Date: Thu, 12 Nov 2009 18:58:44 +0000 (+0000) Subject: Show some default search configurations, so that the user is able to adjust queries... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/288c7db6a7ae804c79d9fe61dcaf7f494a194341 Show some default search configurations, so that the user is able to adjust queries in a faster way (similar to a defaceted interface). svn path=/trunk/KDE/kdebase/apps/; revision=1048109 --- diff --git a/src/search/dolphinsearchbox.cpp b/src/search/dolphinsearchbox.cpp index e2fd81a6f..666405014 100644 --- a/src/search/dolphinsearchbox.cpp +++ b/src/search/dolphinsearchbox.cpp @@ -17,6 +17,7 @@ * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ + #include "dolphinsearchbox.h" #include @@ -248,8 +249,6 @@ DolphinSearchBox::DolphinSearchBox(QWidget* parent) : m_searchInput->setClickMessage(i18nc("@label:textbox", "Search...")); m_searchInput->installEventFilter(this); hLayout->addWidget(m_searchInput); - connect(m_searchInput, SIGNAL(textChanged(const QString&)), - this, SIGNAL(textChanged(const QString&))); connect(m_searchInput, SIGNAL(returnPressed()), this, SLOT(emitSearchSignal())); @@ -278,6 +277,7 @@ bool DolphinSearchBox::event(QEvent* event) return QWidget::event(event); } +#include bool DolphinSearchBox::eventFilter(QObject* watched, QEvent* event) { if ((watched == m_searchInput) && (event->type() == QEvent::FocusIn)) { @@ -287,6 +287,7 @@ bool DolphinSearchBox::eventFilter(QObject* watched, QEvent* event) if (m_completer == 0) { m_completer = new DolphinSearchCompleter(m_searchInput); } + kDebug() << "---- got focus! is visible? " << isVisible(); emit requestSearchOptions(); } diff --git a/src/search/dolphinsearchoptionsconfigurator.cpp b/src/search/dolphinsearchoptionsconfigurator.cpp index 6f4d83460..112c55d82 100644 --- a/src/search/dolphinsearchoptionsconfigurator.cpp +++ b/src/search/dolphinsearchoptionsconfigurator.cpp @@ -32,10 +32,12 @@ #include #include #include +#include #include DolphinSearchOptionsConfigurator::DolphinSearchOptionsConfigurator(QWidget* parent) : QWidget(parent), + m_initialized(false), m_searchFromBox(0), m_searchWhatBox(0), m_addSelectorButton(0), @@ -59,8 +61,6 @@ DolphinSearchOptionsConfigurator::DolphinSearchOptionsConfigurator(QWidget* pare m_searchWhatBox->addItem(i18nc("@label", "Text")); m_searchWhatBox->addItem(i18nc("@label", "Filenames")); - QWidget* filler = new QWidget(this); - // add button "Save" QPushButton* saveButton = new QPushButton(this); saveButton->setIcon(KIcon("document-save")); @@ -80,29 +80,24 @@ DolphinSearchOptionsConfigurator::DolphinSearchOptionsConfigurator(QWidget* pare m_addSelectorButton->setIcon(KIcon("list-add")); m_addSelectorButton->setToolTip(i18nc("@info", "Add search option")); m_addSelectorButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - connect(m_addSelectorButton, SIGNAL(clicked()), this, SLOT(addSelector())); - - QHBoxLayout* hBoxLayout = new QHBoxLayout(this); - hBoxLayout->addWidget(searchLabel); - hBoxLayout->addWidget(m_searchFromBox); - hBoxLayout->addWidget(whatLabel); - hBoxLayout->addWidget(m_searchWhatBox); - hBoxLayout->addWidget(filler, 1); - hBoxLayout->addWidget(saveButton); - hBoxLayout->addWidget(closeButton); - hBoxLayout->addWidget(m_addSelectorButton); + connect(m_addSelectorButton, SIGNAL(clicked()), this, SLOT(slotAddSelectorButtonClicked())); - // add default search criterions - SearchCriterionSelector* dateCriterion = new SearchCriterionSelector(SearchCriterionSelector::Date, this); - connect(dateCriterion, SIGNAL(removeCriterion()), this, SLOT(removeCriterion())); + QHBoxLayout* firstLineLayout = new QHBoxLayout(); + firstLineLayout->addWidget(searchLabel); + firstLineLayout->addWidget(m_searchFromBox); + firstLineLayout->addWidget(whatLabel); + firstLineLayout->addWidget(m_searchWhatBox); + firstLineLayout->addWidget(new QWidget(this), 1); // filler + firstLineLayout->addWidget(m_addSelectorButton); - SearchCriterionSelector* fileSizeCriterion = new SearchCriterionSelector(SearchCriterionSelector::FileSize, this); - connect(fileSizeCriterion, SIGNAL(removeCriterion()), this, SLOT(removeCriterion())); + QHBoxLayout* lastLineLayout = new QHBoxLayout(); + lastLineLayout->addWidget(new QWidget(this), 1); // filler + lastLineLayout->addWidget(saveButton); + lastLineLayout->addWidget(closeButton); m_vBoxLayout->addWidget(new KSeparator(this)); - m_vBoxLayout->addLayout(hBoxLayout); - m_vBoxLayout->addWidget(dateCriterion); - m_vBoxLayout->addWidget(fileSizeCriterion); + m_vBoxLayout->addLayout(firstLineLayout); + m_vBoxLayout->addLayout(lastLineLayout); m_vBoxLayout->addWidget(new KSeparator(this)); } @@ -110,15 +105,27 @@ DolphinSearchOptionsConfigurator::~DolphinSearchOptionsConfigurator() { } -void DolphinSearchOptionsConfigurator::addSelector() +void DolphinSearchOptionsConfigurator::showEvent(QShowEvent* event) { - SearchCriterionSelector* selector = new SearchCriterionSelector(SearchCriterionSelector::Undefined, this); - connect(selector, SIGNAL(removeCriterion()), this, SLOT(removeCriterion())); + if (!event->spontaneous() && !m_initialized) { + // add default search criterions + SearchCriterionSelector* dateCriterion = new SearchCriterionSelector(SearchCriterionSelector::Date, this); + SearchCriterionSelector* tagCriterion = new SearchCriterionSelector(SearchCriterionSelector::Tag, this); + SearchCriterionSelector* sizeCriterion = new SearchCriterionSelector(SearchCriterionSelector::Size, this); + + addSelector(dateCriterion); + addSelector(tagCriterion); + addSelector(sizeCriterion); + + m_initialized = true; + } + QWidget::showEvent(event); +} - // insert the new selector before the KSeparator at the bottom - const int index = m_vBoxLayout->count() - 1; - m_vBoxLayout->insertWidget(index, selector); - updateSelectorButton(); +void DolphinSearchOptionsConfigurator::slotAddSelectorButtonClicked() +{ + SearchCriterionSelector* selector = new SearchCriterionSelector(SearchCriterionSelector::Size, this); + addSelector(selector); } void DolphinSearchOptionsConfigurator::removeCriterion() @@ -163,4 +170,14 @@ void DolphinSearchOptionsConfigurator::saveQuery() dialog.exec(); // TODO... } +void DolphinSearchOptionsConfigurator::addSelector(SearchCriterionSelector* selector) +{ + connect(selector, SIGNAL(removeCriterion()), this, SLOT(removeCriterion())); + + // insert the new selector before the lastLineLayout and the KSeparator at the bottom + const int index = m_vBoxLayout->count() - 2; + m_vBoxLayout->insertWidget(index, selector); + updateSelectorButton(); +} + #include "dolphinsearchoptionsconfigurator.moc" diff --git a/src/search/dolphinsearchoptionsconfigurator.h b/src/search/dolphinsearchoptionsconfigurator.h index b66ab340d..d384f5296 100644 --- a/src/search/dolphinsearchoptionsconfigurator.h +++ b/src/search/dolphinsearchoptionsconfigurator.h @@ -23,6 +23,7 @@ #include class KComboBox; +class SearchCriterionSelector; class QPushButton; class QVBoxLayout; @@ -37,12 +38,11 @@ public: DolphinSearchOptionsConfigurator(QWidget* parent = 0); virtual ~DolphinSearchOptionsConfigurator(); +protected: + virtual void showEvent(QShowEvent* event); + private slots: - /** - * Adds a new search description selector to the bottom - * of the layout. - */ - void addSelector(); + void slotAddSelectorButtonClicked(); void removeCriterion(); @@ -58,6 +58,14 @@ private slots: void saveQuery(); private: + /** + * Adds the new search description selector to the bottom + * of the layout. + */ + void addSelector(SearchCriterionSelector* selector); + +private: + bool m_initialized; KComboBox* m_searchFromBox; KComboBox* m_searchWhatBox; QPushButton* m_addSelectorButton; diff --git a/src/search/searchcriteriondescription.h b/src/search/searchcriteriondescription.h index 2bf3d2f91..5da188633 100644 --- a/src/search/searchcriteriondescription.h +++ b/src/search/searchcriteriondescription.h @@ -38,7 +38,7 @@ class SearchCriterionDescription public: struct Comparator { - Comparator(const QString& n, const QString& o, const QString& p) : + Comparator(const QString& n, const QString& o = QString(), const QString& p = QString()) : name(n), operation(o), prefix(p) {} QString name; // user visible and translated name QString operation; // Nepomuk operation that represents the comparator diff --git a/src/search/searchcriterionselector.cpp b/src/search/searchcriterionselector.cpp index 34b8d0c51..6a900fa7a 100644 --- a/src/search/searchcriterionselector.cpp +++ b/src/search/searchcriterionselector.cpp @@ -40,13 +40,13 @@ SearchCriterionSelector::SearchCriterionSelector(Type type, QWidget* parent) : m_descriptions() { m_descriptionsBox = new QComboBox(this); - m_descriptionsBox->addItem(i18nc("@label", "Select..."), -1); - createDescriptions(); - connect(m_descriptionsBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotDescriptionChanged(int))); m_comparatorBox = new QComboBox(this); - m_comparatorBox->hide(); - connect(m_comparatorBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateQuery())); + m_comparatorBox->setSizeAdjustPolicy(QComboBox::AdjustToContents); + + createDescriptions(); + const int index = static_cast(type); + m_descriptionsBox->setCurrentIndex(index); QWidget* filler = new QWidget(this); filler->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); @@ -65,19 +65,8 @@ SearchCriterionSelector::SearchCriterionSelector(Type type, QWidget* parent) : setLayout(m_layout); - // preselect the used criterion dependent on the type - switch (type) { - case Date: - m_descriptionsBox->setCurrentIndex(1); - m_comparatorBox->setCurrentIndex(1); - break; - case FileSize: - m_descriptionsBox->setCurrentIndex(2); - break; - case Undefined: - default: - break; - } + slotDescriptionChanged(index); + connect(m_descriptionsBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotDescriptionChanged(int))); } SearchCriterionSelector::~SearchCriterionSelector() @@ -86,40 +75,59 @@ SearchCriterionSelector::~SearchCriterionSelector() void SearchCriterionSelector::createDescriptions() { + Q_ASSERT(m_descriptionsBox != 0); + Q_ASSERT(m_comparatorBox != 0); + // TODO: maybe this creation should be forwarded to a factory if // the number of items increases in future - QList comperators; - comperators.append(SearchCriterionDescription::Comparator(i18nc("@label", "Greater Than"), ">", "+")); - comperators.append(SearchCriterionDescription::Comparator(i18nc("@label", "Greater Than or Equal to"), ">=", "+")); - comperators.append(SearchCriterionDescription::Comparator(i18nc("@label", "Less Than"), "<", "+")); - comperators.append(SearchCriterionDescription::Comparator(i18nc("@label", "Less Than or Equal to"), "<=", "+")); + QList defaultComps; + defaultComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "Greater Than"), ">", "+")); + defaultComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "Greater Than or Equal to"), ">=", "+")); + defaultComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "Less Than"), "<", "+")); + defaultComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "Less Than or Equal to"), "<=", "+")); // add "Date" description QList dateComps; - dateComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "Anytime"), "", "")); // TODO - dateComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "Today"), ">", "+")); // TODO - dateComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "This week"), ">", "+")); // TODO - dateComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "This month"), ">", "+")); // TODO - foreach (const SearchCriterionDescription::Comparator& comp, comperators) { + dateComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "Anytime"))); // TODO + dateComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "Today"))); // TODO + dateComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "This week"))); // TODO + dateComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "This month"))); // TODO + foreach (const SearchCriterionDescription::Comparator& comp, defaultComps) { dateComps.append(comp); } DateValue* dateValue = new DateValue(this); dateValue->hide(); - SearchCriterionDescription date(i18nc("@label", "Date Modified"), + SearchCriterionDescription date(i18nc("@label", "Date"), "sourceModified", dateComps, dateValue); - // add "File Size" description - FileSizeValue* fileSizeValue = new FileSizeValue(this); - fileSizeValue->hide(); - SearchCriterionDescription size(i18nc("@label", "File Size"), + // add "Tag" description + QList tagComps; + tagComps.append(SearchCriterionDescription::Comparator(i18nc("@label All (tags)", "All"))); + tagComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "Equal to"), "==")); + + TagValue* tagValue = new TagValue(this); + tagValue->hide(); + SearchCriterionDescription tag(i18nc("@label", "Tag"), + "tag", + tagComps, + tagValue); + + // add "Size" description + QList sizeComps = defaultComps; + sizeComps.insert(0, SearchCriterionDescription::Comparator(i18nc("@label Any (file size)", "Any"))); + + SizeValue* sizeValue = new SizeValue(this); + sizeValue->hide(); + SearchCriterionDescription size(i18nc("@label", "Size"), "contentSize", - comperators, - fileSizeValue); + sizeComps, + sizeValue); m_descriptions.append(date); + m_descriptions.append(tag); m_descriptions.append(size); // add all descriptions to the combo box @@ -131,59 +139,45 @@ void SearchCriterionSelector::createDescriptions() void SearchCriterionSelector::slotDescriptionChanged(int index) { - m_comparatorBox->clear(); - m_comparatorBox->show(); if (m_valueWidget != 0) { + m_valueWidget->hide(); m_layout->removeWidget(m_valueWidget); + m_valueWidget = 0; // the value widget is obtained by the Search Criterion // Selector instance and may not get deleted } - // adjust the comparator box and the value widget dependent from the selected description - m_comparatorBox->addItem(i18nc("@label", "Select..."), -1); - const int descrIndex = m_descriptionsBox->itemData(index).toInt(); - if (descrIndex >= 0) { - // add comparator items - const SearchCriterionDescription& description = m_descriptions[descrIndex]; - foreach (const SearchCriterionDescription::Comparator& comp, description.comparators()) { - m_comparatorBox->addItem(comp.name); - } - - // add value widget - m_valueWidget = description.valueWidget(); - const int layoutIndex = m_layout->count() - 2; - m_layout->insertWidget(layoutIndex, m_valueWidget); - m_valueWidget->show(); + // add comparator items + disconnect(m_comparatorBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotComparatorChanged(int))); + m_comparatorBox->clear(); + + const SearchCriterionDescription& description = m_descriptions[index]; + foreach (const SearchCriterionDescription::Comparator& comp, description.comparators()) { + m_comparatorBox->addItem(comp.name); } + + // add value widget + m_valueWidget = description.valueWidget(); + m_layout->insertWidget(2, m_valueWidget); + + m_comparatorBox->setCurrentIndex(0); + slotComparatorChanged(0); + connect(m_comparatorBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotComparatorChanged(int))); } -void SearchCriterionSelector::updateQuery() +void SearchCriterionSelector::slotComparatorChanged(int index) { - const SearchCriterionDescription* descr = description(); - if (descr == 0) { - // no description has been selected - return; - } + Q_ASSERT(index >= 0); - // get selected comparator related to the description - const int compBoxIndex = m_comparatorBox->currentIndex(); - const int compIndex = m_comparatorBox->itemData(compBoxIndex).toInt(); - if (compIndex < 0) { - // no comparator has been selected - return; - } + // only show the value widget if an operation is defined by the comparator + const int descIndex = m_descriptionsBox->currentIndex(); + const SearchCriterionDescription& descr = m_descriptions[descIndex]; + const SearchCriterionDescription::Comparator& comp = descr.comparators()[index]; + m_valueWidget->setVisible(!comp.operation.isEmpty()); // create query string - const SearchCriterionDescription::Comparator& comp = descr->comparators()[compIndex]; - const QString queryString = comp.prefix + descr->identifier() + comp.operation + m_valueWidget->value(); + const QString queryString = comp.prefix + descr.identifier() + comp.operation + m_valueWidget->value(); emit criterionChanged(queryString); } -const SearchCriterionDescription* SearchCriterionSelector::description() const -{ - const int descrBoxIndex = m_descriptionsBox->currentIndex(); - const int descrIndex = m_descriptionsBox->itemData(descrBoxIndex).toInt(); - return (descrIndex < 0) ? 0 : &m_descriptions[descrIndex]; -} - #include "searchcriterionselector.moc" diff --git a/src/search/searchcriterionselector.h b/src/search/searchcriterionselector.h index f83d28df8..1ddc50d25 100644 --- a/src/search/searchcriterionselector.h +++ b/src/search/searchcriterionselector.h @@ -45,12 +45,7 @@ class SearchCriterionSelector : public QWidget Q_OBJECT public: - enum Type - { - Undefined, - Date, - FileSize - }; + enum Type { Date, Tag, Size }; SearchCriterionSelector(Type type, QWidget* parent = 0); virtual ~SearchCriterionSelector(); @@ -70,11 +65,7 @@ signals: private slots: void slotDescriptionChanged(int index); - - /** - * Updates the query string and emits the signal criterionChanged(). - */ - void updateQuery(); + void slotComparatorChanged(int index); private: /** @@ -83,12 +74,6 @@ private: */ void createDescriptions(); - /** - * Returns the currently selected searc criterion description. If nothing - * is selected, 0 is returned. - */ - const SearchCriterionDescription* description() const; - private: QHBoxLayout* m_layout; QComboBox* m_descriptionsBox; // has items like "File Size", "Date Modified", ... diff --git a/src/search/searchcriterionvalue.cpp b/src/search/searchcriterionvalue.cpp index 301344df6..5a903cbae 100644 --- a/src/search/searchcriterionvalue.cpp +++ b/src/search/searchcriterionvalue.cpp @@ -37,7 +37,7 @@ SearchCriterionValue::~SearchCriterionValue() { } - +// ------------------------------------------------------------------------- DateValue::DateValue(QWidget* parent) : SearchCriterionValue(parent), @@ -59,9 +59,32 @@ QString DateValue::value() const return QString(); } +// ------------------------------------------------------------------------- + +TagValue::TagValue(QWidget* parent) : + SearchCriterionValue(parent), + m_tags(0) +{ + m_tags = new QComboBox(this); + m_tags->addItem("feffi"); + + QHBoxLayout* layout = new QHBoxLayout(this); + layout->setMargin(0); + layout->addWidget(m_tags); +} + +TagValue::~TagValue() +{ +} + +QString TagValue::value() const +{ + return QString(); +} +// ------------------------------------------------------------------------- -FileSizeValue::FileSizeValue(QWidget* parent) : +SizeValue::SizeValue(QWidget* parent) : SearchCriterionValue(parent), m_lineEdit(0), m_units(0) @@ -82,11 +105,11 @@ FileSizeValue::FileSizeValue(QWidget* parent) : layout->addWidget(m_units); } -FileSizeValue::~FileSizeValue() +SizeValue::~SizeValue() { } -QString FileSizeValue::value() const +QString SizeValue::value() const { return QString(); } diff --git a/src/search/searchcriterionvalue.h b/src/search/searchcriterionvalue.h index cfabca24b..7bb79243d 100644 --- a/src/search/searchcriterionvalue.h +++ b/src/search/searchcriterionvalue.h @@ -63,14 +63,30 @@ private: +/** @brief Allows to input a tag as search criterion. */ +class TagValue : public SearchCriterionValue +{ + Q_OBJECT + +public: + TagValue(QWidget* parent = 0); + virtual ~TagValue(); + virtual QString value() const; + +private: + QComboBox* m_tags; +}; + + + /** @brief Allows to input a file size value as search criterion. */ -class FileSizeValue : public SearchCriterionValue +class SizeValue : public SearchCriterionValue { Q_OBJECT public: - FileSizeValue(QWidget* parent = 0); - virtual ~FileSizeValue(); + SizeValue(QWidget* parent = 0); + virtual ~SizeValue(); virtual QString value() const; private: