2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Jussi Laitinen - jussi.laitinen@ixonos.com
7 Situare is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as published by the Free Software Foundation.
11 Situare is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Situare; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
26 #include "friendlistitem.h"
28 ListView::ListView(QWidget *parent)
29 : QListWidget(parent),
32 qDebug() << __PRETTY_FUNCTION__;
34 setAutoFillBackground(false);
35 viewport()->setAutoFillBackground(false);
37 connect(this, SIGNAL(itemClicked(QListWidgetItem*)),
38 this, SLOT(listItemClicked(QListWidgetItem*)));
41 void ListView::addListItem(const QString &key, ListItem *item)
43 qDebug() << __PRETTY_FUNCTION__;
45 if (!m_listItems.contains(key)) {
47 m_listItems.insert(key, item);
51 void ListView::addListItemToView(ListItem *item)
53 qDebug() << __PRETTY_FUNCTION__;
58 void ListView::clearList()
60 qDebug() << __PRETTY_FUNCTION__;
68 void ListView::clearUnused(const QStringList &userIDs)
70 qDebug() << __PRETTY_FUNCTION__;
72 foreach (QString key, m_listItems.keys()) {
73 if (!userIDs.contains(key)) {
74 ListItem *item = m_listItems.take(key);
83 void ListView::clearFilter()
85 qDebug() << __PRETTY_FUNCTION__;
88 m_previousItem->setSelected(false);
90 foreach (ListItem *item, m_listItems)
91 setItemHidden(item, false);
94 bool ListView::contains(const QString &userID)
96 qDebug() << __PRETTY_FUNCTION__;
98 return m_listItems.contains(userID);
101 void ListView::filter(const QList<QString> &userIDs)
103 qDebug() << __PRETTY_FUNCTION__;
105 foreach (ListItem *item, m_listItems) {
106 if (userIDs.contains(item->id()))
107 setItemHidden(item, false);
109 setItemHidden(item, true);
113 void ListView::filter(const QString &pattern)
115 qDebug() << __PRETTY_FUNCTION__;
117 foreach (ListItem *item, m_listItems) {
118 if (item->name().contains(pattern, Qt::CaseInsensitive))
119 setItemHidden(item, false);
121 setItemHidden(item, true);
125 ListItem *ListView::takeListItemFromView(const QString &userID)
127 qDebug() << __PRETTY_FUNCTION__;
129 ListItem *item = listItem(userID);
134 void ListView::listItemClicked(QListWidgetItem *item)
136 qDebug() << __PRETTY_FUNCTION__;
138 ListItem *currentItem = dynamic_cast<ListItem*>(item);
141 if (m_previousItem == currentItem) {
142 currentItem->toggleSelection();
146 m_previousItem->setSelected(false);
148 currentItem->setSelected(true);
151 m_previousItem = currentItem;
157 ListItem *ListView::listItem(const QString &userID)
159 qDebug() << __PRETTY_FUNCTION__;
161 return dynamic_cast<ListItem*>(m_listItems.value(userID));
165 ListView::~ListView()
167 qDebug() << __PRETTY_FUNCTION__;