diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-08-24 01:55:20 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-08-24 01:55:20 (GMT) |
commit | c9ed65f66a61c4149995dcc4c986a28ab2b4f124 (patch) | |
tree | ba6d6d71385707143f72c5dafb81f35302592d2d | |
parent | a750ae1a0b568cdd7e52a0c8aea456b0bae16f0d (diff) | |
parent | 23c9370fb8e25fc814fe057c7ad92f70f34a937b (diff) | |
download | Qt-c9ed65f66a61c4149995dcc4c986a28ab2b4f124.zip Qt-c9ed65f66a61c4149995dcc4c986a28ab2b4f124.tar.gz Qt-c9ed65f66a61c4149995dcc4c986a28ab2b4f124.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
-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 | ||||
-rw-r--r-- | src/declarative/util/qmllistmodel.cpp | 6 |
8 files changed, 193 insertions, 14 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; diff --git a/src/declarative/util/qmllistmodel.cpp b/src/declarative/util/qmllistmodel.cpp index e2575ab..51b0dae 100644 --- a/src/declarative/util/qmllistmodel.cpp +++ b/src/declarative/util/qmllistmodel.cpp @@ -72,7 +72,7 @@ struct ListModelData \qmlclass ListModel \brief The ListModel element defines a free-form list data source. - The ListModel is a simple hierarchy of items containing data roles. + The ListModel is a simple hierarchy of elements containing data roles. For example: \code @@ -93,8 +93,8 @@ struct ListModelData } \endcode - Item roles (properties) must begin with a lower-case letter. The above example defines a - ListModel containing three items, with the roles "name" and "cost". + Roles (properties) must begin with a lower-case letter. The above example defines a + ListModel containing three elements, with the roles "name" and "cost". The defined model can be used in views such as ListView: \code |