From c0ea7090a6db60c315dae3534fcaf05d1b2591e1 Mon Sep 17 00:00:00 2001 From: Tapani Mikola Date: Thu, 13 Aug 2009 22:20:13 +0300 Subject: Fix to QFxWebView to show cursor in focused text input. Correction textedit and lineedit so that they emit focuschanged signals. Clean ups to webbrowser.qml. --- .../declarative/webbrowser/fieldtext/FieldText.qml | 28 ++++++---------------- demos/declarative/webbrowser/webbrowser.qml | 1 - src/declarative/fx/qfxlineedit.cpp | 1 + src/declarative/fx/qfxtextedit.cpp | 1 + src/declarative/fx/qfxwebview.cpp | 17 ++++++++++++- src/declarative/fx/qfxwebview.h | 1 + 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/demos/declarative/webbrowser/fieldtext/FieldText.qml b/demos/declarative/webbrowser/fieldtext/FieldText.qml index d822d65..3a9abdf 100644 --- a/demos/declarative/webbrowser/fieldtext/FieldText.qml +++ b/demos/declarative/webbrowser/fieldtext/FieldText.qml @@ -17,7 +17,6 @@ Item { if (!mouseGrabbed) { fieldText.startEdit(); fieldText.state='editing'; - textEdit.selectAll(); mouseGrabbed=true; } } @@ -61,7 +60,7 @@ Item { opacity: 0 } - TextEdit { + LineEdit { id: textEdit text: fieldText.text focus: false @@ -73,7 +72,9 @@ Item { color: "black" font.bold: true readOnly: true - wrap: false + Keys.onEnterPressed: confirm() + Keys.onReturnPressed: confirm() + Keys.onEscapePressed: reset() } Text { @@ -95,20 +96,6 @@ Item { } } - KeyProxy { - id: proxy - focus: false - anchors.fill: parent - targets: [keyActions,textEdit] - } - - Item { - id: keyActions - Keys.onEnterPressed: confirm() - Keys.onReturnPressed: confirm() - Keys.onEscapePressed: reset() - } - MouseRegion { anchors.fill: cancelIcon onClicked: { reset() } @@ -140,6 +127,9 @@ Item { target: textEdit color: "black" readOnly: false + focus: true + selectionStart: 0 + selectionEnd: -1 } SetProperties { target: editRegion @@ -153,10 +143,6 @@ Item { target: textEdit.anchors rightMargin: 34 } - SetProperties { - target: proxy - focus: true - } } ] diff --git a/demos/declarative/webbrowser/webbrowser.qml b/demos/declarative/webbrowser/webbrowser.qml index efa8532..73fedae 100644 --- a/demos/declarative/webbrowser/webbrowser.qml +++ b/demos/declarative/webbrowser/webbrowser.qml @@ -80,7 +80,6 @@ Item { id: HeaderText text: MyWebView.title!='' || MyWebView.progress == 1.0 ? MyWebView.title : 'Loading...' - //text: MyWebView.url elide: "ElideRight" color: "white" diff --git a/src/declarative/fx/qfxlineedit.cpp b/src/declarative/fx/qfxlineedit.cpp index e1d9f14..ccb0637 100644 --- a/src/declarative/fx/qfxlineedit.cpp +++ b/src/declarative/fx/qfxlineedit.cpp @@ -467,6 +467,7 @@ void QFxLineEdit::focusChanged(bool hasFocus) Q_D(QFxLineEdit); d->focused = hasFocus; setCursorVisible(hasFocus); + emit QFxItem::focusChanged(); } void QFxLineEdit::keyPressEvent(QKeyEvent* ev) diff --git a/src/declarative/fx/qfxtextedit.cpp b/src/declarative/fx/qfxtextedit.cpp index 3013ac2..379e12f 100644 --- a/src/declarative/fx/qfxtextedit.cpp +++ b/src/declarative/fx/qfxtextedit.cpp @@ -885,6 +885,7 @@ void QFxTextEdit::keyReleaseEvent(QKeyEvent *event) void QFxTextEdit::focusChanged(bool hasFocus) { setCursorVisible(hasFocus); + emit QFxItem::focusChanged(); } /*! diff --git a/src/declarative/fx/qfxwebview.cpp b/src/declarative/fx/qfxwebview.cpp index 797e6cb..6645a0f 100644 --- a/src/declarative/fx/qfxwebview.cpp +++ b/src/declarative/fx/qfxwebview.cpp @@ -440,6 +440,20 @@ QVariant QFxWebView::evaluateJavaScript(const QString &scriptSource) return this->page()->mainFrame()->evaluateJavaScript(scriptSource); } +void QFxWebView::focusChanged(bool flag) +{ + QFocusEvent *e; + if (flag) { + e = new QFocusEvent (QEvent::FocusIn); + } + else { + e = new QFocusEvent (QEvent::FocusOut); + } + page()->event(e); + delete e; + emit QFxItem::focusChanged(); +} + void QFxWebView::expandToWebPage() { Q_D(QFxWebView); @@ -702,6 +716,7 @@ void QFxWebView::mousePressEvent(QGraphicsSceneMouseEvent *event) { Q_D(QFxWebView); if (d->interactive) { + setFocus (true); QMouseEvent *me = sceneMouseEventToMouseEvent(event); if (d->lastPress) delete d->lastPress; d->lastPress = me; @@ -709,7 +724,7 @@ void QFxWebView::mousePressEvent(QGraphicsSceneMouseEvent *event) event->setAccepted( /* It is not correct to send the press event upwards, if it is not accepted by WebKit - e.g. push button does not work, if done so as QGraohucsScene will not send the release event at all to WebKit + e.g. push button does not work, if done so as QGraphicsScene will not send the release event at all to WebKit Might be a bug in WebKit, though */ #if 1 //QT_VERSION <= 0x040500 // XXX see bug 230835 diff --git a/src/declarative/fx/qfxwebview.h b/src/declarative/fx/qfxwebview.h index 9003377..498cf2e 100644 --- a/src/declarative/fx/qfxwebview.h +++ b/src/declarative/fx/qfxwebview.h @@ -211,6 +211,7 @@ protected: void timerEvent(QTimerEvent *event); virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); + virtual void focusChanged(bool); private: void init(); -- cgit v0.12