2 * SomePlayer - An alternate music player for Maemo 5
3 * Copyright (C) 2010 Nikolay (somebody) Tischenko <niktischenko@gmail.com>
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.
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.
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.
20 #include "trackrenderer.h"
22 #include <QFontMetrics>
25 #include <QStandardItem>
26 #include <QApplication>
27 #include <QDesktopWidget>
29 using namespace SomePlayer::Storage;
30 TrackRenderer::TrackRenderer(QObject *parent) :
31 AbstractItemRenderer(parent)
34 _icons_theme = config.getValue("ui/iconstheme").toString();
35 _apen = QPen(QColor::fromRgb(255, 255, 255, 128));
36 _spen = QPen(QColor::fromRgb(100, 150, 220));
37 _sspen = QPen(QColor::fromRgb(100, 220, 150));
41 void TrackRenderer::updateIcons() {
43 _icons_theme = config.getValue("ui/iconstheme").toString();
46 void TrackRenderer::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
47 QString value = index.data().toString();
48 if (value.startsWith("##")) {
51 option.rect.getCoords(&x1, &y1, &x2, &y2);
52 QImage image(":/icons/"+_icons_theme+"/"+value);
53 x1 += (x2 - x1 - image.width())/2;
54 y1 += (y2 - y1 - image.width())/2;
55 painter->drawImage(x1, y1, image);
57 QStringList meta = value.split("#_#");
59 QFont f = painter->font();
60 QFont fp = painter->font();
63 option.rect.getCoords(&x1, &y1, &x2, &y2);
65 QPen pen = painter->pen();
67 if (index.row() == _search_row) {
69 painter->setPen(_sspen);
70 } else if (index.row() == _active_row) {
72 painter->setPen(_spen);
77 painter->drawText(x1+10, y1 + 1*(y2-y1)/2, meta[0]);
79 fp.setPointSize(f.pointSize()*3/4);
81 painter->setPen(_apen);
82 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]));
83 painter->drawText(x2-60, y1 + 3*(y2-y1)/5, 55, 2*fp.pointSize(), Qt::AlignAbsolute, QString("%1").arg(meta[3]));
89 QSize TrackRenderer::sizeHint(const QStyleOptionViewItem &/*option*/, const QModelIndex &/*index*/) const {
90 return QSize(QApplication::desktop()->geometry().width(), 80);
93 void TrackRenderer::setActiveTrackColor(QString color) {
95 if (color == "blue") {
96 c = QColor::fromRgb(100, 150, 220);
97 } else if (color == "black") {
98 c = QColor::fromRgb(0, 0, 0);
99 } else if (color == "magenta") {
100 c = QColor::fromRgb(150, 80, 150);
101 } else if (color == "red") {
102 c = QColor::fromRgb(220, 100, 100);
103 } else if (color == "yellow") {
104 c = QColor::fromRgb(220, 220, 100);
105 } else if (color == "white") {
106 c = QColor::fromRgb(255, 255, 255);
107 } else if (color == "dark") {
108 c = QColor::fromRgb(70, 70, 70);
109 } else if (color == "light") {
110 c = QColor::fromRgb(200, 200, 200);