18aa89c31ca7445ddd489adaf0eebedbbd4d8e8c
[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 #include <QStandardItem>
26 #include <QApplication>
27 #include <QDesktopWidget>
28
29 using namespace SomePlayer::Storage;
30 TrackRenderer::TrackRenderer(QObject *parent) :
31     AbstractItemRenderer(parent)
32 {
33         Config config;
34         _icons_theme = config.getValue("ui/iconstheme").toString();
35 }
36
37 void TrackRenderer::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
38         if (index.column() == 0) {
39                 int x1, y1, x2, y2;
40                 option.rect.getCoords(&x1, &y1, &x2, &y2);
41                 painter->drawImage(x1, y1 + 5, QImage(":/icons/"+_icons_theme+"/more_l.png"));
42         } else {
43                 QString value = index.data().toString();
44                 QStringList meta = value.split("#_#");
45
46                 QFont f = painter->font();
47                 QFont fp = painter->font();
48
49                 int x1, y1, x2, y2;
50                 option.rect.getCoords(&x1, &y1, &x2, &y2);
51
52                 QPen pen = painter->pen();
53                 QPen npen (QColor::fromRgb(80, 130, 255, 50));
54                 QPen apen (QColor::fromRgb(255, 255, 255, 128));
55                 QPen spen (QColor::fromRgb(100, 150, 220));
56                 QPen sspen (QColor::fromRgb(100, 220, 150));
57
58                 f.setBold(false);
59                 painter->setPen(npen);
60                 painter->drawLine(x1, y1, x2, y1);
61                 if (index.row() == _search_row) {
62                         f.setBold(true);
63                         painter->setPen(sspen);
64                 } else if (index.row() == _active_row) {
65                         f.setBold(true);
66                         painter->setPen(spen);
67                 } else {
68                         painter->setPen(pen);
69                 }
70                 painter->setFont(f);
71                 painter->drawText(x1+10, y1 + 1*(y2-y1)/2, meta[0]);
72                 fp.setBold(false);
73                 fp.setPointSize(f.pointSize()*3/4);
74                 painter->setFont(fp);
75                 painter->setPen(apen);
76                 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]));
77                 painter->drawText(x2-60, y1 + 3*(y2-y1)/5, 55, 2*fp.pointSize(), Qt::AlignAbsolute, QString("%1").arg(meta[3]));
78                 painter->setPen(npen);
79                 painter->drawLine(x1, y2, x2, y2);
80                 painter->setFont(f);
81                 painter->setPen(pen);
82         }
83 }
84
85 QSize TrackRenderer::sizeHint(const QStyleOptionViewItem &/*option*/, const QModelIndex &/*index*/) const {
86         return QSize(QApplication::desktop()->geometry().width(), 80);
87 }