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"
25 #include "keypressforwarder.h"
26 #include "settingsdialog.h"
28 #include <QActionGroup>
31 #include <QSortFilterProxyModel>
32 #include <QStringListModel>
34 StationListView::StationListView(QWidget *parent) :
36 ui(new Ui::StationListView),
37 viewSelectionGroup(new QActionGroup(0)),
38 stationListModel(new QStringListModel(this)),
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);
51 QStringList stationList;
52 stationList << "Savona"
61 << "Genova Sestri Ponente"
62 << "Genova Cornigliano"
63 << "Genova Sampierdarena"
65 << "Genova Costa di Sestri Ponente"
67 << "Genova Acquasanta"
79 << "Castelnuovo Calcea"
86 << "Genova San Biagio"
87 << "Genova Pontedecimo"
88 << "Piano Orzzontale dei Giovi"
94 << "Serravalle Scrivia"
97 << "Genova Via di Francia"
98 << "Genova Piazza Principe"
101 << "Genova Quarto dei Mille"
102 << "Genova Quinto al Mare"
111 stationListModel->setStringList(stationList);
112 filterModel->setSourceModel(stationListModel);
113 filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
114 ui->listView->setModel(filterModel);
115 ui->listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
116 ui->listView->setSelectionMode(QAbstractItemView::SingleSelection);
117 ui->filterEdit->hide();
119 keyPressForwarder->setTarget(ui->filterEdit);
120 ui->listView->installEventFilter(keyPressForwarder);
122 connect(ui->showAboutAction, SIGNAL(triggered()),
123 this, SIGNAL(aboutTriggered()));
124 connect(ui->listView,
125 SIGNAL(activated(QModelIndex)), SLOT(showStation(QModelIndex)));
126 connect(ui->filterEdit, SIGNAL(textChanged(const QString &)),
127 SLOT(handleFilterChanges(const QString &)));
130 StationListView::~StationListView()
135 void StationListView::showSettings(void)
137 qDebug() << "Show Settings";
138 SettingsDialog *settingsDialog = new SettingsDialog(this);
139 if (settingsDialog->exec() == QDialog::Accepted) {
140 // TODO Use new settings
143 delete settingsDialog;
146 void StationListView::showStation(const QModelIndex &index)
148 qDebug() << "Show Station" << index.data();
149 emit stationSelected(index.data().toString());
152 void StationListView::handleFilterChanges(const QString &filter)
154 if (!filter.isEmpty())
155 ui->filterEdit->show();
157 ui->filterEdit->hide();
158 filterModel->setFilterFixedString(filter);