Merge commit '0.0.2'
[vncallhistory] / listitemdetaildelegate.cc
1 /*
2 Copyright (C) 2011  by Cuong Le <metacuong@gmail.com>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>
16 */
17
18 #include "listitemdetaildelegate.h"
19
20 listitemdetailDelegate::listitemdetailDelegate(QObject*)
21 {
22 }
23
24 listitemdetailDelegate::~listitemdetailDelegate(){
25
26 }
27
28 void listitemdetailDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
29     QString header = index.data(Qt::DisplayRole).toString();
30
31     QRect r = option.rect;
32
33     if (!header.isNull()){
34         r.adjust(0,10,0,-10);
35         QLinearGradient gradientSelected(r.left(),r.top(),r.left(),r.height()+r.top());
36         gradientSelected.setColorAt(0.0, QColor::fromRgb(119,213,247));
37         gradientSelected.setColorAt(0.9, QColor::fromRgb(27,134,183));
38         gradientSelected.setColorAt(1.0, QColor::fromRgb(0,120,174));
39         painter->setBrush(gradientSelected);
40         painter->drawRect(r);
41
42         painter->setPen(Qt::blue);
43         painter->setFont(QFont("Nokia Sans", 18, QFont::Normal));
44         painter->drawText(r.left(), r.top(), r.width(), r.height(), Qt::AlignCenter, header, &r);
45     }else{
46         painter->setPen(Qt::white);
47         QString phone_number = index.data(Qt::UserRole + 1).toString();
48         QString start_end = index.data(Qt::UserRole + 2).toString();
49         QIcon icon_type =  QIcon(qvariant_cast<QIcon>(index.data(Qt::UserRole+4)));
50         QIcon icon_call_type =  QIcon(qvariant_cast<QIcon>(index.data(Qt::UserRole+5)));
51
52         painter->setFont(QFont("Nokia Sans", 16, QFont::Normal));
53         icon_type.paint(painter, r, Qt::AlignVCenter|Qt::AlignLeft);
54         icon_call_type.paint(painter, r, Qt::AlignVCenter|Qt::AlignRight);
55
56         r = option.rect.adjusted(55, 0, -10, -30);
57         painter->setFont(QFont("Nokia Sans", 18, QFont::Bold));
58         painter->drawText(r.left(), r.top(), r.width(), r.height(), Qt::AlignBottom|Qt::AlignLeft, phone_number, &r);
59
60         painter->setFont(QFont("Nokia Sans", 14, QFont::Normal));
61         r = option.rect.adjusted(55, 30, -10, -10);
62         painter->drawText(r.left(), r.top(), r.width(), r.height(), Qt::AlignBottom|Qt::AlignLeft, start_end, &r);
63     }
64 }
65
66 QSize listitemdetailDelegate::sizeHint(const QStyleOptionViewItem&, const QModelIndex&) const {
67     return QSize(200, 70);
68 }