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,
23 #include <QFontMetrics>
26 #include "../common.h"
27 #include "listcommon.h"
28 #include "extendedlistitemstore.h"
30 #include "extendedlistitem.h"
32 const int SUBITEM_TEXT_ROW_HEIGHT = ICON_HEIGHT; ///< Sub item text row height
34 ExtendedListItem::ExtendedListItem()
36 m_expandedHeight(ITEM_MIN_HEIGHT),
37 m_normalHeight(ITEM_MIN_HEIGHT),
41 qDebug() << __PRETTY_FUNCTION__;
43 setSize(QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
45 m_subItemStoreList = new QList<ExtendedListItemStore *>();
46 setData(SUBITEM_STORE_INDEX, qVariantFromValue((void *) m_subItemStoreList));
49 void ExtendedListItem::addSubItem(const QString &text, const QPixmap &icon)
51 qDebug() << __PRETTY_FUNCTION__;
53 ExtendedListItemStore *itemStore = new ExtendedListItemStore(text);
54 itemStore->setIcon(icon);
55 itemStore->setShortenedText(shortenText(text, m_subItemTextWidth, ListItem::TEXT_SIZE_SMALL));
56 itemStore->setTextRect(calculateExpandedTextRect(text));
58 m_subItemStoreList->append(itemStore);
61 void ExtendedListItem::clearSubItems()
63 qDebug() << __PRETTY_FUNCTION__;
65 qDeleteAll(m_subItemStoreList->begin(), m_subItemStoreList->end());
66 m_subItemStoreList->clear();
68 m_expandedHeight = ITEM_MIN_HEIGHT;
69 m_normalHeight = ITEM_MIN_HEIGHT;
72 QRect ExtendedListItem::calculateExpandedTextRect(const QString &text)
74 qDebug() << __PRETTY_FUNCTION__;
76 QPixmap p = QPixmap(ICON_WIDTH, ICON_HEIGHT);
78 painter.setFont(NOKIA_FONT_SMALL);
79 QFontMetrics textMetrics = painter.fontMetrics();
81 QRect textRect = textMetrics.boundingRect(text);
82 int textRectFactor = textRect.width() / m_subItemTextWidth;
84 QRect expandedTextRect = QRect(0, 0, m_subItemTextWidth, SUBITEM_TEXT_ROW_HEIGHT
87 m_normalHeight += SUBITEM_TEXT_ROW_HEIGHT;
88 m_expandedHeight += expandedTextRect.height();
89 setSize(QSize(ITEM_WIDTH, m_normalHeight));
91 return expandedTextRect;
94 void ExtendedListItem::setSubitemTextWidth(int width)
96 qDebug() << __PRETTY_FUNCTION__;
98 m_subItemTextWidth = width;
101 bool ExtendedListItem::toggleSelection()
103 qDebug() << __PRETTY_FUNCTION__;
105 setSelected(!m_selected);
109 void ExtendedListItem::setSelected(bool selected)
111 qDebug() << __PRETTY_FUNCTION__;
113 m_selected = selected;
114 setData(ITEM_EXPANDED_INDEX, m_selected);
117 setData(ITEM_SIZE_HINT_INDEX, QSize(ITEM_WIDTH, m_expandedHeight));
119 setData(ITEM_SIZE_HINT_INDEX, QSize(ITEM_WIDTH, m_normalHeight));
122 ExtendedListItem::~ExtendedListItem()
124 qDebug() << __PRETTY_FUNCTION__;
127 delete m_subItemStoreList;