Merge branch 'master' into contact_dialog
[situare] / src / ui / friendlistpanel.cpp
index f99bfa4..d8740af 100644 (file)
@@ -6,6 +6,7 @@
         Henri Lampela - henri.lampela@ixonos.com
         Pekka Nissinen - pekka.nissinen@ixonos.com
         Sami Rämö - sami.ramo@ixonos.com
+        Jussi Laitinen - jussi.laitinen@ixonos.com
 
     Situare is free software; you can redistribute it and/or
     modify it under the terms of the GNU General Public License
 #include "friendlistitem.h"
 #include "friendlistitemdelegate.h"
 #include "friendlistview.h"
+#include "imagebutton.h"
 #include "panelcommon.h"
 #include "user/user.h"
 
 #include "friendlistpanel.h"
 
 FriendListPanel::FriendListPanel(QWidget *parent)
-    : QWidget(parent),
+    : PanelBase(parent),
       m_mainWindowIsTopmost(false),
       m_somePanelIsOpen(false)
 {
@@ -49,36 +51,27 @@ 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);
-
-    m_friendListHeaderWidget = new QWidget();
-    m_friendListHeaderWidget->setLayout(filterLayout);
-    m_friendListHeaderWidget->setAutoFillBackground(true);
+    // --- HEADER, HOW MANY FRIENDS ARE SELECTED ---
+    m_headerWidget = new QWidget();
 
-    m_routeButton = new QPushButton(tr("Route to friend"));
-    m_routeButton->setDisabled(true);
-
-    m_showContactButton = new QPushButton(tr("Show contact"));
-    m_showContactButton->setDisabled(true);
+    m_headerWidget->hide();
+    m_headerWidget->setAutoFillBackground(true);
 
-    QPalette labelPalette = m_friendListHeaderWidget->palette();
-    labelPalette.setColor(QPalette::Background, Qt::black);
+    QPalette headerPalette = m_headerWidget->palette();
+    headerPalette.setColor(QPalette::Background, Qt::black);
+    m_headerWidget->setPalette(headerPalette);
 
-    m_friendListHeaderWidget->setPalette(labelPalette);
-    m_friendListHeaderWidget->hide();
-    m_friendListLabel = new QLabel(this);
-    m_clearFilterButton = new QPushButton(tr("Show all"));
+    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);
 
-    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));
 
@@ -87,36 +80,17 @@ FriendListPanel::FriendListPanel(QWidget *parent)
                                        PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
     listViewLayout->addWidget(m_friendListView);
 
-    friendListPanelLayout->addWidget(m_showContactButton);
-    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_routeButton, SIGNAL(clicked()),
-            this, SLOT(routeToSelectedFriend()));
-
     connect(m_friendListView, SIGNAL(listItemSelectionChanged()),
-            this, SLOT(setSelectionButtonsDisabled()));
+            this, SLOT(setRouteButtonDisabled()));
 
-    /// @todo remove old filterLayout when new panel are merged
+    // --- FOOTER, TEXT BASED FILTERING ---
+    QHBoxLayout *footerLayout = new QHBoxLayout();
 
-    //////////////////////////////////////////////////////////////////////////
-    // NOTE! Do not mix the new filtering layout below with the old one above
-    //////////////////////////////////////////////////////////////////////////
-
-    // filtering layout
-    QHBoxLayout *filteringLayout = new QHBoxLayout();
-    friendListPanelLayout->addLayout(filteringLayout);
-
-    // line edit for filtering
     m_filterField = new QLineEdit;
-    filteringLayout->addWidget(m_filterField);
+    footerLayout->addWidget(m_filterField);
 
     connect(m_filterField, SIGNAL(returnPressed()),
             this, SLOT(clearTextFiltering()));
@@ -124,19 +98,51 @@ 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_showContactButton = new ImageButton(":res/images/contact_btn.png",
+                                          ":res/images/contact_btn_s.png",
+                                          ":res/images/contact_btn_d.png", this);
     connect(m_showContactButton, SIGNAL(clicked()),
             this, SLOT(requestSelectedFriendContactDialog()));
+
+    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_contextButtonLayout->addWidget(m_routeButton);
+    m_contextButtonLayout->addWidget(m_showContactButton);
+    m_contextButtonLayout->addWidget(m_clearGroupFilteringButton);
 }
 
 void FriendListPanel::anyPanelClosed()
@@ -149,7 +155,7 @@ void FriendListPanel::anyPanelClosed()
     clearFiltering();
 
     m_friendListView->clearItemSelection();
-    setSelectionButtonsDisabled();
+    setRouteButtonDisabled();
 }
 
 void FriendListPanel::anyPanelOpened()
@@ -164,7 +170,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();
 }
@@ -236,20 +244,20 @@ void FriendListPanel::hideEvent(QHideEvent *event)
     clearFiltering();
 
     m_friendListView->clearItemSelection();
-    setSelectionButtonsDisabled();
+    setRouteButtonDisabled();
 }
 
 void FriendListPanel::requestSelectedFriendContactDialog()
 {
-    qDebug() << __PRETTY_FUNCTION__;
+     qDebug() << __PRETTY_FUNCTION__;
 
-    FriendListItem *item = dynamic_cast<FriendListItem *>(m_friendListView->selectedItem());
+     FriendListItem *item = dynamic_cast<FriendListItem *>(m_friendListView->selectedItem());
 
-    if (item) {
-        QString facebookId = item->facebookId();
-        if (!facebookId.isEmpty())
-            emit requestContactDialog(facebookId);
-    }
+     if (item) {
+         QString facebookId = item->facebookId();
+         if (!facebookId.isEmpty())
+             emit requestContactDialog(facebookId);
+     }
 }
 
 void FriendListPanel::routeToSelectedFriend()
@@ -267,17 +275,7 @@ void FriendListPanel::setFilteringLayoutVisibility(bool visible)
     qDebug() << __PRETTY_FUNCTION__;
 
     m_filterField->setVisible(visible);
-    m_filterClearButton->setVisible(visible);
-}
-
-void FriendListPanel::setSelectionButtonsDisabled()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    bool isAnyItemSelected = m_friendListView->selectedItems().isEmpty();
-
-    m_routeButton->setDisabled(isAnyItemSelected);
-    m_showContactButton->setDisabled(isAnyItemSelected);
+    m_clearTextFilteringButton->setVisible(visible);
 }
 
 void FriendListPanel::updateKeyboardGrabbing()
@@ -293,6 +291,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__;
@@ -306,14 +311,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)