Minor fix for another change in Google's movie pages and a fix in
[movie-schedule] / src / ui / cinemapainter.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 "cinemapainter.h"
19
20 #include "data/cinema.h"
21 #include "ui/styleutils.h"
22
23 #include <QPainter>
24 #include <QStyleOptionViewItem>
25
26 CinemaPainter::CinemaPainter()
27 {
28 }
29
30 void CinemaPainter::Paint(QPainter *painter, const QStyleOptionViewItem &option, const Cinema *cinema) const
31 {
32     painter->setFont(option.font);
33     painter->setPen(StyleUtils::INSTANCE()->GetColor(option.palette, StyleUtils::DefaultTextColor));
34     painter->drawText(0, painter->fontMetrics().ascent(), cinema->GetName());
35     int y = painter->fontMetrics().height() + 2;
36     QRect bounding_rect;
37     painter->setPen(StyleUtils::INSTANCE()->GetColor(option.palette, StyleUtils::SecondaryTextColor));
38     bool drawn = false;
39     if (!cinema->GetAddress().isEmpty()) {
40         QFont font2(option.font);
41         font2.setPointSizeF(font2.pointSizeF() * 0.7);
42         painter->setFont(font2);
43         painter->drawText(0, y, 1000, painter->fontMetrics().height(),
44                           0, cinema->GetAddress(), &bounding_rect);
45         drawn = true;
46     }
47     if (!cinema->GetTelephone().isEmpty()) {
48         painter->drawText(bounding_rect.right(), y, 1000, painter->fontMetrics().height(),
49                           0, QString((drawn ? ", %1" : "%1")).arg(cinema->GetTelephone()), &bounding_rect);
50     }
51 }
52
53 QSize CinemaPainter::GetSizeHint(const QStyleOptionViewItem &option) const
54 {
55     return QSize(0, option.fontMetrics.height() + 2 + option.fontMetrics.height() * 0.7 + 4);
56 }