From 2718577ecf7a4a5c9fc619a46ee79a468044b4d7 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Tue, 14 Jul 2009 10:44:05 +1000 Subject: Move some keypad navigation code back out of QLineControl --- src/gui/widgets/qlinecontrol.cpp | 46 ----------------------------------- src/gui/widgets/qlineedit.cpp | 52 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 48 insertions(+), 50 deletions(-) diff --git a/src/gui/widgets/qlinecontrol.cpp b/src/gui/widgets/qlinecontrol.cpp index fc0a173..dd3c057 100644 --- a/src/gui/widgets/qlinecontrol.cpp +++ b/src/gui/widgets/qlinecontrol.cpp @@ -1212,44 +1212,6 @@ void QLineControl::timerEvent ( QTimerEvent * event ) bool QLineControl::processEvent(QEvent* ev) { -#ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled()) { - if ((ev->type() == QEvent::KeyPress) || (ev->type() == QEvent::KeyRelease)) { - QKeyEvent *ke = (QKeyEvent *)ev; - if (ke->key() == Qt::Key_Back) { - if (ke->isAutoRepeat()) { - // Swallow it. We don't want back keys running amok. - ke->accept(); - return true; - } - if ((ev->type() == QEvent::KeyRelease) - && !isReadOnly() - && deleteAllTimer) { - killTimer(m_deleteAllTimer); - m_deleteAllTimer = 0; - backspace(); - ke->accept(); - return true; - } - } - } else if (e->type() == QEvent::EnterEditFocus) { - end(false); - int cft = QApplication::cursorFlashTime(); - control->setCursorBlinkPeriod(cft/2); - } else if (e->type() == QEvent::LeaveEditFocus) { - d->setCursorVisible(false);//!!! - control->setCursorBlinkPeriod(0); - if (!m_emitingEditingFinished) { - if (hasAcceptableInput() || fixup()) { - m_emitingEditingFinished = true; - emit editingFinished(); - m_emitingEditingFinished = false; - } - } - } - return; - } -#endif switch(ev->type()){ #ifndef QT_NO_GRAPHICSVIEW case QEvent::GraphicsSceneMouseMove: @@ -1332,14 +1294,6 @@ void QLineControl::processMouseEvent(QMouseEvent* ev) } if (ev->button() == Qt::RightButton) return; -#ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) { - setEditFocus(true); - // Get the completion list to pop up. - if (m_completer) - m_completer->complete(); - } -#endif bool mark = ev->modifiers() & Qt::ShiftModifier; int cursor = xToPos(ev->pos().x()); diff --git a/src/gui/widgets/qlineedit.cpp b/src/gui/widgets/qlineedit.cpp index 977d00c..b0c48b0 100644 --- a/src/gui/widgets/qlineedit.cpp +++ b/src/gui/widgets/qlineedit.cpp @@ -1361,7 +1361,45 @@ void QLineEdit::paste() bool QLineEdit::event(QEvent * e) { Q_D(QLineEdit); - if (e->type() == QEvent::Timer) { +#ifdef QT_KEYPAD_NAVIGATION + if (QApplication::keypadNavigationEnabled()) { + if ((ev->type() == QEvent::KeyPress) || (ev->type() == QEvent::KeyRelease)) { + QKeyEvent *ke = (QKeyEvent *)ev; + if (ke->key() == Qt::Key_Back) { + if (ke->isAutoRepeat()) { + // Swallow it. We don't want back keys running amok. + ke->accept(); + return true; + } + if ((ev->type() == QEvent::KeyRelease) + && !isReadOnly() + && deleteAllTimer) { + killTimer(m_deleteAllTimer); + m_deleteAllTimer = 0; + backspace(); + ke->accept(); + return true; + } + } + } else if (e->type() == QEvent::EnterEditFocus) { + end(false); + int cft = QApplication::cursorFlashTime(); + control->setCursorBlinkPeriod(cft/2); + } else if (e->type() == QEvent::LeaveEditFocus) { + d->setCursorVisible(false);//!!! + control->setCursorBlinkPeriod(0); + if (!m_emitingEditingFinished) { + if (hasAcceptableInput() || fixup()) { + m_emitingEditingFinished = true; + emit editingFinished(); + m_emitingEditingFinished = false; + } + } + } + return; + } +#endif + if (e->type() == QEvent::Timer) { // should be timerEvent, is here for binary compatibility int timerId = ((QTimerEvent*)e)->timerId(); if (false) { @@ -1442,9 +1480,7 @@ void QLineEdit::mouseMoveEvent(QMouseEvent * e) d->drag(); } else #endif - { d->control->moveCursor(d->xToPos(e->pos().x()), true); - } } } @@ -1463,10 +1499,18 @@ void QLineEdit::mouseReleaseEvent(QMouseEvent* e) d->drag(); } else #endif - { d->control->moveCursor(d->xToPos(e->pos().x()), true); + } +#ifndef QT_NO_CLIPBOARD + if (QApplication::clipboard()->supportsSelection()) { + if (e->button() == Qt::LeftButton) { + d->control->copy(QClipboard::Selection); + } else if (!d->control->isReadOnly() && e->button() == Qt::MidButton) { + deselect(); + insert(QApplication::clipboard()->text(QClipboard::Selection)); } } +#endif } /*! \reimp -- cgit v0.12