1 // Copyright 2010 Jochen Becher
3 // This file is part of MovieSchedule.
5 // MovieSchedule is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // MovieSchedule 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 MovieSchedule. If not, see <http://www.gnu.org/licenses/>.
18 #include "moviepainter.h"
20 #include "data/movie.h"
21 #include "ratingprovider.h"
22 #include "ui/styleutils.h"
25 #include <QStyleOptionViewItem>
27 MoviePainter::MoviePainter()
28 : _rating_height(RatingProvider::INSTANCE()->GetRating(0.0).height())
32 void MoviePainter::Paint(QPainter *painter, const QStyleOptionViewItem &option,
33 const Movie *movie) const
35 painter->setFont(option.font);
36 painter->setPen(StyleUtils::INSTANCE()->GetColor(option.palette, StyleUtils::DefaultTextColor));
37 painter->drawText(0, painter->fontMetrics().ascent(), movie->GetName());
38 int y = painter->fontMetrics().height() + 2;
39 int h = option.font.pointSizeF() * 0.7;
40 if (_rating_height > h) {
43 painter->setPen(StyleUtils::INSTANCE()->GetColor(option.palette, StyleUtils::SecondaryTextColor));
46 if (movie->GetDuration().isValid()) {
47 QFont font2(option.font);
48 font2.setPointSizeF(font2.pointSizeF() * 0.7);
49 painter->setFont(font2);
50 int minutes = movie->GetDuration().hour() * 60 + movie->GetDuration().minute();
51 painter->drawText(0, y, 1000, painter->fontMetrics().height(),
52 0 /* Qt::AlignBottom */, QString(QObject::tr("%1min", "movie duration")).arg(minutes), &bounding_rect);
55 if (!movie->GetComment().isEmpty()) {
56 QFont font2(option.font);
57 font2.setPointSizeF(font2.pointSizeF() * 0.7);
58 painter->setFont(font2);
59 painter->drawText(bounding_rect.right(), y, 1000, painter->fontMetrics().height(),
60 0 /* Qt::AlignBottom */, QString(drawn ? ", %1" : "%1").arg(movie->GetComment()), &bounding_rect);
63 if (movie->GetRate() >= 0.0) {
64 QPixmap p = RatingProvider::INSTANCE()->GetRating(movie->GetRate());
65 painter->drawPixmap(bounding_rect.right() + (drawn ? 8 : 0), y + h - p.height(), p);
70 QSize MoviePainter::GetSizeHint(const QStyleOptionViewItem &option) const
72 int y0 = option.fontMetrics.height();
73 int y1 = option.fontMetrics.height() * 0.7;
74 if (_rating_height > y1) {
77 return QSize(0, y0 + 2 + y1 + 4);