From d8da1372ae23f31bdfe465623d9646bb81008e16 Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Fri, 11 Nov 2011 10:06:41 +1000 Subject: [PATCH] Remove unused code from QQuickLineControl. Task-number: QTBUG-22627 Change-Id: I234977638ac6d42ad0fa648ae366823e5c542ed6 Reviewed-by: Martin Jones --- src/quick/items/qquicklinecontrol.cpp | 212 ---------------------------------- src/quick/items/qquicklinecontrol_p.h | 11 +- src/quick/items/qquicktextinput.cpp | 74 +++++++++--- 3 files changed, 58 insertions(+), 239 deletions(-) diff --git a/src/quick/items/qquicklinecontrol.cpp b/src/quick/items/qquicklinecontrol.cpp index 2d689cf..6daf4b1 100644 --- a/src/quick/items/qquicklinecontrol.cpp +++ b/src/quick/items/qquicklinecontrol.cpp @@ -569,55 +569,6 @@ void QQuickLineControl::processInputMethodEvent(QInputMethodEvent *event) /*! \internal - Draws the display text for the line control using the given - \a painter, \a clip, and \a offset. Which aspects of the display text - are drawn is specified by the given \a flags. - - If the flags contain DrawSelections, then the selection or input mask - backgrounds and foregrounds will be applied before drawing the text. - - If the flags contain DrawCursor a cursor of the current cursorWidth() - will be drawn after drawing the text. - - The display text will only be drawn if the flags contain DrawText -*/ -void QQuickLineControl::draw(QPainter *painter, const QPoint &offset, const QRect &clip, int flags) -{ - QVector selections; - if (flags & DrawSelections) { - QTextLayout::FormatRange o; - if (m_selstart < m_selend) { - o.start = m_selstart; - o.length = m_selend - m_selstart; - o.format.setBackground(m_palette.brush(QPalette::Highlight)); - o.format.setForeground(m_palette.brush(QPalette::HighlightedText)); - } else { - // mask selection - if (!m_blinkPeriod || m_blinkStatus){ - o.start = m_cursor; - o.length = 1; - o.format.setBackground(m_palette.brush(QPalette::Text)); - o.format.setForeground(m_palette.brush(QPalette::Window)); - } - } - selections.append(o); - } - - if (flags & DrawText) - m_textLayout.draw(painter, offset, selections, clip); - - if (flags & DrawCursor){ - int cursor = m_cursor; - if (m_preeditCursor != -1) - cursor += m_preeditCursor; - if (!m_hideCursor && (!m_blinkPeriod || m_blinkStatus)) - m_textLayout.drawCursor(painter, offset, cursor, m_cursorWidth); - } -} - -/*! - \internal - Sets the selection to cover the word at the given cursor position. The word boundaries are defined by the behavior of QTextLayout::SkipWords cursor mode. @@ -1364,144 +1315,6 @@ void QQuickLineControl::timerEvent(QTimerEvent *event) killTimer(m_deleteAllTimer); m_deleteAllTimer = 0; clear(); - } else if (event->timerId() == m_tripleClickTimer) { - killTimer(m_tripleClickTimer); - m_tripleClickTimer = 0; - } -} - -bool QQuickLineControl::processEvent(QEvent* ev) -{ -#ifdef QT_KEYPAD_NAVIGATION - if (QGuiApplication::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()){ - 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 QQuickLineControl::processMouseEvent(QMouseEvent* ev) -{ - - switch (ev->type()) { - case QEvent::MouseButtonPress:{ - if (m_tripleClickTimer - && (ev->localPos() - m_tripleClick).manhattanLength() < qApp->styleHints()->startDragDistance()) { - selectAll(); - return; - } - if (ev->button() == Qt::RightButton) - return; - - bool mark = ev->modifiers() & Qt::ShiftModifier; - int cursor = xToPos(ev->localPos().x()); - moveCursor(cursor, mark); - break; - } - case QEvent::MouseButtonDblClick: - if (ev->button() == Qt::LeftButton) { - selectWordAtPos(xToPos(ev->localPos().x())); - if (m_tripleClickTimer) - killTimer(m_tripleClickTimer); - m_tripleClickTimer = startTimer(qApp->styleHints()->mouseDoubleClickInterval()); - m_tripleClick = ev->localPos(); - } - break; - case QEvent::MouseButtonRelease: -#ifndef QT_NO_CLIPBOARD - if (QGuiApplication::clipboard()->supportsSelection()) { - if (ev->button() == Qt::LeftButton) { - copy(QClipboard::Selection); - } else if (!isReadOnly() && ev->button() == Qt::MidButton) { - deselect(); - insert(QGuiApplication::clipboard()->text(QClipboard::Selection)); - } - } -#endif - break; - case QEvent::MouseMove: - if (ev->buttons() & Qt::LeftButton) { - moveCursor(xToPos(ev->localPos().x()), true); - } - break; - default: - break; } } @@ -1525,12 +1338,6 @@ void QQuickLineControl::processKeyEvent(QKeyEvent* event) && !passwordEchoEditing() && !isReadOnly() && !event->text().isEmpty() -#ifdef QT_KEYPAD_NAVIGATION - && event->key() != Qt::Key_Select - && event->key() != Qt::Key_Up - && event->key() != Qt::Key_Down - && event->key() != Qt::Key_Back -#endif && !(event->modifiers() & Qt::ControlModifier)) { // Clear the edit and reset to normal echo mode while editing; the // echo mode switches back when the edit loses focus @@ -1677,25 +1484,6 @@ void QQuickLineControl::processKeyEvent(QKeyEvent* event) backspace(); } break; -#ifdef QT_KEYPAD_NAVIGATION - case Qt::Key_Back: - if (QGuiApplication::keypadNavigationEnabled() && !event->isAutoRepeat() - && !isReadOnly()) { - if (text().length() == 0) { - setText(m_cancelText); - - if (passwordEchoEditing()) - updatePasswordEchoEditing(false); - - emit editFocusChange(false); - } else if (!m_deleteAllTimer) { - m_deleteAllTimer = startTimer(750); - } - } else { - unknown = true; - } - break; -#endif default: if (!handled) unknown = true; diff --git a/src/quick/items/qquicklinecontrol_p.h b/src/quick/items/qquicklinecontrol_p.h index 4c09e04..e80fad7 100644 --- a/src/quick/items/qquicklinecontrol_p.h +++ b/src/quick/items/qquicklinecontrol_p.h @@ -78,10 +78,10 @@ public: QQuickLineControl(const QString &txt = QString()) : m_cursor(0), m_preeditCursor(0), m_cursorWidth(0), m_layoutDirection(Qt::LayoutDirectionAuto), m_hideCursor(false), m_separator(0), m_readOnly(0), - m_dragEnabled(0), m_echoMode(Normal), m_textDirty(0), m_selDirty(0), + m_echoMode(Normal), m_textDirty(0), m_selDirty(0), m_validInput(1), m_blinkStatus(0), m_blinkPeriod(0), m_blinkTimer(0), m_deleteAllTimer(0), m_ascent(0), m_maxLength(32767), m_lastCursorPos(-1), - m_tripleClickTimer(0), m_maskData(0), m_modifiedState(0), m_undoState(0), + m_maskData(0), m_modifiedState(0), m_undoState(0), m_selstart(0), m_selend(0), m_passwordEchoEditing(false) { init(txt); @@ -314,7 +314,6 @@ public: DrawCursor = 0x04, DrawAll = DrawText | DrawSelections | DrawCursor }; - void draw(QPainter *, const QPoint &, const QRect &, int flags = DrawAll); bool processEvent(QEvent *ev); @@ -352,7 +351,6 @@ private: uint m_hideCursor : 1; // used to hide the m_cursor inside preedit areas uint m_separator : 1; uint m_readOnly : 1; - uint m_dragEnabled : 1; uint m_echoMode : 2; uint m_textDirty : 1; uint m_selDirty : 1; @@ -365,8 +363,6 @@ private: int m_maxLength; int m_lastCursorPos; QList m_transactions; - QPointF m_tripleClick; - int m_tripleClickTimer; QString m_cancelText; void emitCursorPositionChanged(); @@ -437,9 +433,6 @@ Q_SIGNALS: void editingFinished(); void updateNeeded(const QRect &); -#ifdef QT_KEYPAD_NAVIGATION - void editFocusChange(bool); -#endif protected: virtual void timerEvent(QTimerEvent *event); diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp index a21deb6..3752523 100644 --- a/src/quick/items/qquicktextinput.cpp +++ b/src/quick/items/qquicktextinput.cpp @@ -1172,7 +1172,16 @@ void QQuickTextInput::mouseReleaseEvent(QMouseEvent *event) d->selectPressed = false; setKeepMouseGrab(false); } - d->control->processEvent(event); +#ifndef QT_NO_CLIPBOARD + if (QGuiApplication::clipboard()->supportsSelection()) { + if (event->button() == Qt::LeftButton) { + d->control->copy(QClipboard::Selection); + } else if (!isReadOnly() && event->button() == Qt::MidButton) { + d->control->deselect(); + d->control->insert(QGuiApplication::clipboard()->text(QClipboard::Selection)); + } + } +#endif if (!event->isAccepted()) QQuickImplicitSizeItem::mouseReleaseEvent(event); } @@ -1207,24 +1216,53 @@ void QQuickTextInput::mouseUngrabEvent() bool QQuickTextInput::event(QEvent* ev) { - Q_D(QQuickTextInput); - //Anything we don't deal with ourselves, pass to the control - bool handled = false; - switch (ev->type()) { - case QEvent::KeyPress: - case QEvent::KeyRelease://###Should the control be doing anything with release? - case QEvent::InputMethod: - case QEvent::MouseButtonPress: - case QEvent::MouseMove: - case QEvent::MouseButtonRelease: - case QEvent::MouseButtonDblClick: - break; - default: - handled = d->control->processEvent(ev); +#ifndef QT_NO_SHORTCUT + if (ev->type() == 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(); + return true; + } 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: + return true; + default: + break; + } + } + } } - if (!handled) - handled = QQuickImplicitSizeItem::event(ev); - return handled; +#endif + + return QQuickImplicitSizeItem::event(ev); } void QQuickTextInput::geometryChanged(const QRectF &newGeometry, -- 2.7.4