Sorted includes alphabetically.
[situare] / src / ui / listitem.cpp
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5        Jussi Laitinen - jussi.laitinen@ixonos.com
6
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.
10
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.
15
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,
19    USA.
20 */
21
22 #include <QDebug>
23 #include <QPainter>
24
25 #include "../common.h"
26 #include "listcommon.h"
27
28 #include "listitem.h"
29
30 ListItem::ListItem()
31 {
32     qDebug() << __PRETTY_FUNCTION__;
33
34     setSize(QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
35 }
36
37 QString ListItem::name() const
38 {
39     qDebug() << __PRETTY_FUNCTION__;
40
41     return data(NAME_DISPLAY_INDEX).toString();
42 }
43
44 void ListItem::setImage(const QPixmap &image)
45 {
46     qDebug() << __PRETTY_FUNCTION__;
47
48     setData(ITEM_HAS_IMAGE_INDEX, true);
49     setData(AVATAR_IMAGE_INDEX, image);
50
51 }
52
53 void ListItem::setName(const QString &name)
54 {
55     qDebug() << __PRETTY_FUNCTION__;
56
57     setData(NAME_DISPLAY_INDEX, name);
58 }
59
60 void ListItem::setSize(const QSize &size)
61 {
62     qDebug() << __PRETTY_FUNCTION__;
63
64     setData(ITEM_SIZE_HINT_INDEX, size);
65 }
66
67 QString ListItem::shortenText(const QString &text, int textWidth, TextSize textSize)
68 {
69     qDebug() << __PRETTY_FUNCTION__;
70
71     QPixmap p = QPixmap(ICON_WIDTH, ICON_HEIGHT);
72     QPainter painter(&p);
73
74     if (textSize == ListItem::TEXT_SIZE_NORMAL)
75         painter.setFont(NOKIA_FONT_NORMAL);
76     else
77         painter.setFont(NOKIA_FONT_SMALL);
78
79     QFontMetrics textMetrics = painter.fontMetrics();
80
81     QString shortenedText = text;
82
83     int index = shortenedText.indexOf('\n');
84
85     if (index > 0) {
86         shortenedText.truncate(index);
87         shortenedText.append("...");
88     }
89
90     return textMetrics.elidedText(shortenedText, Qt::ElideRight, textWidth);
91 }