3 Copyright (C) 2011 Luciano Montanaro <mikelima@cirulla.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 #include "stationlistview.h"
23 #include "ui_stationlistview.h"
24 #include "stationlistmodel.h"
25 #include "keypressforwarder.h"
26 #include "settingsdialog.h"
28 #include <QActionGroup>
31 #include <QSortFilterProxyModel>
32 #include <QStringListModel>
34 StationListView::StationListView(StationListModel *model, QWidget *parent) :
36 ui(new Ui::StationListView),
37 viewSelectionGroup(new QActionGroup(0)),
38 stationListModel(model),
39 filterModel(new QSortFilterProxyModel(this)),
40 keyPressForwarder(new KeyPressForwarder(this))
44 setAttribute(Qt::WA_Maemo5StackedWindow);
45 setAttribute(Qt::WA_Maemo5AutoOrientation);
48 viewSelectionGroup->addAction(ui->sortByNameAction);
49 viewSelectionGroup->addAction(ui->sortNearFirstAction);
50 viewSelectionGroup->addAction(ui->sortRecentFirstAction);
52 QStringList stationList;
53 stationList << "Savona"
62 << "Genova Sestri Ponente"
63 << "Genova Cornigliano"
64 << "Genova Sampierdarena"
66 << "Genova Costa di Sestri Ponente"
68 << "Genova Acquasanta"
80 << "Castelnuovo Calcea"
87 << "Genova San Biagio"
88 << "Genova Pontedecimo"
89 << "Piano Orzzontale dei Giovi"
95 << "Serravalle Scrivia"
98 << "Genova Via di Francia"
99 << "Genova Piazza Principe"
102 << "Genova Quarto dei Mille"
103 << "Genova Quinto al Mare"
112 stationListModel->setStringList(stationList);
114 filterModel->setSourceModel(stationListModel);
115 filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
116 ui->listView->setModel(filterModel);
117 ui->listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
118 ui->listView->setSelectionMode(QAbstractItemView::SingleSelection);
119 ui->filterEdit->hide();
121 keyPressForwarder->setTarget(ui->filterEdit);
122 ui->listView->installEventFilter(keyPressForwarder);
124 connect(ui->showAboutAction, SIGNAL(triggered()),
125 this, SIGNAL(aboutTriggered()));
126 connect(ui->listView,
127 SIGNAL(activated(QModelIndex)), SLOT(showStation(QModelIndex)));
128 connect(ui->filterEdit, SIGNAL(textChanged(const QString &)),
129 SLOT(handleFilterChanges(const QString &)));
132 StationListView::~StationListView()
137 void StationListView::showSettings(void)
139 qDebug() << "Show Settings";
140 SettingsDialog *settingsDialog = new SettingsDialog(this);
141 if (settingsDialog->exec() == QDialog::Accepted) {
142 // TODO Use new settings
145 delete settingsDialog;
148 void StationListView::showStation(const QModelIndex &index)
150 qDebug() << "Show Station" << index.data();
151 emit stationSelected(index.data().toString());
154 void StationListView::handleFilterChanges(const QString &filter)
156 if (!filter.isEmpty())
157 ui->filterEdit->show();
159 ui->filterEdit->hide();
160 filterModel->setFilterFixedString(filter);