diff options
author | kh1 <qt-info@nokia.com> | 2010-06-03 12:23:52 (GMT) |
---|---|---|
committer | kh1 <qt-info@nokia.com> | 2010-06-03 12:23:52 (GMT) |
commit | 27c4c963de1a28afa95e7837fa844ae8a3bccd2c (patch) | |
tree | b120cdaad333ba8f2c20f0708457cf18beaadf3b /tools/assistant | |
parent | 919ce79845d077f2509d6cc0f8fac50d339175b3 (diff) | |
download | Qt-27c4c963de1a28afa95e7837fa844ae8a3bccd2c.zip Qt-27c4c963de1a28afa95e7837fa844ae8a3bccd2c.tar.gz Qt-27c4c963de1a28afa95e7837fa844ae8a3bccd2c.tar.bz2 |
Make the open pages widget act on the up/ down key directly.
Reviewed-by: ck
Diffstat (limited to 'tools/assistant')
-rw-r--r-- | tools/assistant/tools/assistant/openpageswidget.cpp | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/tools/assistant/tools/assistant/openpageswidget.cpp b/tools/assistant/tools/assistant/openpageswidget.cpp index a68da23..b7ac33e 100644 --- a/tools/assistant/tools/assistant/openpageswidget.cpp +++ b/tools/assistant/tools/assistant/openpageswidget.cpp @@ -134,10 +134,15 @@ OpenPagesWidget::~OpenPagesWidget() void OpenPagesWidget::selectCurrentPage() { TRACE_OBJ + const QModelIndex ¤t = + model()->index(CentralWidget::instance()->currentIndex(), 0); + QItemSelectionModel * const selModel = selectionModel(); - selModel->clearSelection(); - selModel->select(model()->index(CentralWidget::instance()->currentIndex(), 0), + selModel->select(current, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); + selModel->clearSelection(); + + setCurrentIndex(current); scrollTo(currentIndex()); } @@ -204,18 +209,27 @@ void OpenPagesWidget::handleClicked(const QModelIndex &index) bool OpenPagesWidget::eventFilter(QObject *obj, QEvent *event) { TRACE_OBJ - if (obj == this && event->type() == QEvent::KeyPress) { - if (currentIndex().isValid()) { - QKeyEvent *ke = static_cast<QKeyEvent*>(event); + if (obj != this) + return QWidget::eventFilter(obj, event); + + if (event->type() == QEvent::KeyPress) { + QKeyEvent *ke = static_cast<QKeyEvent*>(event); + if (currentIndex().isValid() && ke->modifiers() == 0) { const int key = ke->key(); - if ((key == Qt::Key_Return || key == Qt::Key_Enter || key == Qt::Key_Space) - && ke->modifiers() == 0) { + if (key == Qt::Key_Return || key == Qt::Key_Enter + || key == Qt::Key_Space) { emit setCurrentPage(currentIndex()); } else if ((key == Qt::Key_Delete || key == Qt::Key_Backspace) - && ke->modifiers() == 0 && model()->rowCount() > 1) { + && model()->rowCount() > 1) { emit closePage(currentIndex()); } } + } else if (event->type() == QEvent::KeyRelease) { + QKeyEvent *ke = static_cast<QKeyEvent*>(event); + if (ke->modifiers() == 0 + && (ke->key() == Qt::Key_Up || ke->key() == Qt::Key_Down)) { + emit setCurrentPage(currentIndex()); + } } return QWidget::eventFilter(obj, event); } |