diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2011-11-10 13:20:45 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-12-02 09:05:05 +0100 |
commit | 310d1c18f3462d5fc04efd69dc4a246a5819189d (patch) | |
tree | 86d35adcf6d460a186e0546ad562a212e01d05cb /src/qtquick1/graphicsitems | |
parent | e32eb8ee5d413ab6a908c2e3274645a489cb9df2 (diff) |
Use QWidgetLineControl in the QtQuick1 TextInput.
QDeclarative1TextInput and QLineEdit have the same compatbility
requirements so it makes sense they continue sharing the same line
control implementation. This allows the QtQuick 2 TextInput to diverge
without creating a third variation of QLineControl.
Task-number: QTBUG-22627
Change-Id: Ic06f66f1cb55e78f7129889a4877c3aba5ba72f6
Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src/qtquick1/graphicsitems')
-rw-r--r-- | src/qtquick1/graphicsitems/qdeclarativetextinput.cpp | 52 | ||||
-rw-r--r-- | src/qtquick1/graphicsitems/qdeclarativetextinput_p_p.h | 6 |
2 files changed, 29 insertions, 29 deletions
diff --git a/src/qtquick1/graphicsitems/qdeclarativetextinput.cpp b/src/qtquick1/graphicsitems/qdeclarativetextinput.cpp index d2760d116d..e5fdcb2387 100644 --- a/src/qtquick1/graphicsitems/qdeclarativetextinput.cpp +++ b/src/qtquick1/graphicsitems/qdeclarativetextinput.cpp @@ -561,7 +561,7 @@ QRect QDeclarative1TextInput::cursorRectangle() const Q_D(const QDeclarative1TextInput); QRect r = d->control->cursorRect(); // Scroll and make consistent with TextEdit - // QLineControl inexplicably adds 1 to the height and horizontal padding + // QWidgetLineControl inexplicably adds 1 to the height and horizontal padding // for unicode direction markers. r.adjust(5 - d->hscroll, 0, -4 - d->hscroll, -1); return r; @@ -905,7 +905,7 @@ void QDeclarative1TextInput::setEchoMode(QDeclarative1TextInput::EchoMode echo) Q_D(QDeclarative1TextInput); if (echoMode() == echo) return; - d->control->setEchoMode((QLineControl::EchoMode)echo); + d->control->setEchoMode(echo); d->updateInputMethodHints(); q_textChanged(); emit echoModeChanged(echoMode()); @@ -997,7 +997,7 @@ void QDeclarative1TextInput::createCursor() QDeclarative_setParent_noEvent(d->cursorItem, this); d->cursorItem->setParentItem(this); d->cursorItem->setX(d->control->cursorToX()); - d->cursorItem->setHeight(d->control->height()-1); // -1 to counter QLineControl's +1 which is not consistent with Text. + d->cursorItem->setHeight(d->control->height()-1); // -1 to counter QWidgetLineControl's +1 which is not consistent with Text. } /*! @@ -1064,7 +1064,7 @@ void QDeclarative1TextInputPrivate::focusChanged(bool hasFocus) focused = hasFocus; q->setCursorVisible(hasFocus && scene && scene->hasFocus()); if(!hasFocus && control->passwordEchoEditing()) - control->updatePasswordEchoEditing(false);//QLineControl sets it on key events, but doesn't deal with focus events + control->updatePasswordEchoEditing(false);//QWidgetLineControl sets it on key events, but doesn't deal with focus events if (!hasFocus) control->deselect(); QDeclarativeItemPrivate::focusChanged(hasFocus); @@ -1214,7 +1214,16 @@ void QDeclarative1TextInput::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) } } d->clickCausedFocus = 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()) QDeclarative1PaintedItem::mouseReleaseEvent(event); } @@ -1254,24 +1263,15 @@ bool QDeclarative1TextInput::sceneEvent(QEvent *event) bool QDeclarative1TextInput::event(QEvent* ev) { +#ifndef QT_NO_SHORTCUT Q_D(QDeclarative1TextInput); - //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::GraphicsSceneMousePress: - case QEvent::GraphicsSceneMouseMove: - case QEvent::GraphicsSceneMouseRelease: - case QEvent::GraphicsSceneMouseDoubleClick: - break; - default: - handled = d->control->processEvent(ev); + + if (ev->type() == QEvent::ShortcutOverride) { + d->control->processShortcutOverrideEvent(static_cast<QKeyEvent *>(ev)); + return ev->isAccepted(); } - if(!handled) - handled = QDeclarative1PaintedItem::event(ev); - return handled; +#endif + return QDeclarative1PaintedItem::event(ev); } void QDeclarative1TextInput::geometryChanged(const QRectF &newGeometry, @@ -1354,11 +1354,11 @@ void QDeclarative1TextInput::drawContents(QPainter *p, const QRect &r) p->setRenderHint(QPainter::TextAntialiasing, true); p->save(); p->setPen(QPen(d->color)); - int flags = QLineControl::DrawText; + int flags = QWidgetLineControl::DrawText; if(!isReadOnly() && d->cursorVisible && !d->cursorItem) - flags |= QLineControl::DrawCursor; + flags |= QWidgetLineControl::DrawCursor; if (d->control->hasSelectedText()) - flags |= QLineControl::DrawSelections; + flags |= QWidgetLineControl::DrawSelections; QPoint offset = QPoint(0,0); QFontMetrics fm = QFontMetrics(d->font); QRect br(boundingRect().toRect()); @@ -1387,7 +1387,7 @@ QVariant QDeclarative1TextInput::inputMethodQuery(Qt::InputMethodQuery property) case Qt::ImCursorPosition: return QVariant(d->control->cursor()); case Qt::ImSurroundingText: - if (d->control->echoMode() == QLineControl::PasswordEchoOnEdit + if (d->control->echoMode() == PasswordEchoOnEdit && !d->control->passwordEchoEditing()) return QVariant(displayText()); else @@ -1987,7 +1987,7 @@ void QDeclarative1TextInput::updateSize(bool needsRedraw) Q_D(QDeclarative1TextInput); int w = width(); int h = height(); - setImplicitHeight(d->control->height()-1); // -1 to counter QLineControl's +1 which is not consistent with Text. + setImplicitHeight(d->control->height()-1); // -1 to counter QWidgetLineControl's +1 which is not consistent with Text. setImplicitWidth(d->calculateTextWidth()); setContentsSize(QSize(width(), height()));//Repaints if changed if(w==width() && h==height() && needsRedraw){ diff --git a/src/qtquick1/graphicsitems/qdeclarativetextinput_p_p.h b/src/qtquick1/graphicsitems/qdeclarativetextinput_p_p.h index 4132db65f3..56f1fe312d 100644 --- a/src/qtquick1/graphicsitems/qdeclarativetextinput_p_p.h +++ b/src/qtquick1/graphicsitems/qdeclarativetextinput_p_p.h @@ -50,7 +50,7 @@ #include <QPointer> -#include <private/qlinecontrol_p.h> +#include <private/qwidgetlinecontrol_p.h> // // W A R N I N G @@ -70,7 +70,7 @@ class Q_AUTOTEST_EXPORT QDeclarative1TextInputPrivate : public QDeclarative1Impl { Q_DECLARE_PUBLIC(QDeclarative1TextInput) public: - QDeclarative1TextInputPrivate() : control(new QLineControl), + QDeclarative1TextInputPrivate() : control(new QWidgetLineControl), color((QRgb)0), style(QDeclarative1Text::Normal), styleColor((QRgb)0), hAlign(QDeclarative1TextInput::AlignLeft), mouseSelectionMode(QDeclarative1TextInput::SelectCharacters), inputMethodHints(Qt::ImhNone), @@ -109,7 +109,7 @@ public: bool sendMouseEventToInputContext(QGraphicsSceneMouseEvent *event, QEvent::Type eventType); void updateInputMethodHints(); - QLineControl* control; + QWidgetLineControl* control; QFont font; QFont sourceFont; |