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 setSelectionMode(QAbstractItemView::SingleSelection);
35 setAutoFillBackground(false);
36 viewport()->setAutoFillBackground(false);
38 connect(this, SIGNAL(itemClicked(QListWidgetItem*)),
39 this, SLOT(listItemClicked(QListWidgetItem*)));
42 void ListView::addListItem(const QString &key, ListItem *item)
44 qDebug() << __PRETTY_FUNCTION__;
46 if (!m_listItems.contains(key)) {
48 m_listItems.insert(key, item);
52 void ListView::addListItemToView(ListItem *item)
54 qDebug() << __PRETTY_FUNCTION__;
59 void ListView::clearItemSelection()
61 qDebug() << __PRETTY_FUNCTION__;
66 m_currentItem->setSelected(false);
68 emit listItemSelectionChanged();
71 void ListView::clearList()
73 qDebug() << __PRETTY_FUNCTION__;
77 qDeleteAll(m_listItems.begin(), m_listItems.end());
84 void ListView::clearUnused(const QStringList &itemIDs)
86 qDebug() << __PRETTY_FUNCTION__;
88 foreach (QString key, m_listItems.keys()) {
89 if (!itemIDs.contains(key)) {
90 ListItem *item = m_listItems.take(key);
93 if (m_currentItem == item)
101 void ListView::clearFilter()
103 qDebug() << __PRETTY_FUNCTION__;
105 m_filteredItemIDs.clear();
107 foreach (ListItem *item, m_listItems)
108 setItemHidden(item, false);
111 bool ListView::contains(const QString &itemID)
113 qDebug() << __PRETTY_FUNCTION__;
115 return m_listItems.contains(itemID);
118 void ListView::filter(const QList<QString> &itemIDs)
120 qDebug() << __PRETTY_FUNCTION__;
122 m_filteredItemIDs = itemIDs;
124 foreach (ListItem *item, m_listItems) {
125 if (itemIDs.contains(m_listItems.key(item))) {
126 item->setHidden(false);
128 item->setSelected(false);
129 item->setHidden(true);
133 emit listItemSelectionChanged();
136 void ListView::filter(const QString &pattern)
138 qDebug() << __PRETTY_FUNCTION__;
140 if (m_filteredItemIDs.isEmpty()) {
141 foreach (ListItem *item, m_listItems) {
142 if (item->title().contains(pattern, Qt::CaseInsensitive)) {
143 item->setHidden(false);
145 item->setSelected(false);
146 item->setHidden(true);
150 foreach (QString key, m_filteredItemIDs) {
151 ListItem *item = m_listItems.value(key);
153 if (item->title().contains(pattern, Qt::CaseInsensitive)) {
154 item->setHidden(false);
156 item->setSelected(false);
157 item->setHidden(true);
163 emit listItemSelectionChanged();
166 ListItem *ListView::takeListItemFromView(const QString &itemID)
168 qDebug() << __PRETTY_FUNCTION__;
170 ListItem *item = listItem(itemID);
175 bool ListView::listItemClicked(ListItem *clickedItem)
177 qDebug() << __PRETTY_FUNCTION__;
179 if (m_currentItem == clickedItem) {
180 clickedItem->toggleSelection();
183 m_currentItem->setSelected(false);
185 clickedItem->setSelected(true);
187 m_currentItem = clickedItem;
189 emit listItemSelectionChanged();
191 return clickedItem->isSelected();
194 void ListView::listItemClicked(QListWidgetItem *item)
196 qDebug() << __PRETTY_FUNCTION__;
198 ListItem *currentItem = dynamic_cast<ListItem*>(item);
201 listItemClicked(currentItem);
204 ListItem *ListView::listItem(const QString &itemID)
206 qDebug() << __PRETTY_FUNCTION__;
208 return dynamic_cast<ListItem*>(m_listItems.value(itemID));
211 ListItem *ListView::listItemAt(int index)
213 qDebug() << __PRETTY_FUNCTION__;
215 ListItem *listItem = 0;
218 listItem = dynamic_cast<ListItem*>(item(index));
223 void ListView::prependListItem(const QString &key, ListItem *item)
225 qDebug() << __PRETTY_FUNCTION__;
227 if (!m_listItems.contains(key)) {
229 m_listItems.insert(key, item);
233 void ListView::removeLastItem()
235 qDebug() << __PRETTY_FUNCTION__;
237 ListItem *item = listItemAt(count() - 1);
241 QString key = m_listItems.key(item);
242 m_listItems.remove(key);
244 if (m_currentItem == item)
252 ListItem *ListView::selectedItem()
254 qDebug() << __PRETTY_FUNCTION__;
256 QList<QListWidgetItem *> selectedListItems = selectedItems();
258 if (!selectedListItems.isEmpty())
259 return dynamic_cast<ListItem *>(selectedListItems.first());
264 void ListView::setSelectedItem(ListItem *item)
266 qDebug() << __PRETTY_FUNCTION__;
268 listItemClicked(item);
271 ListView::~ListView()
273 qDebug() << __PRETTY_FUNCTION__;