Version 1.3.5
[someplayer] / src / trackrenderer.cpp
1 /*
2  * SomePlayer - An alternate music player for Maemo 5
3  * Copyright (C) 2010 Nikolay (somebody) Tischenko <niktischenko@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18  */
19
20 #include "trackrenderer.h"
21 #include <QFont>
22 #include <QFontMetrics>
23 #include <QSize>
24 #include <QColor>
25
26 TrackRenderer::TrackRenderer(QObject *parent) :
27     AbstractItemRenderer(parent)
28 {
29 }
30
31 void TrackRenderer::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
32         QString value = index.data().toString();
33         QStringList meta = value.split("#_#");
34
35         QFont f = painter->font();
36         QFont fp = painter->font();
37
38         int x1, y1, x2, y2;
39         option.rect.getCoords(&x1, &y1, &x2, &y2);
40
41         QPen pen = painter->pen();
42         QPen npen (QColor::fromRgb(80, 130, 255, 50));
43         QPen apen (QColor::fromRgb(255, 255, 255, 128));
44         QPen spen (QColor::fromRgb(100, 150, 220));
45         QPen sspen (QColor::fromRgb(100, 220, 150));
46
47         f.setBold(false);
48         painter->setPen(npen);
49         painter->drawLine(x1, y1, x2, y1);
50         if (index.row() == _search_row) {
51                 f.setBold(true);
52                 painter->setPen(sspen);
53         } else if (index.row() == _active_row) {
54                 f.setBold(true);
55                 painter->setPen(spen);
56         } else {
57                 painter->setPen(pen);
58         }
59         painter->setFont(f);
60         painter->drawText(x1+10, y1 + 1*(y2-y1)/2, meta[0]);
61         fp.setBold(false);
62         fp.setPointSize(f.pointSize()*3/4);
63         painter->setFont(fp);
64         painter->setPen(apen);
65         painter->drawText(x1+10, y1 + 3*(y2-y1)/5, (x2-x1)-100, 2*fp.pointSize(), Qt::AlignAbsolute, QString("%1 (%2)").arg(meta[2]).arg(meta[1]));
66         painter->drawText(x2-60, y1 + 3*(y2-y1)/5, 55, 2*fp.pointSize(), Qt::AlignAbsolute, QString("%1").arg(meta[3]));
67         painter->setPen(npen);
68         painter->drawLine(x1, y2, x2, y2);
69         painter->setFont(f);
70         painter->setPen(pen);
71 }
72
73 QSize TrackRenderer::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &/*index*/) const {
74         return QSize(option.rect.width(), 80);
75 }