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 "extendedlistitemstore.h"
28 #include "listcommon.h"
30 #include "extendedlistitem.h"
32 ExtendedListItem::ExtendedListItem()
34 m_expandedHeight(ITEM_MIN_HEIGHT),
35 m_normalHeight(ITEM_MIN_HEIGHT),
39 qDebug() << __PRETTY_FUNCTION__;
41 setSize(QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
43 m_subItemStoreList = new QList<ExtendedListItemStore *>();
44 setData(SUBITEM_STORE_INDEX, qVariantFromValue((void *) m_subItemStoreList));
47 void ExtendedListItem::addSubItem(const QString &text, const QPixmap &icon)
49 qDebug() << __PRETTY_FUNCTION__;
51 ExtendedListItemStore *itemStore = new ExtendedListItemStore(text);
52 itemStore->setIcon(icon);
53 itemStore->setShortenedText(shortenText(text, m_subItemTextWidth, ListItem::TEXT_SIZE_SMALL));
54 itemStore->setTextRect(calculateExpandedTextRect(text));
56 m_subItemStoreList->append(itemStore);
59 QRect ExtendedListItem::boundingRect(const QString &text)
61 qDebug() << __PRETTY_FUNCTION__;
63 QPixmap p = QPixmap(ICON_WIDTH, ICON_HEIGHT);
65 painter.setFont(NOKIA_FONT_SMALL);
67 QFontMetrics textMetrics = painter.fontMetrics();
69 QStringList rows = text.split('\n');
71 foreach (QString row, rows) {
73 QRect textRowRect = textMetrics.boundingRect(row);
75 if (textRowRect.width() > textRect.width())
76 textRect.setWidth(textRowRect.width());
78 textRect.setHeight(textRect.height() + textRowRect.height());
84 void ExtendedListItem::clearSubItems()
86 qDebug() << __PRETTY_FUNCTION__;
88 qDeleteAll(m_subItemStoreList->begin(), m_subItemStoreList->end());
89 m_subItemStoreList->clear();
91 m_expandedHeight = ITEM_MIN_HEIGHT;
92 m_normalHeight = ITEM_MIN_HEIGHT;
95 QRect ExtendedListItem::calculateExpandedTextRect(const QString &text)
97 qDebug() << __PRETTY_FUNCTION__;
99 const int TEXT_BOTTOM_MARGIN = 2;
101 QRect textRect = boundingRect(text);
103 int textRectFactor = textRect.width() / m_subItemTextWidth;
104 textRectFactor += textRect.height() / SUBITEM_TEXT_ROW_HEIGHT;
106 QRect expandedTextRect = QRect(0, 0, m_subItemTextWidth, SUBITEM_TEXT_ROW_HEIGHT
109 m_normalHeight += SUBITEM_TEXT_ROW_HEIGHT + TEXT_BOTTOM_MARGIN;
110 m_expandedHeight += expandedTextRect.height() + TEXT_BOTTOM_MARGIN;
111 setSize(QSize(ITEM_WIDTH, m_normalHeight));
113 return expandedTextRect;
116 void ExtendedListItem::setSubitemTextWidth(int width)
118 qDebug() << __PRETTY_FUNCTION__;
120 m_subItemTextWidth = width;
123 bool ExtendedListItem::toggleSelection()
125 qDebug() << __PRETTY_FUNCTION__;
127 setSelected(!m_selected);
131 void ExtendedListItem::setSelected(bool selected)
133 qDebug() << __PRETTY_FUNCTION__;
135 m_selected = selected;
136 setData(ITEM_EXPANDED_INDEX, m_selected);
139 setData(ITEM_SIZE_HINT_INDEX, QSize(ITEM_WIDTH, m_expandedHeight));
141 setData(ITEM_SIZE_HINT_INDEX, QSize(ITEM_WIDTH, m_normalHeight));
144 ExtendedListItem::~ExtendedListItem()
146 qDebug() << __PRETTY_FUNCTION__;
149 delete m_subItemStoreList;