X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/61da3d924cecdbea4efa4fc70e461e5273fd5b08..321f747ddf9cf71ed3c8fa4de287d131cd22c2d8:/src/search/dolphinsearchbox.cpp diff --git a/src/search/dolphinsearchbox.cpp b/src/search/dolphinsearchbox.cpp index 0bad32fe8..a9c960c24 100644 --- a/src/search/dolphinsearchbox.cpp +++ b/src/search/dolphinsearchbox.cpp @@ -20,6 +20,7 @@ #include "dolphinsearchbox.h" #include "dolphin_searchsettings.h" +#include "dolphinfacetswidget.h" #include "dolphinsearchinformation.h" #include @@ -34,7 +35,6 @@ #include #include #include -#include #include #include #include @@ -66,6 +66,8 @@ DolphinSearchBox::DolphinSearchBox(QWidget* parent) : m_separator(0), m_fromHereButton(0), m_everywhereButton(0), + m_facetsToggleButton(0), + m_facetsWidget(0), m_searchPath(), m_readOnlyQuery(), m_startSearchTimer(0) @@ -92,7 +94,7 @@ void DolphinSearchBox::setSearchPath(const KUrl& url) m_searchPath = url; QFontMetrics metrics(m_fromHereButton->font()); - const int maxWidth = metrics.averageCharWidth() * 15; + const int maxWidth = metrics.height() * 8; QString location = url.fileName(); if (location.isEmpty()) { @@ -110,6 +112,10 @@ void DolphinSearchBox::setSearchPath(const KUrl& url) m_separator->setVisible(showSearchFromButtons); m_fromHereButton->setVisible(showSearchFromButtons); m_everywhereButton->setVisible(showSearchFromButtons); + + const DolphinSearchInformation& searchInfo = DolphinSearchInformation::instance(); + const bool hasFacetsSupport = searchInfo.isIndexingEnabled() && searchInfo.isPathIndexed(m_searchPath); + m_facetsWidget->setEnabled(hasFacetsSupport); } KUrl DolphinSearchBox::searchPath() const @@ -229,6 +235,14 @@ void DolphinSearchBox::slotReturnPressed(const QString& text) emit returnPressed(text); } +void DolphinSearchBox::slotFacetsButtonToggled() +{ + const bool visible = !m_facetsWidget->isVisible(); + m_facetsWidget->setVisible(visible); + SearchSettings::setShowFacetsWidget(visible); + updateFacetsToggleButtonIcon(); +} + void DolphinSearchBox::initButton(QToolButton* button) { button->setAutoExclusive(true); @@ -250,6 +264,8 @@ void DolphinSearchBox::loadSettings() } else { m_fileNameButton->setChecked(true); } + + m_facetsWidget->setVisible(SearchSettings::showFacetsWidget()); } void DolphinSearchBox::saveSettings() @@ -320,6 +336,14 @@ void DolphinSearchBox::init() connect(m_fromHereButton, SIGNAL(clicked()), this, SLOT(slotSearchLocationChanged())); connect(m_everywhereButton, SIGNAL(clicked()), this, SLOT(slotSearchLocationChanged())); + // Create "Facets" widgets + m_facetsToggleButton = new QToolButton(this); + m_facetsToggleButton->setAutoRaise(true); + connect(m_facetsToggleButton, SIGNAL(clicked()), this, SLOT(slotFacetsButtonToggled())); + + m_facetsWidget = new DolphinFacetsWidget(this); + m_facetsWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); + // Apply layout for the options QHBoxLayout* optionsLayout = new QHBoxLayout(); optionsLayout->setMargin(0); @@ -329,6 +353,7 @@ void DolphinSearchBox::init() optionsLayout->addWidget(m_fromHereButton); optionsLayout->addWidget(m_everywhereButton); optionsLayout->addStretch(1); + optionsLayout->addWidget(m_facetsToggleButton); // Put the options into a QScrollArea. This prevents increasing the view width // in case that not enough width for the options is available. @@ -348,6 +373,7 @@ void DolphinSearchBox::init() m_topLayout->setMargin(0); m_topLayout->addLayout(searchInputLayout); m_topLayout->addWidget(m_optionsScrollArea); + m_topLayout->addWidget(m_facetsWidget); loadSettings(); @@ -358,6 +384,7 @@ void DolphinSearchBox::init() m_startSearchTimer->setInterval(1000); connect(m_startSearchTimer, SIGNAL(timeout()), this, SLOT(emitSearchSignal())); + updateFacetsToggleButtonIcon(); applyReadOnlyState(); } @@ -414,6 +441,18 @@ void DolphinSearchBox::applyReadOnlyState() m_searchInput->setVisible(!m_readOnly); m_optionsScrollArea->setVisible(!m_readOnly); + + if (m_readOnly) { + m_facetsWidget->hide(); + } else { + m_facetsWidget->setVisible(SearchSettings::showFacetsWidget()); + } +} + +void DolphinSearchBox::updateFacetsToggleButtonIcon() +{ + const bool visible = SearchSettings::showFacetsWidget(); + m_facetsToggleButton->setIcon(KIcon(visible ? "list-remove" : "list-add")); } #include "dolphinsearchbox.moc"