Rough implementation of the item related buttons
[situare] / src / ui / friendlistpanel.cpp
index dc492fd..5e461e5 100644 (file)
@@ -32,6 +32,7 @@
 #include "friendlistitem.h"
 #include "friendlistitemdelegate.h"
 #include "friendlistview.h"
+#include "imagebutton.h"
 #include "panelcommon.h"
 #include "user/user.h"
 
@@ -49,65 +50,49 @@ FriendListPanel::FriendListPanel(QWidget *parent)
     const int FRIENDPANEL_FILTER_MARGIN_RIGHT = PANEL_MARGIN_RIGHT + MAEMO5_SCROLLBAR_WIDTH + 4;
     const int FRIENDPANEL_FILTER_MARGIN_BOTTOM = 0;
 
-    QVBoxLayout *friendListPanelLayout = new QVBoxLayout();
-    friendListPanelLayout->setMargin(0);
-    friendListPanelLayout->setSpacing(0);
-    setLayout(friendListPanelLayout);
-
-    QHBoxLayout *filterLayout = new QHBoxLayout();
-    filterLayout->setContentsMargins(FRIENDPANEL_FILTER_MARGIN_LEFT, FRIENDPANEL_FILTER_MARGIN_TOP,
-                                     FRIENDPANEL_FILTER_MARGIN_RIGHT, FRIENDPANEL_FILTER_MARGIN_BOTTOM);
+    // --- HEADER, HOW MANY FRIENDS ARE SELECTED ---
+    m_headerWidget = new QWidget();
 
-    m_friendListHeaderWidget = new QWidget();
-    m_friendListHeaderWidget->setLayout(filterLayout);
-    m_friendListHeaderWidget->setAutoFillBackground(true);
+    m_headerWidget->hide();
+    m_headerWidget->setAutoFillBackground(true);
 
-    m_routeButton = new QPushButton(tr("Route to friend"));
+    QPalette headerPalette = m_headerWidget->palette();
+    headerPalette.setColor(QPalette::Background, Qt::black);
+    m_headerWidget->setPalette(headerPalette);
 
-    QPalette labelPalette = m_friendListHeaderWidget->palette();
-    labelPalette.setColor(QPalette::Background, Qt::black);
+    QHBoxLayout *headerLayout = new QHBoxLayout();
+    m_headerWidget->setLayout(headerLayout);
+    headerLayout->setContentsMargins(FRIENDPANEL_FILTER_MARGIN_LEFT,
+                                     FRIENDPANEL_FILTER_MARGIN_TOP,
+                                     FRIENDPANEL_FILTER_MARGIN_RIGHT,
+                                     FRIENDPANEL_FILTER_MARGIN_BOTTOM);
 
-    m_friendListHeaderWidget->setPalette(labelPalette);
-    m_friendListHeaderWidget->hide();
-    m_friendListLabel = new QLabel(this);
-    m_clearFilterButton = new QPushButton(tr("Show all"));
-
-    filterLayout->addWidget(m_friendListLabel);
-    filterLayout->addWidget(m_clearFilterButton);
+    m_headerLabel = new QLabel(this);
+    headerLayout->addWidget(m_headerLabel, 0, Qt::AlignCenter);
 
+    // --- FRIEND LIST ---
     m_friendListView = new FriendListView(this);
     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);
-    friendListPanelLayout->addWidget(m_friendListHeaderWidget);
-    friendListPanelLayout->addLayout(listViewLayout);
-
     connect(m_friendListView, SIGNAL(friendItemClicked(GeoCoordinate)),
             this, SIGNAL(findFriend(GeoCoordinate)));
 
-    connect(m_clearFilterButton, SIGNAL(clicked()),
-            this, SLOT(clearFiltering()));
+    connect(m_friendListView, SIGNAL(listItemSelectionChanged()),
+            this, SLOT(setRouteButtonDisabled()));
 
-    connect(m_routeButton, SIGNAL(clicked()),
-            this, SLOT(routeToSelectedFriend()));
-
-    /// @todo remove old filterLayout when new panel are merged
-
-    //////////////////////////////////////////////////////////////////////////
-    // NOTE! Do not mix the new filtering layout below with the old one above
-    //////////////////////////////////////////////////////////////////////////
+    connect(m_friendListView, SIGNAL(listItemSelectionChanged()),
+            this, SLOT(onListItemSelectionChanged()));
 
-    // filtering layout
-    QHBoxLayout *filteringLayout = new QHBoxLayout();
-    friendListPanelLayout->addLayout(filteringLayout);
+    // --- FOOTER, TEXT BASED FILTERING ---
+    QHBoxLayout *footerLayout = new QHBoxLayout();
 
-    // line edit for filtering
     m_filterField = new QLineEdit;
-    filteringLayout->addWidget(m_filterField);
+    footerLayout->addWidget(m_filterField);
 
     connect(m_filterField, SIGNAL(returnPressed()),
             this, SLOT(clearTextFiltering()));
@@ -115,16 +100,44 @@ FriendListPanel::FriendListPanel(QWidget *parent)
     connect(m_filterField, SIGNAL(textChanged(QString)),
             this, SLOT(filterTextChanged(QString)));
 
-    // button for clearing the filtering
-    m_filterClearButton = new QPushButton();
-    filteringLayout->addWidget(m_filterClearButton);
-    m_filterClearButton->setIcon(QIcon::fromTheme(QLatin1String("general_close")));
+    m_clearTextFilteringButton = new QPushButton();
+    footerLayout->addWidget(m_clearTextFilteringButton);
+    m_clearTextFilteringButton->setIcon(QIcon::fromTheme(QLatin1String("general_close")));
 
-    connect(m_filterClearButton, SIGNAL(clicked()),
+    connect(m_clearTextFilteringButton, SIGNAL(clicked()),
             this, SLOT(clearTextFiltering()));
 
     connect(qApp, SIGNAL(topmostWindowChanged(bool)),
             this, SLOT(topmostWindowChanged(bool)));
+
+    // --- MAIN LAYOUT ---
+    QVBoxLayout *friendListPanelLayout = new QVBoxLayout();
+    friendListPanelLayout->setMargin(0);
+    friendListPanelLayout->setSpacing(0);
+    setLayout(friendListPanelLayout);
+
+    friendListPanelLayout->addWidget(m_headerWidget);
+    friendListPanelLayout->addLayout(listViewLayout);
+    friendListPanelLayout->addLayout(footerLayout);
+
+    // --- CONTEXT BUTTONS ---
+    m_routeButton = new ImageButton(":res/images/route_to_friend.png",
+                                    ":res/images/route_to_friend_s.png",
+                                    ":res/images/route_to_friend_d.png", this);
+    m_routeButton->setDisabled(true);
+    connect(m_routeButton, SIGNAL(clicked()),
+            this, SLOT(routeToSelectedFriend()));
+
+    m_clearGroupFilteringButton = new ImageButton(":res/images/filtered.png",
+                                                  ":res/images/filtered_s.png",
+                                                  ":res/images/filtered_d.png", this);
+    m_clearGroupFilteringButton->setCheckable(true);
+    m_clearGroupFilteringButton->setDisabled(true);
+    connect(m_clearGroupFilteringButton, SIGNAL(clicked()),
+            this, SLOT(clearFiltering()));
+
+    m_itemButtonsLayout->addWidget(m_routeButton);
+    m_genericButtonsLayout->addWidget(m_clearGroupFilteringButton);
 }
 
 void FriendListPanel::anyPanelClosed()
@@ -135,6 +148,9 @@ void FriendListPanel::anyPanelClosed()
     updateKeyboardGrabbing();
 
     clearFiltering();
+
+    m_friendListView->clearItemSelection();
+    setRouteButtonDisabled();
 }
 
 void FriendListPanel::anyPanelOpened()
@@ -149,7 +165,9 @@ void FriendListPanel::clearFiltering()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_friendListHeaderWidget->hide();
+    m_headerWidget->hide();
+    m_clearGroupFilteringButton->setChecked(false);
+    m_clearGroupFilteringButton->setDisabled(true);
     m_friendListView->clearFilter();
     clearTextFiltering();
 }
@@ -219,6 +237,9 @@ void FriendListPanel::hideEvent(QHideEvent *event)
     QWidget::hideEvent(event);
     updateKeyboardGrabbing();
     clearFiltering();
+
+    m_friendListView->clearItemSelection();
+    setRouteButtonDisabled();
 }
 
 void FriendListPanel::routeToSelectedFriend()
@@ -236,7 +257,7 @@ void FriendListPanel::setFilteringLayoutVisibility(bool visible)
     qDebug() << __PRETTY_FUNCTION__;
 
     m_filterField->setVisible(visible);
-    m_filterClearButton->setVisible(visible);
+    m_clearTextFilteringButton->setVisible(visible);
 }
 
 void FriendListPanel::updateKeyboardGrabbing()
@@ -252,6 +273,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__;
@@ -265,14 +293,16 @@ void FriendListPanel::showFriendsInList(const QList<QString> &userIDs)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_friendListLabel->setText(tr("Selected: %1").arg(userIDs.count()));
+    m_headerLabel->setText(tr("Selected: %1").arg(userIDs.count()));
 
-    m_friendListHeaderWidget->show();
+    m_headerWidget->show();
+    m_clearGroupFilteringButton->setDisabled(false);
+    m_clearGroupFilteringButton->setChecked(true);
     m_friendListView->filter(userIDs);
 
     clearTextFiltering();
 
-    emit showPanelRequested(this);
+    emit openPanelRequested(this);
 }
 
 void FriendListPanel::topmostWindowChanged(bool mainWindowIsTopmost)