settingsdialog.cpp \
stationview.cpp \
app.cpp \
- stationlistview.cpp
+ stationlistview.cpp \
+ keypressforwarder.cpp
HEADERS += \
settingsdialog.h \
stationview.h \
app.h \
- stationlistview.h
+ stationlistview.h \
+ keypressforwarder.h
FORMS += \
settingsdialog.ui \
--- /dev/null
+/*
+
+Copyright (C) 2011 mikelima
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; see the file COPYING. If not, write to
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.
+
+*/
+
+#include "keypressforwarder.h"
+
+#include <QApplication>
+#include <QDebug>
+#include <QEvent>
+#include <QKeyEvent>
+#include <QWidget>
+
+KeyPressForwarder::KeyPressForwarder(QObject *parent) :
+ QObject(parent)
+{
+}
+
+bool KeyPressForwarder::eventFilter(QObject *obj, QEvent *event)
+{
+ if (event->type() == QEvent::KeyPress) {
+ QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
+ qDebug() << keyEvent->key();
+ if (target) {
+ target->show();
+ target->setFocus();
+ return QApplication::sendEvent(target, event);
+ }
+ }
+ return QObject::eventFilter(obj, event);
+}
+
+void KeyPressForwarder::setTarget(QWidget *w)
+{
+ target = w;
+}
--- /dev/null
+/*
+
+Copyright (C) 2011 mikelima
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; see the file COPYING. If not, write to
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.
+
+*/
+
+#ifndef EDITFIELDENABLER_H
+#define EDITFIELDENABLER_H
+
+#include <QObject>
+
+class QWidget;
+
+class KeyPressForwarder : public QObject
+{
+ Q_OBJECT
+public:
+ explicit KeyPressForwarder(QObject *parent = 0);
+
+ void setTarget(QWidget *w);
+
+protected:
+ bool eventFilter(QObject *obj, QEvent *event);
+
+private:
+ QWidget *target;
+};
+
+#endif // EDITFIELDENABLER_H
#include "stationlistview.h"
#include "ui_stationlistview.h"
+#include "keypressforwarder.h"
#include "settingsdialog.h"
-#include "stationview.h"
#include <QActionGroup>
#include <QDebug>
+#include <QKeyEvent>
#include <QSortFilterProxyModel>
#include <QStringListModel>
viewSelectionGroup(new QActionGroup(0)),
stationListModel(new QStringListModel(this)),
filterModel(new QSortFilterProxyModel(this)),
- stationView(0)
+ keyPressForwarder(new KeyPressForwarder(this))
{
#ifdef Q_WS_MAEMO_5
<< "Camogli";
stationListModel->setStringList(stationList);
filterModel->setSourceModel(stationListModel);
+ filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
ui->listView->setModel(filterModel);
ui->listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->listView->setSelectionMode(QAbstractItemView::SingleSelection);
- //ui->filterEdit->hide();
+ ui->filterEdit->hide();
+
+ keyPressForwarder->setTarget(ui->filterEdit);
+ ui->listView->installEventFilter(keyPressForwarder);
+
connect(ui->listView,
SIGNAL(activated(QModelIndex)), SLOT(showStation(QModelIndex)));
connect(ui->filterEdit, SIGNAL(textChanged(const QString &)),
- filterModel, SLOT(setFilterFixedString(const QString &)));
+ SLOT(handleFilterChanges(const QString &)));
}
StationListView::~StationListView()
qDebug() << "Show Station" << index.data();
emit stationSelected(index.data().toString());
}
+
+void StationListView::handleFilterChanges(const QString &filter)
+{
+ if (!filter.isEmpty())
+ ui->filterEdit->show();
+ else
+ ui->filterEdit->hide();
+ filterModel->setFilterFixedString(filter);
+}
class QActionGroup;
class QStringListModel;
class QSortFilterProxyModel;
+class KeyPressForwarder;
class StationView;
private slots:
void showSettings(void);
void showStation(const QModelIndex &index);
+ void handleFilterChanges(const QString &filter);
private:
Ui::StationListView *ui;
QActionGroup *viewSelectionGroup;
QStringListModel *stationListModel;
QSortFilterProxyModel *filterModel;
- StationView *stationView;
+ KeyPressForwarder *keyPressForwarder;
};
#endif // STATIONLISTVIEW_H