Merge branch 'master' into friendlist
[situare] / src / ui / friendlistpanel.cpp
index b3b06e9..8a631db 100644 (file)
 #include "friendlistpanel.h"
 #include "friendlistview.h"
 #include "friendlistitem.h"
+#include "panelcommon.h"
+#include "panelsliderbar.h"
 
 FriendListPanel::FriendListPanel(QWidget *parent)
     : QWidget(parent)
 {
     qDebug() << __PRETTY_FUNCTION__;
     m_friendsPanelVBox = new QVBoxLayout(this);
-    this->setLayout(m_friendsPanelVBox);
-    m_friendsPanelExpandButton = new QPushButton("Friends", this);
-    m_friendsPanelVBox->addWidget(m_friendsPanelExpandButton);
+    m_friendsPanelVBox->setMargin(0);
+    m_friendsPanelVBox->setContentsMargins(SLIDINGBAR_WIDTH+1, 0, SIDEBAR_WIDTH, 0);
+    m_friendsPanelVBox->setSpacing(0);
+    setLayout(m_friendsPanelVBox);
+
+    m_clearFilterButton = new QPushButton("Clear filtering");
+    m_clearFilterButton->hide();
+    m_friendsPanelVBox->addWidget(m_clearFilterButton, 0, Qt::AlignCenter);
+
+    m_panelBase = new QWidget(this);
+    m_panelBase->setLayout(m_friendsPanelVBox);
+    m_panelBase->move(TOP_CORNER_X + SLIDINGBAR_WIDTH,PANEL_TOP_Y);
+    m_panelBase->resize(FRIENDPANEL_WIDTH, FRIENDPANEL_HEIGHT);
+
+    QPalette pal = palette();
+    pal.setColor(QPalette::Background, QColor(0, 0, 0, 128));
+    m_panelBase->setPalette(pal);
+    m_panelBase->setAutoFillBackground(true);
 
     m_friendListView = new FriendListView(this);
     QScrollArea *friendListScroll = new QScrollArea(this);
+    friendListScroll->setWidgetResizable(false);
     friendListScroll->setWidget(m_friendListView);
-    friendListScroll->setWidgetResizable(true);
     friendListScroll->viewport()->setAutoFillBackground(false);
+    friendListScroll->widget()->setAutoFillBackground(false);
 
     m_friendsPanelVBox->addWidget(friendListScroll);
 
-    this->resize(420,600);
+    m_friendsPanelSlidingBar = new PanelSliderBar(this, RIGHT);
+    m_friendsPanelSlidingBar->move(TOP_CORNER_X, PANEL_TOP_Y);
 
     m_friendsPanelStateMachine = new QStateMachine(this);
     m_friendsPanelStateClosed = new QState(m_friendsPanelStateMachine);
-    m_friendsPanelStateClosed->assignProperty(this, "pos", QPoint(800,0));
+    m_friendsPanelStateClosed->assignProperty(this, "pos", QPoint(
+            FRIENDPANEL_CLOSED_X, PANEL_TOP_Y));
     m_friendsPanelStateMachine->setInitialState(m_friendsPanelStateClosed);
 
     m_friendsPanelStateOpened = new QState(m_friendsPanelStateMachine);
-    m_friendsPanelStateOpened->assignProperty(this, "pos", QPoint(400,0));
+    m_friendsPanelStateOpened->assignProperty(this, "pos", QPoint(
+            FRIENDPANEL_OPENED_X, PANEL_TOP_Y));
 
     m_friendsPanelTransitionOpen = m_friendsPanelStateClosed->addTransition(
-            m_friendsPanelExpandButton, SIGNAL(clicked()), m_friendsPanelStateOpened);
-    m_friendsPanelTransitionOpen->addAnimation(new QPropertyAnimation(this, "pos"));
+            m_friendsPanelSlidingBar, SIGNAL(clicked()), m_friendsPanelStateOpened);
+    m_friendsPanelTransitionOpen->addAnimation(new QPropertyAnimation(this, "pos", this));
 
     m_friendsPanelTransitionClose = m_friendsPanelStateOpened->addTransition(
-            m_friendsPanelExpandButton, SIGNAL(clicked()), m_friendsPanelStateClosed);
-    m_friendsPanelTransitionClose->addAnimation(new QPropertyAnimation(this, "pos"));
+            m_friendsPanelSlidingBar, SIGNAL(clicked()), m_friendsPanelStateClosed);
+    m_friendsPanelTransitionClose->addAnimation(new QPropertyAnimation(this, "pos", this));
 
     m_friendsPanelStateMachine->start();
+    setObjectName("FriendsPanel");
+
+    connect(m_clearFilterButton, SIGNAL(clicked()), this, SLOT(clearFriendListFilter()));
 }
 
 void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
@@ -70,11 +94,33 @@ void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
     foreach (User *user, friendList) {
         FriendListItem *item = new FriendListItem(m_friendListView);
         item->setData(user);
-        m_friendListView->addWidget(item);
+        m_friendListView->addWidget(user->userId(), item);
+
+        connect(item, SIGNAL(findFriend(QPointF)),
+            this, SIGNAL(findFriend(QPointF)));
     }
 }
 
 void FriendListPanel::reDrawFriendsPanel(int width, int height)
 {
     qDebug() << __PRETTY_FUNCTION__;
+    resize(FRIENDPANEL_WIDTH + SLIDINGBAR_WIDTH,height + MARGIN_CORRECTION);
+    m_panelBase->resize(FRIENDPANEL_WIDTH, height + MARGIN_CORRECTION);
+    m_friendsPanelStateClosed->assignProperty(this, "pos", QPoint(
+            width - PANEL_PEEK_AMOUNT - SLIDINGBAR_WIDTH + MARGIN_CORRECTION, PANEL_TOP_Y));
+    m_friendsPanelStateOpened->assignProperty(this, "pos", QPoint(
+            width - FRIENDPANEL_WIDTH - SLIDINGBAR_WIDTH + MARGIN_CORRECTION, PANEL_TOP_Y));
+    move(width - PANEL_PEEK_AMOUNT - SLIDINGBAR_WIDTH + MARGIN_CORRECTION, PANEL_TOP_Y);
+}
+
+void FriendListPanel::clearFriendListFilter()
+{
+    m_clearFilterButton->hide();
+    m_friendListView->clearFilter();
+}
+
+void FriendListPanel::filterFriendList(const QList<QString> &userIDs)
+{
+    m_clearFilterButton->show();
+    m_friendListView->filter(userIDs);
 }