From 8fb15f3a7540b0ef40ee15292e76a442889fed36 Mon Sep 17 00:00:00 2001 From: Pekka Vuorela Date: Fri, 30 Sep 2011 16:50:10 +0300 Subject: [PATCH] Removed some dead code from QWidgetLineControl There was a big processEvents() method which was actually getting called for a single type of events. Change-Id: I66ac70c7ac6e2f9136b24541d42a4185f8797583 Reviewed-on: http://codereview.qt-project.org/6132 Reviewed-by: Qt Sanity Bot Reviewed-by: Lars Knoll Reviewed-by: Joona Petrell --- src/widgets/widgets/qlineedit.cpp | 7 +- src/widgets/widgets/qwidgetlinecontrol.cpp | 181 +++++---------------- src/widgets/widgets/qwidgetlinecontrol_p.h | 5 +- 3 files changed, 46 insertions(+), 147 deletions(-) diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp index 9706707f20..2b91601f8c 100644 --- a/src/widgets/widgets/qlineedit.cpp +++ b/src/widgets/widgets/qlineedit.cpp @@ -1347,8 +1347,11 @@ bool QLineEdit::event(QEvent * e) //d->separate(); } else if (e->type() == QEvent::WindowActivate) { QTimer::singleShot(0, this, SLOT(_q_handleWindowActivate())); - }else if(e->type() == QEvent::ShortcutOverride){ - d->control->processEvent(e); +#ifndef QT_NO_SHORTCUT + } else if (e->type() == QEvent::ShortcutOverride) { + QKeyEvent *ke = static_cast(e); + d->control->processShortcutOverrideEvent(ke); +#endif } else if (e->type() == QEvent::KeyRelease) { d->control->setCursorBlinkPeriod(QApplication::cursorFlashTime()); } else if (e->type() == QEvent::Show) { diff --git a/src/widgets/widgets/qwidgetlinecontrol.cpp b/src/widgets/widgets/qwidgetlinecontrol.cpp index c04671b710..6869f56e0a 100644 --- a/src/widgets/widgets/qwidgetlinecontrol.cpp +++ b/src/widgets/widgets/qwidgetlinecontrol.cpp @@ -1380,156 +1380,51 @@ void QWidgetLineControl::timerEvent(QTimerEvent *event) } } -bool QWidgetLineControl::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() - && m_deleteAllTimer) { - killTimer(m_deleteAllTimer); - m_deleteAllTimer = 0; - backspace(); - ke->accept(); - return true; - } - } - } - } -#endif - switch(ev->type()){ -#ifndef QT_NO_GRAPHICSVIEW - case QEvent::GraphicsSceneMouseDoubleClick: - case QEvent::GraphicsSceneMouseMove: - case QEvent::GraphicsSceneMouseRelease: - case QEvent::GraphicsSceneMousePress:{ - QGraphicsSceneMouseEvent *gvEv = static_cast(ev); - QMouseEvent mouse(ev->type(), - gvEv->pos(), gvEv->pos(), gvEv->screenPos(), gvEv->button(), gvEv->buttons(), gvEv->modifiers()); - processMouseEvent(&mouse); break; - } -#endif - case QEvent::MouseButtonPress: - case QEvent::MouseButtonRelease: - case QEvent::MouseButtonDblClick: - case QEvent::MouseMove: - processMouseEvent(static_cast(ev)); break; - case QEvent::KeyPress: - case QEvent::KeyRelease: - processKeyEvent(static_cast(ev)); break; - case QEvent::InputMethod: - processInputMethodEvent(static_cast(ev)); break; #ifndef QT_NO_SHORTCUT - case QEvent::ShortcutOverride:{ - if (isReadOnly()) - return false; - QKeyEvent* ke = static_cast(ev); - if (ke == QKeySequence::Copy - || ke == QKeySequence::Paste - || ke == QKeySequence::Cut - || ke == QKeySequence::Redo - || ke == QKeySequence::Undo - || ke == QKeySequence::MoveToNextWord - || ke == QKeySequence::MoveToPreviousWord - || ke == QKeySequence::MoveToStartOfDocument - || ke == QKeySequence::MoveToEndOfDocument - || ke == QKeySequence::SelectNextWord - || ke == QKeySequence::SelectPreviousWord - || ke == QKeySequence::SelectStartOfLine - || ke == QKeySequence::SelectEndOfLine - || ke == QKeySequence::SelectStartOfBlock - || ke == QKeySequence::SelectEndOfBlock - || ke == QKeySequence::SelectStartOfDocument - || ke == QKeySequence::SelectAll - || ke == QKeySequence::SelectEndOfDocument) { - ke->accept(); - } else if (ke->modifiers() == Qt::NoModifier || ke->modifiers() == Qt::ShiftModifier - || ke->modifiers() == Qt::KeypadModifier) { - if (ke->key() < Qt::Key_Escape) { - ke->accept(); - } else { - switch (ke->key()) { - case Qt::Key_Delete: - case Qt::Key_Home: - case Qt::Key_End: - case Qt::Key_Backspace: - case Qt::Key_Left: - case Qt::Key_Right: - ke->accept(); - default: - break; - } - } - } - } -#endif - default: - return false; - } - return true; -} - -void QWidgetLineControl::processMouseEvent(QMouseEvent* ev) +void QWidgetLineControl::processShortcutOverrideEvent(QKeyEvent *ke) { + if (isReadOnly()) + return; - switch (ev->type()) { - case QEvent::GraphicsSceneMousePress: - case QEvent::MouseButtonPress:{ - if (m_tripleClickTimer - && (ev->pos() - m_tripleClick).manhattanLength() - < QApplication::startDragDistance()) { - selectAll(); - return; + if (ke == QKeySequence::Copy + || ke == QKeySequence::Paste + || ke == QKeySequence::Cut + || ke == QKeySequence::Redo + || ke == QKeySequence::Undo + || ke == QKeySequence::MoveToNextWord + || ke == QKeySequence::MoveToPreviousWord + || ke == QKeySequence::MoveToStartOfDocument + || ke == QKeySequence::MoveToEndOfDocument + || ke == QKeySequence::SelectNextWord + || ke == QKeySequence::SelectPreviousWord + || ke == QKeySequence::SelectStartOfLine + || ke == QKeySequence::SelectEndOfLine + || ke == QKeySequence::SelectStartOfBlock + || ke == QKeySequence::SelectEndOfBlock + || ke == QKeySequence::SelectStartOfDocument + || ke == QKeySequence::SelectAll + || ke == QKeySequence::SelectEndOfDocument) { + ke->accept(); + } else if (ke->modifiers() == Qt::NoModifier || ke->modifiers() == Qt::ShiftModifier + || ke->modifiers() == Qt::KeypadModifier) { + if (ke->key() < Qt::Key_Escape) { + ke->accept(); + } else { + switch (ke->key()) { + case Qt::Key_Delete: + case Qt::Key_Home: + case Qt::Key_End: + case Qt::Key_Backspace: + case Qt::Key_Left: + case Qt::Key_Right: + ke->accept(); + default: + break; } - if (ev->button() == Qt::RightButton) - return; - - bool mark = ev->modifiers() & Qt::ShiftModifier; - int cursor = xToPos(ev->pos().x()); - moveCursor(cursor, mark); - break; } - case QEvent::GraphicsSceneMouseDoubleClick: - case QEvent::MouseButtonDblClick: - if (ev->button() == Qt::LeftButton) { - selectWordAtPos(xToPos(ev->pos().x())); - if (m_tripleClickTimer) - killTimer(m_tripleClickTimer); - m_tripleClickTimer = startTimer(QApplication::doubleClickInterval()); - m_tripleClick = ev->pos(); - } - break; - case QEvent::GraphicsSceneMouseRelease: - case QEvent::MouseButtonRelease: -#ifndef QT_NO_CLIPBOARD - if (QApplication::clipboard()->supportsSelection()) { - if (ev->button() == Qt::LeftButton) { - copy(QClipboard::Selection); - } else if (!isReadOnly() && ev->button() == Qt::MidButton) { - deselect(); - insert(QApplication::clipboard()->text(QClipboard::Selection)); - } - } -#endif - break; - case QEvent::GraphicsSceneMouseMove: - case QEvent::MouseMove: - if (ev->buttons() & Qt::LeftButton) { - moveCursor(xToPos(ev->pos().x()), true); - } - break; - default: - break; } } +#endif void QWidgetLineControl::processKeyEvent(QKeyEvent* event) { diff --git a/src/widgets/widgets/qwidgetlinecontrol_p.h b/src/widgets/widgets/qwidgetlinecontrol_p.h index 5fcb8527f0..4ffa9e4b31 100644 --- a/src/widgets/widgets/qwidgetlinecontrol_p.h +++ b/src/widgets/widgets/qwidgetlinecontrol_p.h @@ -308,7 +308,6 @@ public: void setFont(const QFont &font) { m_textLayout.setFont(font); updateDisplayText(); } void processInputMethodEvent(QInputMethodEvent *event); - void processMouseEvent(QMouseEvent* ev); void processKeyEvent(QKeyEvent* ev); int cursorBlinkPeriod() const { return m_blinkPeriod; } @@ -331,7 +330,9 @@ public: }; void draw(QPainter *, const QPoint &, const QRect &, int flags = DrawAll); - bool processEvent(QEvent *ev); +#ifndef QT_NO_SHORTCUT + void processShortcutOverrideEvent(QKeyEvent *ke); +#endif QTextLayout *textLayout() const {