1 #include "uicontroller.h"
6 #include "messagetable.h"
10 #include <QPushButton>
12 #include <QButtonGroup>
13 #include <QRadioButton>
14 #include <QVBoxLayout>
16 UiController::UiController( Ui *ui ) :
19 Locations *locations = Locations::instance();
20 Location *homeLocation = locations->location( "home" );
21 Location *workLocation = locations->location( "work" );
23 if ( homeLocation==0 ) {
24 homeLocation = new Location( "home" );
25 locations->addLocation( homeLocation );
26 } else if ( homeLocation->isValid() ) {
30 if ( workLocation==0 ) {
31 workLocation = new Location( "work" );
32 locations->addLocation( workLocation );
33 } else if ( workLocation->isValid() ) {
38 homeLocation, SIGNAL( becomeValid() ),
39 this, SLOT( setHomeButtonValid() )
42 homeLocation, SIGNAL( becomeValid() ),
43 locations, SLOT( saveLocation() )
47 workLocation, SIGNAL( becomeValid() ),
48 this, SLOT( setWorkButtonValid() )
51 workLocation, SIGNAL( becomeValid() ),
52 locations, SLOT( saveLocation() )
55 destination.append( homeLocation );
56 destination.append( workLocation );
59 ui->destinationButtons, SIGNAL( buttonClicked( int ) ),
60 this, SLOT( changeDestination( int ) )
64 UiController::~UiController()
68 void UiController::setHomeButtonValid()
70 qDebug() << "setting home button valid";
71 setButtonValid( Ui::HomeButtonId );
74 void UiController::setWorkButtonValid()
76 qDebug() << "setting work button valid";
77 setButtonValid( Ui::WorkButtonId );
80 void UiController::setButtonValid( int id )
82 ui->destinationButtons->button( id )->setEnabled(true);
85 void UiController::changeDestination( int id )
87 qDebug() << "Button "+QString::number(id)+" clicked";
89 bool destinationHasChanged = ( currentDestination != id );
90 if ( destinationHasChanged ) {
91 emit destinationChanged( destination[id] );
94 // always want to emit this so that the gps position is update
95 // and the user gets new information
99 void UiController::displayRoute( const QList<RouteData> &routeData )
101 qDebug() << "displaying route";
103 for ( int i=0; i<Ytv::ShowFiveResults; ++i ) {
106 QWidget *widget = ui->routeStack->itemAt( i )->widget();
107 QRadioButton *button = qobject_cast<QRadioButton *>(widget);
109 if ( i<routeData.count() ) {
110 RouteData thisRouteData = routeData.at(i);
111 label = ( QStringList()
112 << thisRouteData.m_departureTime
113 << thisRouteData.m_lineCode ).join( "/" );
114 button->setEnabled( true );
116 button->setEnabled( false );
119 button->setText( label );