2 #include "ui_chooser.h"
4 Chooser::Chooser(QWidget *parent) :
9 ui->scrollArea->setProperty("FingerScrollable", true);
10 //Create the buttons for favourite stations
11 updateStationButtons();
15 * Re-creates the display of the buttons for the user's favourite stations.
17 void Chooser::updateStationButtons()
19 //Delete all the currently displayed buttons
20 for(int i = 0; i < stationButtons.size(); i++)
21 delete stationButtons.at(i);
23 //Clear the list of pointers to displayed station buttons
24 stationButtons.clear();
26 //Get the user's favourite stations, and add a button for each
27 QStringList favourites = settings.value("FavouriteDepartureBoards", QVariant()).toStringList();
28 QStringList favouritesCRS = settings.value("FavouriteDepartureBoardsCRS", QVariant()).toStringList();
30 for(int i = 0; i < favourites.size(); i++)
31 addStationButton(favourites.at(i), favouritesCRS.at(i));
33 //Make a button to allow the user to edit their favourites...
34 QPushButton * b = new QPushButton("Edit Favourites...");
35 //...add it to the list of displayed buttons & the display widget
36 stationButtons.append(b);
37 ui->favourites_widget->layout()->addWidget(b);
38 b->setIcon(QIcon(":/icons/folder.png"));
39 connect(b, SIGNAL(clicked()), this, SLOT(editFavouriteDepartures()));
41 QPushButton * b2 = new QPushButton("Choose Station...");
42 //...add it to the list of displayed buttons & the display widget
43 stationButtons.append(b2);
44 ui->favourites_widget->layout()->addWidget(b2);
45 connect(b2, SIGNAL(clicked()), this, SLOT(chooseStation()));
48 void Chooser::chooseStation()
50 StationChooser chooser;
52 if(chooser.exec() == QDialog::Accepted)
54 departureBoard = new DepartureBoard(this);
55 departureBoard->show(chooser.getChoiceCRS());
60 * Slot to show the dialog allowing the user to edit their favourite stations
62 void Chooser::editFavouriteDepartures()
64 favouriteStations.exec("FavouriteDepartureBoards", "FavouriteDepartureBoardsCRS");
65 //Update the button display in case the favourites have changed
66 updateStationButtons();
70 * Adds a button to the display widget. Returns a pointer to the created button
72 QPushButton * Chooser::addStationButton(QString name, QString crs)
74 QPushButton * b = new QPushButton(name);
75 //Create the button and add it to the list of buttons, & the display widget
76 stationButtons.append(b);
77 ui->favourites_widget->layout()->addWidget(b);
78 //Set the button's name to the station's CRS code; we use this in the clicked() slot to find which button was clicked
79 b->setObjectName(crs);
80 connect(b, SIGNAL(clicked()), this, SLOT(stationSelected()));
85 * Slot for when one of the station buttons is clicked
87 void Chooser::stationSelected()
89 //Show the departure board for the station. The CRS code for the station is found from the button's objectName
90 departureBoard = new DepartureBoard(this);
91 departureBoard->show(sender()->objectName());
96 if(departureBoard != 0)
97 delete departureBoard;
103 * Slot to show the journey planner
105 void Chooser::launchPlanner()
107 //Launch the webpage for the journey planner online, and quit
108 QDesktopServices::openUrl(QUrl("http://ojp.nationalrail.co.uk/en/s/planjourney/query"));
112 void Chooser::changeEvent(QEvent *e)
114 QMainWindow::changeEvent(e);
116 case QEvent::LanguageChange:
117 ui->retranslateUi(this);