Made small cosmetic changes to contact and back button images, removed btn suffix...
[situare] / src / ui / locationsearchpanel.cpp
index 5bfd2e6..8b7b4d0 100644 (file)
@@ -20,7 +20,6 @@
     USA.
 */
 
-#include <QPair>
 #include <QSettings>
 
 #include "avatarimage.h"
@@ -77,7 +76,7 @@ LocationSearchPanel::LocationSearchPanel(QWidget *parent)
             SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
 
     connect(m_locationListView, SIGNAL(listItemSelectionChanged()),
-            this, SLOT(setRouteButtonDisabled()));
+            this, SLOT(onListItemSelectionChanged()));
 
     QVBoxLayout *resultsListViewLayout = new QVBoxLayout;
     resultsListViewLayout->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP,
@@ -93,13 +92,21 @@ LocationSearchPanel::LocationSearchPanel(QWidget *parent)
     const int MARGIN_LEFT = 0;
     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->setAlignment(Qt::AlignCenter);
+
+    QPalette m_noSearchPalette = palette();
+    m_noSearchPalette.setColor(QPalette::Foreground, Qt::white);
+    m_noSearchLabel->setPalette(m_noSearchPalette);
 
     panelLayout->addWidget(resultsHeaderWidget);
+    panelLayout->addWidget(m_noSearchLabel, Qt::AlignCenter);
     panelLayout->addLayout(resultsListViewLayout);
 
     // --- CONTEXT BUTTONS ---
-    m_routeButton = new ImageButton(":res/images/compass.png", "", "", this);
-    m_routeButton->setDisabled(true);
+    m_routeButton = new ImageButton(":res/images/route_to_location.png",
+                                    ":res/images/route_to_location_s.png", "", this);
     connect(m_routeButton, SIGNAL(clicked()),
             this, SLOT(routeToSelectedLocation()));
 
@@ -109,20 +116,21 @@ LocationSearchPanel::LocationSearchPanel(QWidget *parent)
     connect(searchLocationButton, SIGNAL(clicked()),
             this, SIGNAL(requestSearchLocation()));
 
-    m_clearLocationListButton = new ImageButton(":/res/images/clear_btn.png",
-                                                ":/res/images/clear_btn_s.png",
-                                                ":/res/images/clear_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()),
-            this, SLOT(showSearchHistoryList()));
+            this, SLOT(showSearchHistoryListView()));
 
-    m_contextButtonLayout->addWidget(m_routeButton);
-    m_contextButtonLayout->addWidget(searchLocationButton);
-    m_contextButtonLayout->addWidget(m_clearLocationListButton);
+    m_itemButtonsLayout->addWidget(m_routeButton);
+    m_genericButtonsLayout->addWidget(searchLocationButton);
+    m_genericButtonsLayout->addWidget(m_clearLocationListButton);
 
     readSettings();
-    showSearchHistoryList();
+    showSearchHistoryListView();
+    showEmptyPanel(true);
 }
 
 LocationSearchPanel::~LocationSearchPanel()
@@ -154,6 +162,8 @@ void LocationSearchPanel::prependSearchHistory(QString searchString, QDateTime d
     const int SEARCH_HISTORY_LIMIT = 10;
     static int counter = 0;
 
+    showSearchHistoryListView();
+
     if (m_searchHistoryListView->count() >= SEARCH_HISTORY_LIMIT)
         m_searchHistoryListView->removeLastItem();
 
@@ -168,8 +178,6 @@ void LocationSearchPanel::clearListsSelections()
 
     m_locationListView->clearItemSelection();
     m_searchHistoryListView->clearItemSelection();
-
-    setRouteButtonDisabled();
 }
 
 void LocationSearchPanel::hideEvent(QHideEvent *event)
@@ -185,12 +193,8 @@ void LocationSearchPanel::populateLocationListView(const QList<Location> &locati
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_searchHistoryListView->clearItemSelection();
-    m_searchHistoryListView->hide();
-    setHeaderText(locations.count());
     m_locationListView->clearList();
-    m_clearLocationListButton->setEnabled(true);
-    m_locationListView->show();
+    showLocationListView(locations.count());
 
     for (int i = 0; i < locations.size(); ++i) {
         LocationListItem *item = new LocationListItem();
@@ -198,16 +202,6 @@ void LocationSearchPanel::populateLocationListView(const QList<Location> &locati
         m_locationListView->addListItem(QString::number(i), item);
     }
 
-    const int FIRST_LOCATION_ITEM_INDEX = 0;
-    const int ONE_LOCATION_ITEM = 1;
-
-    if (locations.size() == ONE_LOCATION_ITEM) {
-        ListItem *item = m_locationListView->listItemAt(FIRST_LOCATION_ITEM_INDEX);
-
-        if (item)
-            m_locationListView->setSelectedItem(item);
-    }
-
     m_locationListView->scrollToTop();
 }
 
@@ -241,6 +235,17 @@ void LocationSearchPanel::routeToSelectedLocation()
         emit routeToLocation(item->coordinates());
 }
 
+void LocationSearchPanel::showEmptyPanel(bool show)
+{
+    if (show) {
+        m_noSearchLabel->show();
+        m_searchHistoryListView->hide();
+    }
+    else {
+        m_noSearchLabel->hide();
+    }
+}
+
 void LocationSearchPanel::setHeaderText(int count)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -248,14 +253,19 @@ void LocationSearchPanel::setHeaderText(int count)
     m_resultsLabel->setText(tr("Search results: %1").arg(count));
 }
 
-void LocationSearchPanel::setRouteButtonDisabled()
+void LocationSearchPanel::showLocationListView(int locationItemsCount)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_routeButton->setDisabled(m_locationListView->selectedItems().isEmpty());
+    m_searchHistoryListView->clearItemSelection();
+    m_searchHistoryListView->hide();
+    setHeaderText(locationItemsCount);
+    m_clearLocationListButton->setEnabled(true);
+    m_locationListView->show();
+    showEmptyPanel(false);
 }
 
-void LocationSearchPanel::showSearchHistoryList()
+void LocationSearchPanel::showSearchHistoryListView()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -264,4 +274,5 @@ void LocationSearchPanel::showSearchHistoryList()
     m_resultsLabel->setText(tr("Search history:"));
     m_clearLocationListButton->setDisabled(true);
     m_searchHistoryListView->show();
+    showEmptyPanel(false);
 }