Fixed list view selection to work as expected. Selection is cleared
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Wed, 18 Aug 2010 12:10:48 +0000 (15:10 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Wed, 18 Aug 2010 12:10:48 +0000 (15:10 +0300)
when panel is hidden.

src/ui/extendedlistitem.cpp
src/ui/friendlistpanel.cpp
src/ui/friendlistpanel.h
src/ui/listview.cpp
src/ui/routingpanel.cpp
src/ui/routingpanel.h

index 4709de3..7e0b859 100644 (file)
@@ -132,6 +132,7 @@ void ExtendedListItem::setSelected(bool selected)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
+    QListWidgetItem::setSelected(selected);
     m_selected = selected;
     setData(ITEM_EXPANDED_INDEX, m_selected);
 
index 4f8d230..bc9d87c 100644 (file)
@@ -63,6 +63,7 @@ FriendListPanel::FriendListPanel(QWidget *parent)
     m_friendListHeaderWidget->setAutoFillBackground(true);
 
     m_routeButton = new QPushButton(tr("Route to friend"));
+    m_routeButton->setDisabled(true);
 
     QPalette labelPalette = m_friendListHeaderWidget->palette();
     labelPalette.setColor(QPalette::Background, Qt::black);
@@ -79,7 +80,8 @@ FriendListPanel::FriendListPanel(QWidget *parent)
     m_friendListView->setItemDelegate(new FriendListItemDelegate(this));
 
     QVBoxLayout *listViewLayout = new QVBoxLayout;
-    listViewLayout->setContentsMargins(PANEL_MARGIN_LEFT, 0, PANEL_MARGIN_RIGHT, 0);
+    listViewLayout->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP,
+                                       PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
     listViewLayout->addWidget(m_friendListView);
 
     friendListPanelLayout->addWidget(m_routeButton);
@@ -95,6 +97,9 @@ FriendListPanel::FriendListPanel(QWidget *parent)
     connect(m_routeButton, SIGNAL(clicked()),
             this, SLOT(routeToSelectedFriend()));
 
+    connect(m_friendListView, SIGNAL(clicked(QModelIndex)),
+            this, SLOT(setRouteButtonDisabled()));
+
     /// @todo remove old filterLayout when new panel are merged
 
     //////////////////////////////////////////////////////////////////////////
@@ -219,6 +224,8 @@ void FriendListPanel::hideEvent(QHideEvent *event)
     QWidget::hideEvent(event);
     updateKeyboardGrabbing();
     clearFiltering();
+
+    m_friendListView->clearSelection();
 }
 
 void FriendListPanel::routeToSelectedFriend()
@@ -252,6 +259,13 @@ void FriendListPanel::updateKeyboardGrabbing()
     }
 }
 
+void FriendListPanel::setRouteButtonDisabled()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_routeButton->setDisabled(m_friendListView->selectedItems().isEmpty());
+}
+
 void FriendListPanel::showEvent(QShowEvent *event)
 {
     qDebug() << __PRETTY_FUNCTION__;
index 49d0ccb..2d3bfdc 100644 (file)
@@ -168,6 +168,13 @@ private slots:
     void routeToSelectedFriend();
 
     /**
+    * @brief Sets route button disabled.
+    *
+    * Disabled if there isn't any list item selected.
+    */
+    void setRouteButtonDisabled();
+
+    /**
      * @brief Slot to show friends in list.
      *
      * Shows only friends that are on userIDs list
index c1b8ca9..88e943a 100644 (file)
@@ -207,8 +207,12 @@ ListItem *ListView::listItemAt(int index)
 ListItem *ListView::selectedItem()
 {
     qDebug() << __PRETTY_FUNCTION__;
+    QList<QListWidgetItem *> selectedListItems = selectedItems();
 
-    return m_previousItem;
+    if (!selectedListItems.isEmpty())
+        return dynamic_cast<ListItem *>(selectedListItems.first());
+    else
+        return 0;
 }
 
 void ListView::setSelectedItem(ListItem *item)
index ebd75c6..7607972 100644 (file)
@@ -65,6 +65,9 @@ RoutingPanel::RoutingPanel(QWidget *parent)
             this,
             SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
 
+    connect(m_locationListView, SIGNAL(clicked(QModelIndex)),
+            this, SLOT(setRouteButtonDisabled()));
+
     connect(m_routeButton, SIGNAL(clicked()),
             this, SLOT(routeToSelectedLocation()));
 
@@ -75,6 +78,16 @@ RoutingPanel::RoutingPanel(QWidget *parent)
             this, SIGNAL(requestSearchLocation()));
 }
 
+void RoutingPanel::hideEvent(QHideEvent *event)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    Q_UNUSED(event);
+
+    m_locationListView->clearSelection();
+    m_routeWaypointListView->clearSelection();
+}
+
 void RoutingPanel::populateLocationListView(const QList<Location> &locations)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -145,3 +158,10 @@ void RoutingPanel::setRoute(Route &route)
 
     emit showPanelRequested(this);
 }
+
+void RoutingPanel::setRouteButtonDisabled()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_routeButton->setDisabled(m_locationListView->selectedItems().isEmpty());
+}
index d329f1e..73bd829 100644 (file)
@@ -49,6 +49,19 @@ public:
     RoutingPanel(QWidget *parent = 0);
 
 /*******************************************************************************
+ * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
+ ******************************************************************************/
+protected:
+    /**
+    * @brief Re-implemented from QWidget::hideEvent()
+    *
+    * Clears lists' selections.
+    *
+    * @param event
+    */
+    void hideEvent(QHideEvent *event);
+
+/*******************************************************************************
  * MEMBER FUNCTIONS AND SLOTS
  ******************************************************************************/
 private slots:
@@ -74,6 +87,13 @@ private slots:
     */
     void setRoute(Route &route);
 
+    /**
+    * @brief Sets route button disabled.
+    *
+    * Disabled if there isn't any list item selected.
+    */
+    void setRouteButtonDisabled();
+
 /*******************************************************************************
  * SIGNALS
  ******************************************************************************/