3d0e0cab1df4b68c5d48979b120085610ee04feb
[ptas] / zouba / uicontroller.cpp
1 #include "uicontroller.h"
2 #include "route.h"
3 #include "ui.h"
4 #include "ytv.h"
5 #include "location.h"
6 #include "messagetable.h"
7
8 #include <QObject>
9 #include <QTableWidgetItem>
10 #include <QPushButton>
11 #include <QDebug>
12 #include <QButtonGroup>
13
14 UiController::UiController( Ui *ui ) :
15   ui(ui)
16 {
17   Location *homeLocation = new Location();
18   Location *workLocation = new Location();
19
20   connect(
21       homeLocation, SIGNAL( becomeValid() ),
22       this, SLOT( setHomeButtonValid() )
23   );
24   connect(
25       workLocation, SIGNAL( becomeValid() ),
26       this, SLOT( setWorkButtonValid() )
27   );
28
29   homeLocation->resolveAddress( Ytv::Home );
30   workLocation->resolveAddress( Ytv::Work );
31
32   destination.append( homeLocation );
33   destination.append( workLocation );
34
35   connect(
36       ui->destinationButtons, SIGNAL( buttonClicked( int ) ),
37       this, SLOT( changeDestination( int ) )
38   );
39
40 }
41
42 UiController::~UiController()
43 {
44 }
45
46 void UiController::setHomeButtonValid()
47 {
48   setButtonValid( Ui::HomeButtonId );
49 }
50
51 void UiController::setWorkButtonValid()
52 {
53   setButtonValid( Ui::WorkButtonId );
54 }
55
56 void UiController::setButtonValid( int id )
57 {
58   ui->destinationButtons->button( id )->setEnabled(true);
59 }
60
61 void UiController::changeDestination( int id )
62 {
63   qDebug() << "Button "+QString::number(id)+" clicked";
64
65   bool destinationHasChanged = ( currentDestination != id );
66   if ( destinationHasChanged ) {
67     emit destinationChanged( *(destination[id]) );
68   }
69
70   // always want to emit this so that the gps position is update
71   // and the user gets new information
72   emit buttonClicked();
73 }
74
75 void UiController::displayRoute( const QList<RouteData> &routeData )
76 {
77   qDebug() << "displaying route";
78
79   ui->routeTable->setRowCount( routeData.count() );
80
81   for ( int i=0; i<routeData.count(); i++ ) {
82     QTableWidgetItem *timeItem = new QTableWidgetItem( routeData.at(i).arrivalTime );
83     ui->routeTable->setItem( i, 0, timeItem );
84
85     QTableWidgetItem *lineItem = new QTableWidgetItem( routeData.at(i).lineCode );
86     ui->routeTable->setItem( i, 1, lineItem );
87   }
88 }