return QWidget::event(event);
}
-#include <kdebug.h>
bool DolphinSearchBox::eventFilter(QObject* watched, QEvent* event)
{
if ((watched == m_searchInput) && (event->type() == QEvent::FocusIn)) {
if (m_completer == 0) {
m_completer = new DolphinSearchCompleter(m_searchInput);
}
- kDebug() << "---- got focus! is visible? " << isVisible();
emit requestSearchOptions();
}
#include <QShowEvent>
#include <QVBoxLayout>
+#include <kdebug.h>
+
DolphinSearchOptionsConfigurator::DolphinSearchOptionsConfigurator(QWidget* parent) :
QWidget(parent),
m_initialized(false),
m_searchFromBox(0),
m_searchWhatBox(0),
m_addSelectorButton(0),
- m_vBoxLayout(0)
+ m_vBoxLayout(0),
+ m_criterions()
{
m_vBoxLayout = new QVBoxLayout(this);
Q_ASSERT(static_cast<int>(SearchCriterionSelector::Date) == 0);
Q_ASSERT(static_cast<int>(SearchCriterionSelector::Size) == 1);
Q_ASSERT(static_cast<int>(SearchCriterionSelector::Tag) == 2);
- addSelector(dateCriterion);
- addSelector(sizeCriterion);
- addSelector(tagCriterion);
+ addCriterion(dateCriterion);
+ addCriterion(sizeCriterion);
+ addCriterion(tagCriterion);
m_initialized = true;
}
void DolphinSearchOptionsConfigurator::slotAddSelectorButtonClicked()
{
SearchCriterionSelector* selector = new SearchCriterionSelector(SearchCriterionSelector::Tag, this);
- addSelector(selector);
+ addCriterion(selector);
+}
+
+void DolphinSearchOptionsConfigurator::slotCriterionChanged()
+{
+ QString searchOptions;
+ foreach (const SearchCriterionSelector* criterion, m_criterions) {
+ searchOptions += criterion->queryString() + ' ';
+ }
+ kDebug() << "Search option string:" << searchOptions;
+ emit searchOptionsChanged(searchOptions);
}
void DolphinSearchOptionsConfigurator::removeCriterion()
{
- QWidget* criterion = qobject_cast<QWidget*>(sender());
+ SearchCriterionSelector* criterion = qobject_cast<SearchCriterionSelector*>(sender());
Q_ASSERT(criterion != 0);
m_vBoxLayout->removeWidget(criterion);
+
+ const int index = m_criterions.indexOf(criterion);
+ m_criterions.removeAt(index);
+
criterion->deleteLater();
updateSelectorButton();
dialog.exec(); // TODO...
}
-void DolphinSearchOptionsConfigurator::addSelector(SearchCriterionSelector* selector)
+void DolphinSearchOptionsConfigurator::addCriterion(SearchCriterionSelector* criterion)
{
- connect(selector, SIGNAL(removeCriterion()), this, SLOT(removeCriterion()));
+ connect(criterion, SIGNAL(removeCriterion()), this, SLOT(removeCriterion()));
+ connect(criterion, SIGNAL(criterionChanged()), this, SLOT(slotCriterionChanged()));
// 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);
+ m_vBoxLayout->insertWidget(index, criterion);
updateSelectorButton();
+
+ m_criterions.append(criterion);
}
#include "dolphinsearchoptionsconfigurator.moc"
#ifndef DOLPHINSEARCHOPTIONSCONFIGURATOR_H
#define DOLPHINSEARCHOPTIONSCONFIGURATOR_H
+#include <QList>
#include <QWidget>
class KComboBox;
DolphinSearchOptionsConfigurator(QWidget* parent = 0);
virtual ~DolphinSearchOptionsConfigurator();
+signals:
+ void searchOptionsChanged(const QString& options);
+
protected:
virtual void showEvent(QShowEvent* event);
private slots:
void slotAddSelectorButtonClicked();
+ void slotCriterionChanged();
+
void removeCriterion();
/**
* Adds the new search description selector to the bottom
* of the layout.
*/
- void addSelector(SearchCriterionSelector* selector);
+ void addCriterion(SearchCriterionSelector* selector);
private:
bool m_initialized;
KComboBox* m_searchWhatBox;
QPushButton* m_addSelectorButton;
QVBoxLayout* m_vBoxLayout;
+ QList<SearchCriterionSelector*> m_criterions;
};
#endif
{
}
+QString SearchCriterionSelector::queryString() const
+{
+ if (m_valueWidget == 0) {
+ return QString();
+ }
+
+ const int descIndex = m_descriptionsBox->currentIndex();
+ const SearchCriterionDescription& descr = m_descriptions[descIndex];
+
+ const int compIndex = m_comparatorBox->currentIndex();
+ const SearchCriterionDescription::Comparator& comp = descr.comparators()[compIndex];
+
+ return comp.prefix + descr.identifier() + comp.operation +
+ '"' + m_valueWidget->value() + '"';
+}
+
+void SearchCriterionSelector::slotDescriptionChanged(int index)
+{
+ 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
+ }
+
+ // 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::slotComparatorChanged(int index)
+{
+ Q_ASSERT(index >= 0);
+
+ // 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());
+
+ emit criterionChanged();
+}
+
void SearchCriterionSelector::createDescriptions()
{
Q_ASSERT(m_descriptionsBox != 0);
DateValue* dateValue = new DateValue(this);
dateValue->hide();
- SearchCriterionDescription date(i18nc("@label", "Date"),
- "sourceModified",
+ SearchCriterionDescription date(i18nc("@label", "Date:"),
+ "lastModified",
dateComps,
dateValue);
SizeValue* sizeValue = new SizeValue(this);
sizeValue->hide();
- SearchCriterionDescription size(i18nc("@label", "Size"),
+ SearchCriterionDescription size(i18nc("@label", "Size:"),
"contentSize",
sizeComps,
sizeValue);
// add "Tag" description
QList<SearchCriterionDescription::Comparator> tagComps;
tagComps.append(SearchCriterionDescription::Comparator(i18nc("@label All (tags)", "All")));
- tagComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "Equal to"), "=="));
+ tagComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "Equal to"), ":"));
TagValue* tagValue = new TagValue(this);
tagValue->hide();
- SearchCriterionDescription tag(i18nc("@label", "Tag"),
+ SearchCriterionDescription tag(i18nc("@label", "Tag:"),
"tag",
tagComps,
tagValue);
m_descriptions.append(size);
m_descriptions.append(tag);
- // add all descriptions to the combo box
- const int count = m_descriptions.count();
- for (int i = 0; i < count; ++i) {
- m_descriptionsBox->addItem(m_descriptions[i].name(), i);
- }
-}
-
-void SearchCriterionSelector::slotDescriptionChanged(int index)
-{
- 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
- }
-
- // 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 all descriptions to the combo box and connect the value widgets
+ int i = 0;
+ foreach (const SearchCriterionDescription& desc, m_descriptions) {
+ m_descriptionsBox->addItem(desc.name(), i);
+ connect(desc.valueWidget(), SIGNAL(valueChanged(QString)), this, SIGNAL(criterionChanged()));
+ ++i;
}
-
- // 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::slotComparatorChanged(int index)
-{
- Q_ASSERT(index >= 0);
-
- // 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 QString queryString = comp.prefix + descr.identifier() + comp.operation + m_valueWidget->value();
- emit criterionChanged(queryString);
}
#include "searchcriterionselector.moc"
SearchCriterionSelector(Type type, QWidget* parent = 0);
virtual ~SearchCriterionSelector();
+ QString queryString() const;
+
signals:
/**
* Is emitted if the criterion selector should be removed
*/
void removeCriterion();
- /**
- * Is emitted if the user changed the search criterion.
- * \p queryString represents a Nepomuk conform query string.
- */
- void criterionChanged(const QString& queryString);
+ /** Is emitted if the user has changed the search criterion. */
+ void criterionChanged();
private slots:
void slotDescriptionChanged(int index);
#include "searchcriterionvalue.h"
+#include <kdatewidget.h>
#include <klineedit.h>
#include <klocale.h>
#include <nepomuk/tag.h>
#include <QComboBox>
-#include <QDateEdit>
+#include <QDate>
+#include <QIntValidator>
#include <QLabel>
#include <QHBoxLayout>
#include <QShowEvent>
DateValue::DateValue(QWidget* parent) :
SearchCriterionValue(parent),
- m_dateEdit(0)
+ m_dateWidget(0)
{
- m_dateEdit = new QDateEdit(this);
+ m_dateWidget = new KDateWidget(QDate::currentDate(), this);
QHBoxLayout* layout = new QHBoxLayout(this);
layout->setMargin(0);
- layout->addWidget(m_dateEdit);
+ layout->addWidget(m_dateWidget);
}
DateValue::~DateValue()
QString DateValue::value() const
{
- return QString();
+ return m_dateWidget->date().toString(Qt::ISODate);
}
// -------------------------------------------------------------------------
QHBoxLayout* layout = new QHBoxLayout(this);
layout->setMargin(0);
layout->addWidget(m_tags);
+
+ connect(m_tags, SIGNAL(activated(QString)),
+ this, SIGNAL(valueChanged(QString)));
}
TagValue::~TagValue()
QString TagValue::value() const
{
- return QString();
+ return m_tags->currentText();
}
void TagValue::showEvent(QShowEvent* event)
{
m_lineEdit = new KLineEdit(this);
m_lineEdit->setClearButtonShown(true);
+ m_lineEdit->setValidator(new QIntValidator(this));
+ m_lineEdit->setAlignment(Qt::AlignRight);
m_units = new QComboBox(this);
// TODO: check the KByte vs. KiByte dilemma :-/
m_units->addItem(i18nc("@label", "MByte"));
m_units->addItem(i18nc("@label", "GByte"));
+ // set 1 MByte as default
+ m_lineEdit->setText("1");
+ m_units->setCurrentIndex(2);
+
QHBoxLayout* layout = new QHBoxLayout(this);
layout->setMargin(0);
layout->addWidget(m_lineEdit);
#include <QWidget>
class QComboBox;
-class QDateEdit;
+class KDateWidget;
class KLineEdit;
/**
virtual QString value() const;
private:
- QDateEdit* m_dateEdit;
+ KDateWidget* m_dateWidget;
};