Fixed searchclients to handle new Google URLs correctly; added GUI
[movie-schedule] / src / ui / theaterscheduledelegate.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 "theaterscheduledelegate.h"
19
20 #include "theaterschedulemodel.h"
21 #include "data/scheduleentry.h"
22 #include "data/movie.h"
23 #include "scheduleentryitem.h"
24 #include "utils/timeutils.h"
25 #include "ui/styleutils.h"
26
27 #include <QPainter>
28
29 TheaterScheduleDelegate::TheaterScheduleDelegate(QWidget *parent)
30     : QStyledItemDelegate(parent)
31 {
32 }
33
34 void TheaterScheduleDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
35                                     const QModelIndex &index) const
36 {
37     if (qVariantCanConvert<ScheduleEntryItem>(index.data())) {
38         ScheduleEntryItem item = qVariantValue<ScheduleEntryItem>(index.data());
39         painter->save();
40         painter->translate(option.rect.x(), option.rect.y());
41         QRect bounding_rect;
42         QFont bigfont(option.font);
43         bigfont.setPointSizeF(bigfont.pointSizeF() * 1.5);
44         painter->setFont(bigfont);
45         if (item.IsScheduleDateItem()) {
46             _day_painter.Paint(painter, option, item.GetScheduleDate());
47         } else {
48             painter->setPen(StyleUtils::INSTANCE()->GetScheduleTimeColor(option.palette, item.GetScheduleEntry()->GetStartTime()));
49             painter->drawText(0, 0, 1000, option.rect.height() - 4,
50                               Qt::AlignTop, TimeUtils::ToTimeString(item.GetScheduleEntry()->GetStartTime()), &bounding_rect);
51             int x = bounding_rect.right() + 8;
52             painter->translate(x, 0);
53             _movie_painter.Paint(painter, option, item.GetScheduleEntry()->GetMovie());
54         }
55         painter->restore();
56     } else {
57         QStyledItemDelegate::paint(painter, option, index);
58     }
59 }
60
61 QSize TheaterScheduleDelegate::sizeHint(const QStyleOptionViewItem &option,
62                                         const QModelIndex &index) const
63 {
64     if (qVariantCanConvert<ScheduleEntryItem>(index.data())) {
65         ScheduleEntryItem item = qVariantValue<ScheduleEntryItem>(index.data());
66         if (item.IsScheduleDateItem()) {
67             return _day_painter.GetSizeHint(option);
68         }
69         return _movie_painter.GetSizeHint(option);
70     } else {
71         return QStyledItemDelegate::sizeHint(option, index);
72     }
73 }