4 #include "headerlistitemdelegate.h"
5 #include "personlistitem.h"
6 #include "extendedlistitemdelegate.h"
7 #include "personlistview.h"
8 #include "imagebutton.h"
9 #include "panelcommon.h"
10 #include "../user/user.h"
12 #include "meetpeoplepanel.h"
14 MeetPeoplePanel::MeetPeoplePanel(QWidget *parent)
16 m_headerListItemDelegate(0)
18 qDebug() << __PRETTY_FUNCTION__;
20 QVBoxLayout *meetPeopleLayout = new QVBoxLayout;
21 meetPeopleLayout->setMargin(0);
22 meetPeopleLayout->setSpacing(0);
23 setLayout(meetPeopleLayout);
25 m_personListView = new PersonListView(this);
26 m_personListItemDelegate = new ExtendedListItemDelegate(this);
28 connect(m_personListView, SIGNAL(listItemSelectionChanged()),
29 this, SLOT(listItemSelectionHandler()));
30 connect(m_personListView, SIGNAL(personItemClicked(GeoCoordinate)),
31 this, SIGNAL(findPerson(GeoCoordinate)));
33 QVBoxLayout *listViewLayout = new QVBoxLayout;
34 listViewLayout->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP,
35 PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
36 listViewLayout->addWidget(m_personListView);
37 meetPeopleLayout->addLayout(listViewLayout);
39 ImageButton *refreshInterestingPeopleButton = new ImageButton(":/res/images/refresh.png",
40 ":/res/images/refresh_s.png",
42 connect(refreshInterestingPeopleButton, SIGNAL(clicked()),
43 this, SIGNAL(requestInterestingPeople()));
45 ImageButton *searchPeopleButton = new ImageButton(":/res/images/search.png",
46 ":/res/images/search_s.png", "", this);
47 connect(searchPeopleButton, SIGNAL(clicked()),
48 this, SIGNAL(requestInterestingPeopleSearch()));
50 m_friendListButton = new ImageButton(":/res/images/friend_list_btn.png",
51 ":/res/images/friend_list_btn_s.png",
52 ":/res/images/friend_list_btn_d.png", this);
53 connect(m_friendListButton, SIGNAL(clicked()),
54 this, SLOT(showFriend()));
56 ImageButton *messageButton = new ImageButton(":/res/images/chat_btn.png",
57 ":/res/images/chat_btn_s.png",
58 ":/res/images/chat_btn_d.png", this);
59 connect(messageButton, SIGNAL(clicked()),
60 this, SLOT(messageButtonPressed()));
62 m_genericButtonsLayout->addWidget(refreshInterestingPeopleButton);
63 m_genericButtonsLayout->addWidget(searchPeopleButton);
64 m_itemButtonsLayout->addWidget(m_friendListButton);
65 m_itemButtonsLayout->addWidget(messageButton);
68 void MeetPeoplePanel::anyPanelClosed()
70 qDebug() << __PRETTY_FUNCTION__;
72 m_personListView->clearItemSelection();
75 void MeetPeoplePanel::hideEvent(QHideEvent *event)
77 qDebug() << __PRETTY_FUNCTION__;
79 QWidget::hideEvent(event);
81 m_personListView->clearItemSelection();
84 void MeetPeoplePanel::initItemDelegates()
86 qDebug() << __PRETTY_FUNCTION__;
88 m_personListView->setItemDelegate(m_personListItemDelegate);
90 if (m_headerListItemDelegate)
91 delete m_headerListItemDelegate;
92 m_headerListItemDelegate = new HeaderListItemDelegate(this);
95 void MeetPeoplePanel::listItemSelectionHandler()
97 qDebug() << __PRETTY_FUNCTION__;
99 PersonListItem *personItem = dynamic_cast<PersonListItem*>(m_personListView->selectedItem());
101 if (personItem && !personItem->isFriend())
102 m_friendListButton->setDisabled(true);
104 m_friendListButton->setEnabled(true);
106 onListItemSelectionChanged();
109 void MeetPeoplePanel::messageButtonPressed()
111 qDebug() << __PRETTY_FUNCTION__;
113 PersonListItem *personItem = dynamic_cast<PersonListItem*>(m_personListView->selectedItem());
116 m_personListView->clearItemSelection();
117 emit requestMessageDialog(QPair<QString, QString>(personItem->facebookId(),
118 personItem->title()));
122 void MeetPeoplePanel::setImage(const QString &id, const QPixmap &image)
124 qDebug() << __PRETTY_FUNCTION__;
126 PersonListItem *personItem = dynamic_cast<PersonListItem*>(m_personListView->listItem(id));
128 personItem->setAvatarImage(image);
131 void MeetPeoplePanel::showFriend()
133 qDebug() << __PRETTY_FUNCTION__;
135 PersonListItem *personItem = dynamic_cast<PersonListItem*>(m_personListView->selectedItem());
137 m_personListView->clearItemSelection();
138 QList<QString> userIds;
139 userIds.append(personItem->facebookId());
140 emit requestShowFriend(userIds);
144 void MeetPeoplePanel::populateInterestingPeopleListView(QList<User> &friends, QList<User> &others)
146 qDebug() << __PRETTY_FUNCTION__ ;
148 m_personListView->clearList();
151 if (friends.count() > 0) {
152 m_personListView->setItemDelegateForRow(0, m_headerListItemDelegate);
153 ExtendedListItem *friendsHeaderItem = new ExtendedListItem(0, QListWidgetItem::UserType);
154 friendsHeaderItem->setTitle(tr("Friends:"));
155 m_personListView->addListItem(QString("friendsHeader"), friendsHeaderItem);
157 foreach (User user, friends) {
158 PersonListItem *item = new PersonListItem();
159 item->setPersonData(user, true);
160 m_personListView->addListItem(user.userId(), item);
164 if (others.count() > 0) {
165 m_personListView->setItemDelegateForRow(m_personListView->count(),
166 m_headerListItemDelegate);
167 ExtendedListItem *othersHeaderItem = new ExtendedListItem(0, QListWidgetItem::UserType);
168 othersHeaderItem->setTitle(tr("Others:"));
169 m_personListView->addListItem(QString("othersHeader"), othersHeaderItem);
171 foreach (User user, others) {
172 PersonListItem *item = new PersonListItem();
173 item->setPersonData(user, false);
174 m_personListView->addListItem(user.userId(), item);
178 m_personListView->scrollToTop();