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 "moviescheduledelegate.h"
20 #include "movieschedulemodel.h"
21 #include "data/scheduleentry.h"
22 #include "data/cinema.h"
23 #include "scheduleentryitem.h"
24 #include "utils/timeutils.h"
25 #include "ui/styleutils.h"
29 MovieScheduleDelegate::MovieScheduleDelegate(QWidget *parent)
30 : QStyledItemDelegate(parent)
34 void MovieScheduleDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
35 const QModelIndex &index) const
37 if (qVariantCanConvert<ScheduleEntryItem>(index.data())) {
38 ScheduleEntryItem item = qVariantValue<ScheduleEntryItem>(index.data());
40 painter->translate(option.rect.x(), option.rect.y());
41 if (item.IsScheduleDateItem()) {
42 _day_painter.Paint(painter, option, item.GetScheduleDate());
45 QFont bigfont(option.font);
46 bigfont.setPointSizeF(bigfont.pointSizeF() * 1.5);
47 painter->setFont(bigfont);
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 _cinema_painter.Paint(painter, option, item.GetScheduleEntry()->GetCinema());
57 QStyledItemDelegate::paint(painter, option, index);
61 QSize MovieScheduleDelegate::sizeHint(const QStyleOptionViewItem &option,
62 const QModelIndex &index) const
64 if (qVariantCanConvert<ScheduleEntryItem>(index.data())) {
65 ScheduleEntryItem item = qVariantValue<ScheduleEntryItem>(index.data());
66 if (item.IsScheduleDateItem()) {
67 return _day_painter.GetSizeHint(option);
69 return _cinema_painter.GetSizeHint(option);
71 return QStyledItemDelegate::sizeHint(option, index);