Fixed searchclients to handle new Google URLs correctly; added GUI
[movie-schedule] / src / ui / theaterwindow.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 "theaterwindow.h"
19 #include "ui_theaterwindow.h"
20
21 #include "theaterscheduledelegate.h"
22 #include "theaterschedulemodel.h"
23 #include "data/cinemaschedule.h"
24
25 #include <QStackedLayout>
26 #ifdef Q_WS_MAEMO_5
27 #include <QAbstractKineticScroller>
28 #endif
29
30 TheaterWindow::TheaterWindow(CinemaSchedule *cinema_schedule, QWidget *parent) :
31     AbstractMainWindow(parent),
32     ui(new Ui::TheaterWindow),
33     _cinema_schedule(cinema_schedule),
34     _theater_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 TheaterScheduleDelegate(this));
48     ui->Schedule->setProperty("FingerScrollable", true);
49     connect(ui->Schedule, SIGNAL(clicked(QModelIndex)), this, SLOT(ScheduleEntrySelected(QModelIndex)));
50 }
51
52 TheaterWindow::~TheaterWindow()
53 {
54     delete ui;
55 }
56
57 void TheaterWindow::SetTheaterName(QString movie_name)
58 {
59     ui->Background->SetLabelText(movie_name);
60 }
61
62 void TheaterWindow::SetTheaterScheduleModel(QAbstractItemModel *theater_schedule_model)
63 {
64     _theater_schedule_model = theater_schedule_model;
65     ui->TheaterPages->setCurrentWidget(ui->TheaterPage);
66     ui->Schedule->setModel(_theater_schedule_model);
67 }
68
69 void TheaterWindow::SetError(QString error_text)
70 {
71     ui->TheaterPages->setCurrentWidget(ui->ErrorPage);
72     ui->ErrorMessage->setText(error_text);
73 }
74
75 bool TheaterWindow::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 TheaterWindow::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 TheaterWindow::ScheduleEntrySelected(QModelIndex index)
99 {
100     QVariant var = _theater_schedule_model->data(index, TheaterScheduleModel::TheaterScheduleKeyRole);
101     ScheduleEntryKey schedule_entry_key = qVariantValue<ScheduleEntryKey>(var);
102     emit ScheduleEntrySelected(schedule_entry_key);
103 }