From f38b88fa3d8ec4448c28044bf95c5c845a80d3f1 Mon Sep 17 00:00:00 2001 From: mae Date: Mon, 5 Oct 2009 18:20:40 +0200 Subject: Fix QPlainTextEdit pageUp/Down key handling in read-only mode QTextControl has two independent interaction flags TextEditable and TextSelectableByKeyboard, i.e. the latter can also apply in read-only mode. This used to be handled incorrectly in QPlainTextEdit. Reviewed-by: con --- src/gui/widgets/qplaintextedit.cpp | 51 ++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/src/gui/widgets/qplaintextedit.cpp b/src/gui/widgets/qplaintextedit.cpp index d519bfe..5d13c36 100644 --- a/src/gui/widgets/qplaintextedit.cpp +++ b/src/gui/widgets/qplaintextedit.cpp @@ -1578,7 +1578,35 @@ void QPlainTextEdit::keyPressEvent(QKeyEvent *e) } #endif - if (!(d->control->textInteractionFlags() & Qt::TextEditable)) { +#ifndef QT_NO_SHORTCUT + + Qt::TextInteractionFlags tif = d->control->textInteractionFlags(); + + if (tif & Qt::TextSelectableByKeyboard){ + if (e == QKeySequence::SelectPreviousPage) { + e->accept(); + d->pageUpDown(QTextCursor::Up, QTextCursor::KeepAnchor); + return; + } else if (e ==QKeySequence::SelectNextPage) { + e->accept(); + d->pageUpDown(QTextCursor::Down, QTextCursor::KeepAnchor); + return; + } + } + if (tif & (Qt::TextSelectableByKeyboard | Qt::TextEditable)) { + if (e == QKeySequence::MoveToPreviousPage) { + e->accept(); + d->pageUpDown(QTextCursor::Up, QTextCursor::MoveAnchor); + return; + } else if (e == QKeySequence::MoveToNextPage) { + e->accept(); + d->pageUpDown(QTextCursor::Down, QTextCursor::MoveAnchor); + return; + } + } +#endif // QT_NO_SHORTCUT + + if (!(tif & Qt::TextEditable)) { switch (e->key()) { case Qt::Key_Space: e->accept(); @@ -1605,27 +1633,6 @@ void QPlainTextEdit::keyPressEvent(QKeyEvent *e) return; } -#ifndef QT_NO_SHORTCUT - if (e == QKeySequence::MoveToPreviousPage) { - e->accept(); - d->pageUpDown(QTextCursor::Up, QTextCursor::MoveAnchor); - return; - } else if (e == QKeySequence::MoveToNextPage) { - e->accept(); - d->pageUpDown(QTextCursor::Down, QTextCursor::MoveAnchor); - return; - } else if (e == QKeySequence::SelectPreviousPage) { - e->accept(); - d->pageUpDown(QTextCursor::Up, QTextCursor::KeepAnchor); - return; - } else if (e ==QKeySequence::SelectNextPage) { - e->accept(); - d->pageUpDown(QTextCursor::Down, QTextCursor::KeepAnchor); - return; - } -#endif // QT_NO_SHORTCUT - - d->sendControlEvent(e); #ifdef QT_KEYPAD_NAVIGATION if (!e->isAccepted()) { -- cgit v0.12