aboutsummaryrefslogtreecommitdiffstats
path: root/src/shared/help/topicchooser.cpp
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@digia.com>2014-06-05 11:00:58 +0200
committerEike Ziller <eike.ziller@digia.com>2014-06-05 11:36:14 +0200
commit9e39fa7ab4fec7b37f90193a09f83f5f917a7baa (patch)
treefee7841ffa258ee02f88f1c507db6eda8c5c58d3 /src/shared/help/topicchooser.cpp
parente7689ce967822f9d5fa67b814736d4e964bf1d31 (diff)
Help: Add page up/down handling to topic chooser
And avoid that the filter line edit jumps to start of line and end of line when pressing up/down Change-Id: Ia3485f395a064e7a979a78d54fa5f0a41784d67d Reviewed-by: Karsten Heimrich <karsten.heimrich@digia.com>
Diffstat (limited to 'src/shared/help/topicchooser.cpp')
-rw-r--r--src/shared/help/topicchooser.cpp43
1 files changed, 26 insertions, 17 deletions
diff --git a/src/shared/help/topicchooser.cpp b/src/shared/help/topicchooser.cpp
index 308a316f272..ec9dde695ca 100644
--- a/src/shared/help/topicchooser.cpp
+++ b/src/shared/help/topicchooser.cpp
@@ -104,23 +104,32 @@ void TopicChooser::activated(const QModelIndex &index)
bool TopicChooser::eventFilter(QObject *object, QEvent *event)
{
if (object == ui.lineEdit && event->type() == QEvent::KeyPress) {
- QModelIndex idx = ui.listWidget->currentIndex();
- switch ((static_cast<QKeyEvent*>(event)->key())) {
- case Qt::Key_Up:
- idx = m_filterModel->index(idx.row() - 1, idx.column(),
- idx.parent());
- if (idx.isValid())
- ui.listWidget->setCurrentIndex(idx);
- break;
-
- case Qt::Key_Down:
- idx = m_filterModel->index(idx.row() + 1, idx.column(),
- idx.parent());
- if (idx.isValid())
- ui.listWidget->setCurrentIndex(idx);
- break;
-
- default: ;
+ QKeyEvent *ke = static_cast<QKeyEvent*>(event);
+ int dIndex = 0;
+ switch (ke->key()) {
+ case Qt::Key_Up:
+ dIndex = -1;
+ break;
+ case Qt::Key_Down:
+ dIndex = +1;
+ break;
+ case Qt::Key_PageUp:
+ dIndex = -5;
+ break;
+ case Qt::Key_PageDown:
+ dIndex = +5;
+ break;
+ default:
+ break;
+ }
+ if (dIndex != 0) {
+ QModelIndex idx = ui.listWidget->currentIndex();
+ int newIndex = qMin(m_filterModel->rowCount(idx.parent()) - 1,
+ qMax(0, idx.row() + dIndex));
+ idx = m_filterModel->index(newIndex, idx.column(), idx.parent());
+ if (idx.isValid())
+ ui.listWidget->setCurrentIndex(idx);
+ return true;
}
} else if (ui.lineEdit && event->type() == QEvent::FocusIn
&& static_cast<QFocusEvent *>(event)->reason() != Qt::MouseFocusReason) {