Fixed searchclients to handle new Google URLs correctly; added GUI
[movie-schedule] / src / ui / moviepainter.cpp
1 // Copyright 2010 Jochen Becher
2 //
3 // This file is part of MovieSchedule.
4 //
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.
9 //
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.
14 //
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/>.
17
18 #include "moviepainter.h"
19
20 #include "data/movie.h"
21 #include "ratingprovider.h"
22 #include "ui/styleutils.h"
23
24 #include <QPainter>
25 #include <QStyleOptionViewItem>
26
27 MoviePainter::MoviePainter()
28     : _rating_height(RatingProvider::INSTANCE()->GetRating(0.0).height())
29 {
30 }
31
32 void MoviePainter::Paint(QPainter *painter, const QStyleOptionViewItem &option,
33                          const Movie *movie) const
34 {
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) {
41         h = _rating_height;
42     }
43     painter->setPen(StyleUtils::INSTANCE()->GetColor(option.palette, StyleUtils::SecondaryTextColor));
44     QRect bounding_rect;
45     bool drawn = false;
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);
53         drawn = true;
54     }
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);
61         drawn = true;
62     }
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);
66         drawn = true;
67     }
68 }
69
70 QSize MoviePainter::GetSizeHint(const QStyleOptionViewItem &option) const
71 {
72     int y0 = option.fontMetrics.height();
73     int y1 = option.fontMetrics.height() * 0.7;
74     if (_rating_height > y1) {
75         y1 = _rating_height;
76     }
77     return QSize(0, y0 + 2 + y1 + 4);
78 }