Tuning the look of the location search panel with empty search history
[situare] / src / ui / locationsearchpanel.cpp
index 2afe5a9..beb9b0c 100644 (file)
@@ -56,8 +56,8 @@ LocationSearchPanel::LocationSearchPanel(QWidget *parent)
                                      PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
 
     m_resultsLabel = new QLabel(this);
+    m_resultsLabel->hide();
     headerLayout->addWidget(m_resultsLabel, 0, Qt::AlignCenter);
-    setHeaderText(0);
 
     // --- SEARCH HISTORY LIST VIEW ---
     m_searchHistoryListView = new SearchHistoryListView(this);
@@ -93,7 +93,7 @@ LocationSearchPanel::LocationSearchPanel(QWidget *parent)
     panelLayout->setContentsMargins(MARGIN_LEFT, PANEL_MARGIN_TOP,
                                     PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
     m_noSearchLabel = new QLabel();
-    m_noSearchLabel->setText("No search results");
+    m_noSearchLabel->setText("No search history");
     m_noSearchLabel->setAlignment(Qt::AlignCenter);
 
     QPalette m_noSearchPalette = palette();
@@ -116,9 +116,9 @@ LocationSearchPanel::LocationSearchPanel(QWidget *parent)
     connect(searchLocationButton, SIGNAL(clicked()),
             this, SIGNAL(requestSearchLocation()));
 
-    m_clearLocationListButton = new ImageButton(":/res/images/back_btn.png",
-                                                ":/res/images/back_btn_s.png",
-                                                ":/res/images/back_btn_d.png", this);
+    m_clearLocationListButton = new ImageButton(":/res/images/back.png",
+                                                ":/res/images/back_s.png",
+                                                ":/res/images/back_d.png", this);
     m_clearLocationListButton->setDisabled(true);
 
     connect(m_clearLocationListButton, SIGNAL(clicked()),
@@ -128,8 +128,8 @@ LocationSearchPanel::LocationSearchPanel(QWidget *parent)
     m_genericButtonsLayout->addWidget(searchLocationButton);
     m_genericButtonsLayout->addWidget(m_clearLocationListButton);
 
+    showEmptyPanel(true);
     readSettings();
-    showSearchHistoryListView();
 }
 
 LocationSearchPanel::~LocationSearchPanel()
@@ -154,21 +154,6 @@ LocationSearchPanel::~LocationSearchPanel()
     settings.setValue(SETTINGS_SEARCH_HISTORY, searchHistories);
 }
 
-void LocationSearchPanel::prependSearchHistory(QString searchString, QDateTime dateTime)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    const int SEARCH_HISTORY_LIMIT = 10;
-    static int counter = 0;
-
-    if (m_searchHistoryListView->count() >= SEARCH_HISTORY_LIMIT)
-        m_searchHistoryListView->removeLastItem();
-
-    SearchHistoryListItem *item = new SearchHistoryListItem();
-    item->setSearchHistoryData(searchString, dateTime);
-    m_searchHistoryListView->prependListItem(QString::number(counter++), item);
-}
-
 void LocationSearchPanel::clearListsSelections()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -202,6 +187,21 @@ void LocationSearchPanel::populateLocationListView(const QList<Location> &locati
     m_locationListView->scrollToTop();
 }
 
+void LocationSearchPanel::prependSearchHistory(QString searchString, QDateTime dateTime)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    const int SEARCH_HISTORY_LIMIT = 10;
+    static int counter = 0;
+
+    if (m_searchHistoryListView->count() >= SEARCH_HISTORY_LIMIT)
+        m_searchHistoryListView->removeLastItem();
+
+    SearchHistoryListItem *item = new SearchHistoryListItem();
+    item->setSearchHistoryData(searchString, dateTime);
+    m_searchHistoryListView->prependListItem(QString::number(counter++), item);
+}
+
 void LocationSearchPanel::readSettings()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -211,6 +211,9 @@ void LocationSearchPanel::readSettings()
     QSettings settings(DIRECTORY_NAME, FILE_NAME);
     QList<QVariant> searchHistories = settings.value(SETTINGS_SEARCH_HISTORY).toList();
 
+    if (searchHistories.count() > 0)
+            showSearchHistoryListView();
+
     //Read from end to begin so items are prepended in correct order
     for (int i = searchHistories.count() - 1; i >= 0; --i) {
         QList<QVariant> searchHistory = searchHistories.at(i).toList();
@@ -232,24 +235,26 @@ void LocationSearchPanel::routeToSelectedLocation()
         emit routeToLocation(item->coordinates());
 }
 
+void LocationSearchPanel::setHeaderText(int count)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_resultsLabel->setText(tr("Search results: %1").arg(count));
+}
+
 void LocationSearchPanel::showEmptyPanel(bool show)
 {
     if (show) {
         m_noSearchLabel->show();
         m_searchHistoryListView->hide();
+        m_locationListView->hide();
     }
     else {
         m_noSearchLabel->hide();
+        m_resultsLabel->show();
     }
 }
 
-void LocationSearchPanel::setHeaderText(int count)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_resultsLabel->setText(tr("Search results: %1").arg(count));
-}
-
 void LocationSearchPanel::showLocationListView(int locationItemsCount)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -271,5 +276,4 @@ void LocationSearchPanel::showSearchHistoryListView()
     m_resultsLabel->setText(tr("Search history:"));
     m_clearLocationListButton->setDisabled(true);
     m_searchHistoryListView->show();
-    showEmptyPanel(false);
 }