Assistant: Introduce a 'compact' display for the simple search
authorkh1 <karsten.heimrich@digia.com>
Thu, 9 Jan 2014 07:56:43 +0000 (08:56 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Thu, 9 Jan 2014 09:34:55 +0000 (10:34 +0100)
Setting the mode disables the Previous and Next buttons for the simple
search history. This is meant to be used e.g. in Qt Creator where the
horizontal space in the side bar is precious.

Change-Id: If13ffbf2656c471ceb10c5bb15e39166fedbcb85
Reviewed-by: Karsten Heimrich <karsten.heimrich@digia.com>
src/assistant/help/qhelpsearchquerywidget.cpp
src/assistant/help/qhelpsearchquerywidget.h

index d2e5da0..d071613 100644 (file)
@@ -101,6 +101,7 @@ private:
 
     QHelpSearchQueryWidgetPrivate()
         : QObject()
+        , compactMode(false)
         , simpleSearch(true)
         , searchCompleter(new CompleterModel(this), this)
     {
@@ -287,6 +288,25 @@ private:
     }
 
 private slots:
+    bool eventFilter(QObject *ob, QEvent *event)
+    {
+        if (event->type() == QEvent::KeyPress) {
+            QKeyEvent *const keyEvent = static_cast<QKeyEvent *>(event);
+            if (keyEvent->key() == Qt::Key_Down) {
+                if (simpleQueries.curQuery + 1 < simpleQueries.queries.size())
+                    nextQuery();
+                return true;
+            }
+            if (keyEvent->key() == Qt::Key_Up) {
+                if (simpleQueries.curQuery > 0)
+                    prevQuery();
+                return true;
+            }
+
+        }
+        return QObject::eventFilter(ob, event);
+    }
+
     void showHideAdvancedSearch()
     {
         if (simpleSearch) {
@@ -381,6 +401,7 @@ private slots:
 private:
     friend class QHelpSearchQueryWidget;
 
+    bool compactMode;
     bool simpleSearch;
     QLabel *simpleSearchLabel;
     QLabel *advancedSearchLabel;
@@ -441,6 +462,7 @@ QHelpSearchQueryWidget::QHelpSearchQueryWidget(QWidget *parent)
     d->simpleSearchLabel = new QLabel(this);
     d->defaultQuery = new QLineEdit(this);
     d->defaultQuery->setCompleter(&d->searchCompleter);
+    d->defaultQuery->installEventFilter(d);
     d->prevQueryButton = new QToolButton(this);
     d->prevQueryButton->setArrowType(Qt::LeftArrow);
     d->prevQueryButton->setEnabled(false);
@@ -529,6 +551,7 @@ QHelpSearchQueryWidget::QHelpSearchQueryWidget(QWidget *parent)
         d, SLOT(showHideAdvancedSearch()));
 #endif
     connect(this, SIGNAL(search()), d, SLOT(searchRequested()));
+    setCompactMode(true);
 }
 
 /*!
@@ -593,6 +616,21 @@ void QHelpSearchQueryWidget::setQuery(const QList<QHelpSearchQuery> &queryList)
     d->searchRequested();
 }
 
+bool QHelpSearchQueryWidget::isCompactMode() const
+{
+    return d->compactMode;
+}
+
+void QHelpSearchQueryWidget::setCompactMode(bool on)
+{
+    if (d->compactMode != on) {
+        d->compactMode = on;
+        d->prevQueryButton->setVisible(!on);
+        d->nextQueryButton->setVisible(!on);
+        d->simpleSearchLabel->setVisible(!on);
+    }
+}
+
 /*!
     \reimp
 */
index f72e2ae..ed0e209 100644 (file)
@@ -71,6 +71,9 @@ public:
     QList<QHelpSearchQuery> query() const;
     void setQuery(const QList<QHelpSearchQuery> &queryList);
 
+    bool isCompactMode() const;
+    Q_SLOT void setCompactMode(bool on);
+
 Q_SIGNALS:
     void search();