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