1 #include "uicontroller.h"
6 #include "messagetable.h"
10 #include <QTableWidgetItem>
11 #include <QPushButton>
13 #include <QButtonGroup>
15 UiController::UiController( Ui *ui ) :
18 Locations *locations = Locations::instance();
19 Location *homeLocation = locations->location( "home" );
20 Location *workLocation = locations->location( "work" );
23 homeLocation, SIGNAL( becomeValid() ),
24 this, SLOT( setHomeButtonValid() )
27 homeLocation, SIGNAL( becomeValid() ),
28 locations, SLOT( saveLocation() )
32 workLocation, SIGNAL( becomeValid() ),
33 this, SLOT( setWorkButtonValid() )
36 workLocation, SIGNAL( becomeValid() ),
37 locations, SLOT( saveLocation() )
40 homeLocation->resolveAddress( Ytv::Home );
41 workLocation->resolveAddress( Ytv::Work );
43 destination.append( homeLocation );
44 destination.append( workLocation );
47 ui->destinationButtons, SIGNAL( buttonClicked( int ) ),
48 this, SLOT( changeDestination( int ) )
52 UiController::~UiController()
56 void UiController::setHomeButtonValid()
58 qDebug() << "setting home button valid";
59 setButtonValid( Ui::HomeButtonId );
62 void UiController::setWorkButtonValid()
64 setButtonValid( Ui::WorkButtonId );
67 void UiController::setButtonValid( int id )
69 ui->destinationButtons->button( id )->setEnabled(true);
72 void UiController::changeDestination( int id )
74 qDebug() << "Button "+QString::number(id)+" clicked";
76 bool destinationHasChanged = ( currentDestination != id );
77 if ( destinationHasChanged ) {
78 emit destinationChanged( destination[id] );
81 // always want to emit this so that the gps position is update
82 // and the user gets new information
86 void UiController::displayRoute( const QList<RouteData> &routeData )
88 qDebug() << "displaying route";
90 ui->routeTable->setRowCount( routeData.count() );
92 for ( int i=0; i<routeData.count(); i++ ) {
93 QTableWidgetItem *timeItem = new QTableWidgetItem( routeData.at(i).arrivalTime );
94 ui->routeTable->setItem( i, 0, timeItem );
96 QTableWidgetItem *lineItem = new QTableWidgetItem( routeData.at(i).lineCode );
97 ui->routeTable->setItem( i, 1, lineItem );