]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Search improvements
authorPeter Penz <peter.penz19@gmail.com>
Wed, 20 Apr 2011 19:19:46 +0000 (21:19 +0200)
committerPeter Penz <peter.penz19@gmail.com>
Wed, 20 Apr 2011 19:21:26 +0000 (21:21 +0200)
Use Query::titleFromQueryUrl() to give a hint what kind of information
is shown to the user.

src/dolphinviewcontainer.cpp
src/search/dolphinsearchbox.cpp
src/search/dolphinsearchbox.h

index 15eb7f64429343d03229b76b984c652d7f382efa..1042ece6335756347b1b796d8ab7478b5e5b5fab 100644 (file)
@@ -254,7 +254,7 @@ void DolphinViewContainer::setSearchModeEnabled(bool enabled)
     if (enabled) {
         KUrl url = m_urlNavigator->locationUrl();
         m_searchBox->setText(QString());
-        m_searchBox->setReadOnly(isSearchUrl(url));
+        m_searchBox->setReadOnly(isSearchUrl(url), url);
 
         // Remember the most recent non-search URL as search path
         // of the search-box, so that it can be restored
index c4270d38312c95440b5d370e8cac64e3506f8e1c..3a6120d413eea9f5c7f1fe37042c87ce8f93b532 100644 (file)
@@ -58,14 +58,16 @@ DolphinSearchBox::DolphinSearchBox(QWidget* parent) :
     m_startedSearching(false),
     m_readOnly(false),
     m_topLayout(0),
+    m_searchLabel(0),
     m_searchInput(0),
+    m_optionsScrollArea(0),
     m_fileNameButton(0),
     m_contentButton(0),
     m_separator(0),
     m_fromHereButton(0),
     m_everywhereButton(0),
-    m_infoLabel(0),
     m_searchPath(),
+    m_readOnlyQuery(),
     m_startSearchTimer(0)
 {
 }
@@ -148,10 +150,11 @@ void DolphinSearchBox::selectAll()
     m_searchInput->selectAll();
 }
 
-void DolphinSearchBox::setReadOnly(bool readOnly)
+void DolphinSearchBox::setReadOnly(bool readOnly, const KUrl& query)
 {
     if (m_readOnly != readOnly) {
         m_readOnly = readOnly;
+        m_readOnlyQuery = query;
         applyReadOnlyState();
     }
 }
@@ -266,7 +269,7 @@ void DolphinSearchBox::init()
     connect(closeButton, SIGNAL(clicked()), SIGNAL(closeRequest()));
 
     // Create search label
-    QLabel* searchLabel = new QLabel(i18nc("@label:textbox", "Find:"), this);
+    m_searchLabel = new QLabel(this);
 
     // Create search box
     m_searchInput = new KLineEdit(this);
@@ -278,16 +281,12 @@ void DolphinSearchBox::init()
     connect(m_searchInput, SIGNAL(textChanged(QString)),
             this, SLOT(slotSearchTextChanged(QString)));
 
-    // Create information label
-    m_infoLabel = new QLabel("TODO: Provide information about the current query", this);
-
     // Apply layout for the search input
     QHBoxLayout* searchInputLayout = new QHBoxLayout();
     searchInputLayout->setMargin(0);
     searchInputLayout->addWidget(closeButton);
-    searchInputLayout->addWidget(searchLabel);
+    searchInputLayout->addWidget(m_searchLabel);
     searchInputLayout->addWidget(m_searchInput);
-    searchInputLayout->addWidget(m_infoLabel);
 
     // Create "Filename" and "Content" button
     m_fileNameButton = new QPushButton(this);
@@ -335,20 +334,21 @@ void DolphinSearchBox::init()
     // in case that not enough width for the options is available.
     QWidget* optionsContainer = new QWidget(this);
     optionsContainer->setLayout(optionsLayout);
-    QScrollArea* optionsScrollArea = new QScrollArea(this);
-    optionsScrollArea->setFrameShape(QFrame::NoFrame);
-    optionsScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-    optionsScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-    optionsScrollArea->setMaximumHeight(optionsContainer->sizeHint().height());
-    optionsScrollArea->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
-    optionsScrollArea->setWidget(optionsContainer);
-    optionsScrollArea->setWidgetResizable(true);
+
+    m_optionsScrollArea = new QScrollArea(this);
+    m_optionsScrollArea->setFrameShape(QFrame::NoFrame);
+    m_optionsScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    m_optionsScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    m_optionsScrollArea->setMaximumHeight(optionsContainer->sizeHint().height());
+    m_optionsScrollArea->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+    m_optionsScrollArea->setWidget(optionsContainer);
+    m_optionsScrollArea->setWidgetResizable(true);
 
     m_topLayout = new QVBoxLayout(this);
+    m_topLayout->setMargin(0);
     m_topLayout->addLayout(searchInputLayout);
-    m_topLayout->addWidget(optionsScrollArea);
+    m_topLayout->addWidget(m_optionsScrollArea);
 
-    searchLabel->setBuddy(m_searchInput);
     loadSettings();
 
     // The searching should be started automatically after the user did not change
@@ -404,14 +404,14 @@ KUrl DolphinSearchBox::nepomukUrlForSearching() const
 
 void DolphinSearchBox::applyReadOnlyState()
 {
-    // TODO: This is just an early draft to indicate that a state change
-    // has been done
+    if (m_readOnly) {
+        m_searchLabel->setText(Nepomuk::Query::Query::titleFromQueryUrl(m_readOnlyQuery));
+    } else {
+        m_searchLabel->setText(i18nc("@label:textbox", "Find:"));
+    }
+
     m_searchInput->setVisible(!m_readOnly);
-    m_infoLabel->setVisible(m_readOnly);
-    m_fileNameButton->setVisible(!m_readOnly);
-    m_contentButton->setVisible(!m_readOnly);
-    m_fromHereButton->setVisible(!m_readOnly);
-    m_everywhereButton->setVisible(!m_readOnly);
+    m_optionsScrollArea->setVisible(!m_readOnly);
 }
 
 #include "dolphinsearchbox.moc"
index 27561481d01756521ed2f4c3a75d2e3a37c0d97f..2d4f31b3b823a0b34e2e42cc94201c3333acbe87 100644 (file)
 #include <QWidget>
 
 class AbstractSearchFilterWidget;
-class QLabel;
 class KLineEdit;
 class KSeparator;
 class QFormLayout;
 class QPushButton;
+class QScrollArea;
+class QLabel;
 class QVBoxLayout;
 
 /**
@@ -90,8 +91,11 @@ public:
      * @param readOnly If set to true the searchbox cannot be modified
      *                 by the user and acts as visual indicator for
      *                 an externally triggered search query.
+     * @param query    If readOnly is true this URL will be used
+     *                 to show a human readable information about the
+     *                 query.
      */
-    void setReadOnly(bool readOnly);
+    void setReadOnly(bool readOnly, const KUrl& query = KUrl());
     bool isReadOnly() const;
 
 protected:
@@ -157,16 +161,17 @@ private:
 
     QVBoxLayout* m_topLayout;
 
+    QLabel* m_searchLabel;
     KLineEdit* m_searchInput;
+    QScrollArea* m_optionsScrollArea;
     QPushButton* m_fileNameButton;
     QPushButton* m_contentButton;
     KSeparator* m_separator;
     QPushButton* m_fromHereButton;
     QPushButton* m_everywhereButton;
 
-    QLabel* m_infoLabel;
-
     KUrl m_searchPath;
+    KUrl m_readOnlyQuery;
 
     QTimer* m_startSearchTimer;
 };