Initial commit (software version 0.2.0)
[movie-schedule] / src / ui / moviewindow.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 "moviewindow.h"
19 #include "ui_moviewindow.h"
20
21 #include "moviescheduledelegate.h"
22 #include "movieschedulemodel.h"
23 #include "data/cinemaschedule.h"
24
25 #include <QStackedLayout>
26 #ifdef Q_WS_MAEMO_5
27 #include <QAbstractKineticScroller>
28 #endif
29
30 MovieWindow::MovieWindow(CinemaSchedule *cinema_schedule, QWidget *parent) :
31     AbstractMainWindow(parent),
32     ui(new Ui::MovieWindow),
33     _cinema_schedule(cinema_schedule),
34     _movie_schedule_model(0)
35 {
36     ui->setupUi(this);
37 #ifdef Q_WS_MAEMO_5
38     setAttribute(Qt::WA_Maemo5StackedWindow);
39 #endif
40     QStackedLayout *layout = dynamic_cast<QStackedLayout*>(ui->MainStack->layout());
41     if (layout != 0) {
42         layout->setStackingMode(QStackedLayout::StackAll);
43     }
44     QFont f(font());
45     f.setPointSizeF(f.pointSizeF() * 1.5);
46     ui->ErrorMessage->setFont(f);
47     ui->Schedule->setItemDelegate(new MovieScheduleDelegate(this));
48     ui->Schedule->setProperty("FingerScrollable", true);
49     connect(ui->Schedule, SIGNAL(clicked(QModelIndex)), this, SLOT(ScheduleEntrySelected(QModelIndex)));
50 }
51
52 MovieWindow::~MovieWindow()
53 {
54     delete ui;
55 }
56
57 void MovieWindow::SetMovieName(QString movie_name)
58 {
59     ui->Background->SetLabelText(movie_name);
60 }
61
62 void MovieWindow::SetMovieScheduleModel(QAbstractItemModel *movie_schedule_model)
63 {
64     _movie_schedule_model = movie_schedule_model;
65     ui->MoviePages->setCurrentWidget(ui->MoviePage);
66     ui->Schedule->setModel(_movie_schedule_model);
67 }
68
69 void MovieWindow::SetError(QString error_text)
70 {
71     ui->MoviePages->setCurrentWidget(ui->ErrorPage);
72     ui->ErrorMessage->setText(error_text);
73 }
74
75 bool MovieWindow::IsIdle()
76 {
77 #ifdef Q_WS_MAEMO_5
78     QAbstractKineticScroller *k1 = ui->Schedule->property("kineticScroller").value<QAbstractKineticScroller *>();
79     bool k1_idle = (k1 == 0) || (k1->state() == QAbstractKineticScroller::Inactive);
80     return k1_idle;
81 #else
82     return true;
83 #endif
84 }
85
86 void MovieWindow::changeEvent(QEvent *e)
87 {
88     QMainWindow::changeEvent(e);
89     switch (e->type()) {
90     case QEvent::LanguageChange:
91         ui->retranslateUi(this);
92         break;
93     default:
94         break;
95     }
96 }
97
98 void MovieWindow::ScheduleEntrySelected(QModelIndex index)
99 {
100     QVariant var = _movie_schedule_model->data(index, MovieScheduleModel::MovieScheduleKeyRole);
101     ScheduleEntryKey schedule_entry_key = qVariantValue<ScheduleEntryKey>(var);
102     emit ScheduleEntrySelected(schedule_entry_key);
103 }