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"
66 << "Genova San Biagio"
67 << "Genova Pontedecimo"
68 << "Piano Orzzontale dei Giovi"
71 << "Genova Via di Francia"
72 << "Genova Piazza Principe"
75 << "Genova Quarto dei Mille"
76 << "Genova Quinto al Mare"
85 stationListModel->setStringList(stationList);
86 filterModel->setSourceModel(stationListModel);
87 filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
88 ui->listView->setModel(filterModel);
89 ui->listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
90 ui->listView->setSelectionMode(QAbstractItemView::SingleSelection);
91 ui->filterEdit->hide();
93 keyPressForwarder->setTarget(ui->filterEdit);
94 ui->listView->installEventFilter(keyPressForwarder);
97 SIGNAL(activated(QModelIndex)), SLOT(showStation(QModelIndex)));
98 connect(ui->filterEdit, SIGNAL(textChanged(const QString &)),
99 SLOT(handleFilterChanges(const QString &)));
102 StationListView::~StationListView()
107 void StationListView::showSettings(void)
109 qDebug() << "Show Settings";
110 SettingsDialog *settingsDialog = new SettingsDialog(this);
111 if (settingsDialog->exec() == QDialog::Accepted) {
112 // TODO Use new settings
115 delete settingsDialog;
118 void StationListView::showStation(const QModelIndex &index)
120 qDebug() << "Show Station" << index.data();
121 emit stationSelected(index.data().toString());
124 void StationListView::handleFilterChanges(const QString &filter)
126 if (!filter.isEmpty())
127 ui->filterEdit->show();
129 ui->filterEdit->hide();
130 filterModel->setFilterFixedString(filter);