diff options
-rw-r--r-- | demos/declarative/webbrowser/fieldtext/FieldText.qml | 5 | ||||
-rw-r--r-- | examples/declarative/webview/content/FieldText.qml | 163 | ||||
-rw-r--r-- | examples/declarative/webview/content/SpinSquare.qml | 4 | ||||
-rw-r--r-- | examples/declarative/webview/content/pics/cancel.png | bin | 0 -> 1038 bytes | |||
-rw-r--r-- | examples/declarative/webview/content/pics/ok.png | bin | 0 -> 655 bytes | |||
-rw-r--r-- | src/declarative/fx/qfxwebview.cpp | 23 | ||||
-rw-r--r-- | src/declarative/fx/qfxwebview.h | 6 |
7 files changed, 190 insertions, 11 deletions
diff --git a/demos/declarative/webbrowser/fieldtext/FieldText.qml b/demos/declarative/webbrowser/fieldtext/FieldText.qml index 976785b..fe55185 100644 --- a/demos/declarative/webbrowser/fieldtext/FieldText.qml +++ b/demos/declarative/webbrowser/fieldtext/FieldText.qml @@ -60,7 +60,7 @@ Item { opacity: 0 } - LineEdit { + TextInput { id: textEdit text: fieldText.text focus: false @@ -72,8 +72,7 @@ Item { color: "black" font.bold: true readOnly: true - Keys.onEnterPressed: confirm() - Keys.onReturnPressed: confirm() + onAccepted: confirm() Keys.onEscapePressed: reset() } diff --git a/examples/declarative/webview/content/FieldText.qml b/examples/declarative/webview/content/FieldText.qml new file mode 100644 index 0000000..fe55185 --- /dev/null +++ b/examples/declarative/webview/content/FieldText.qml @@ -0,0 +1,163 @@ +import Qt 4.6 + +Item { + id: fieldText + height: 30 + property string text: "" + property string label: "" + property bool mouseGrabbed: false + signal confirmed + signal cancelled + signal startEdit + + resources: [ + Script { + + function edit() { + if (!mouseGrabbed) { + fieldText.startEdit(); + fieldText.state='editing'; + mouseGrabbed=true; + } + } + + function confirm() { + fieldText.state=''; + fieldText.text = textEdit.text; + mouseGrabbed=false; + fieldText.confirmed(); + } + + function reset() { + textEdit.text = fieldText.text; + fieldText.state=''; + mouseGrabbed=false; + fieldText.cancelled(); + } + + } + ] + + Image { + id: cancelIcon + width: 22 + height: 22 + anchors.right: parent.right + anchors.rightMargin: 4 + anchors.verticalCenter: parent.verticalCenter + source: "pics/cancel.png" + opacity: 0 + } + + Image { + id: confirmIcon + width: 22 + height: 22 + anchors.left: parent.left + anchors.leftMargin: 4 + anchors.verticalCenter: parent.verticalCenter + source: "pics/ok.png" + opacity: 0 + } + + TextInput { + id: textEdit + text: fieldText.text + focus: false + anchors.left: parent.left + anchors.leftMargin: 0 + anchors.right: parent.right + anchors.rightMargin: 0 + anchors.verticalCenter: parent.verticalCenter + color: "black" + font.bold: true + readOnly: true + onAccepted: confirm() + Keys.onEscapePressed: reset() + } + + Text { + id: textLabel + x: 5 + width: parent.width-10 + anchors.verticalCenter: parent.verticalCenter + horizontalAlignment: "AlignHCenter" + color: fieldText.state == "editing" ? "#505050" : "#AAAAAA" + font.italic: true + font.bold: true + text: label + opacity: textEdit.text == '' ? 1 : 0 + opacity: Behavior { + NumberAnimation { + property: "opacity" + duration: 250 + } + } + } + + MouseRegion { + anchors.fill: cancelIcon + onClicked: { reset() } + } + + MouseRegion { + anchors.fill: confirmIcon + onClicked: { confirm() } + } + + MouseRegion { + id: editRegion + anchors.fill: textEdit + onClicked: { edit() } + } + + states: [ + State { + name: "editing" + PropertyChanges { + target: confirmIcon + opacity: 1 + } + PropertyChanges { + target: cancelIcon + opacity: 1 + } + PropertyChanges { + target: textEdit + color: "black" + readOnly: false + focus: true + selectionStart: 0 + selectionEnd: -1 + } + PropertyChanges { + target: editRegion + opacity: 0 + } + PropertyChanges { + target: textEdit.anchors + leftMargin: 34 + } + PropertyChanges { + target: textEdit.anchors + rightMargin: 34 + } + } + ] + + transitions: [ + Transition { + from: "" + to: "*" + reversible: true + NumberAnimation { + properties: "opacity,leftMargin,rightMargin" + duration: 200 + } + ColorAnimation { + property: "color" + duration: 150 + } + } + ] +} diff --git a/examples/declarative/webview/content/SpinSquare.qml b/examples/declarative/webview/content/SpinSquare.qml index 57ad697..6d5ada3 100644 --- a/examples/declarative/webview/content/SpinSquare.qml +++ b/examples/declarative/webview/content/SpinSquare.qml @@ -1,8 +1,8 @@ import Qt 4.6 Item { - properties var period : 250 - properties var color : "black" + property var period : 250 + propert var color : "black" id: Root Item { diff --git a/examples/declarative/webview/content/pics/cancel.png b/examples/declarative/webview/content/pics/cancel.png Binary files differnew file mode 100644 index 0000000..ecc9533 --- /dev/null +++ b/examples/declarative/webview/content/pics/cancel.png diff --git a/examples/declarative/webview/content/pics/ok.png b/examples/declarative/webview/content/pics/ok.png Binary files differnew file mode 100644 index 0000000..5795f04 --- /dev/null +++ b/examples/declarative/webview/content/pics/ok.png diff --git a/src/declarative/fx/qfxwebview.cpp b/src/declarative/fx/qfxwebview.cpp index a7d233f..9fc469a 100644 --- a/src/declarative/fx/qfxwebview.cpp +++ b/src/declarative/fx/qfxwebview.cpp @@ -131,6 +131,8 @@ public: QWebSettings *s; }; +QML_DECLARE_TYPE(QFxWebSettings) +QML_DEFINE_NOCREATE_TYPE(QFxWebSettings) class QFxWebViewPrivate : public QFxPaintedItemPrivate { @@ -951,7 +953,7 @@ QWebPage *QFxWebView::page() const } \endqml */ -QObject *QFxWebView::settingsObject() const +QFxWebSettings *QFxWebView::settingsObject() const { Q_D(const QFxWebView); d->settings.s = page()->settings(); @@ -1101,22 +1103,35 @@ public: QmlEngine *engine = qmlEngine(webview); component = new QmlComponent(engine, url, this); item = 0; - if (component->isReady()) - qmlLoaded(); - else + if (component->isLoading()) connect(component, SIGNAL(statusChanged(QmlComponent::Status)), this, SLOT(qmlLoaded())); + else + qmlLoaded(); } public Q_SLOTS: void qmlLoaded() { + if (component->isError()) { + // XXX Could instead give these errors to the WebView to handle. + foreach (QmlError err, component->errors()) + qWarning(err.toString().toLatin1()); + return; + } item = qobject_cast<QFxItem*>(component->create(qmlContext(webview))); item->setParent(webview); + QString jsObjName; for (int i=0; i<propertyNames.count(); ++i) { if (propertyNames[i] != QLatin1String("type") && propertyNames[i] != QLatin1String("data")) { item->setProperty(propertyNames[i].toLatin1(),propertyValues[i]); + if (propertyNames[i] == QLatin1String("objectname")) + jsObjName = propertyValues[i]; } } + if (!jsObjName.isNull()) { + QWebFrame *f = webview->page()->mainFrame(); + f->addToJavaScriptWindowObject(jsObjName, item); + } resizeEvent(0); delete component; component = 0; diff --git a/src/declarative/fx/qfxwebview.h b/src/declarative/fx/qfxwebview.h index d619e94..d84a01c 100644 --- a/src/declarative/fx/qfxwebview.h +++ b/src/declarative/fx/qfxwebview.h @@ -75,6 +75,8 @@ private: class QFxWebViewAttached; +class QFxWebSettings; + class Q_DECLARATIVE_EXPORT QFxWebView : public QFxPaintedItem { Q_OBJECT @@ -103,7 +105,7 @@ class Q_DECLARATIVE_EXPORT QFxWebView : public QFxPaintedItem Q_PROPERTY(QObject* forward READ forwardAction CONSTANT) Q_PROPERTY(QObject* stop READ stopAction CONSTANT) - Q_PROPERTY(QObject* settings READ settingsObject CONSTANT) + Q_PROPERTY(QFxWebSettings* settings READ settingsObject CONSTANT) Q_PROPERTY(QmlList<QObject *>* javaScriptWindowObjects READ javaScriptWindowObjects CONSTANT) @@ -157,7 +159,7 @@ public: QWebHistory *history() const; QWebSettings *settings() const; - QObject *settingsObject() const; + QFxWebSettings *settingsObject() const; QString status() const; |