aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLauro Neto <lauro.neto@openbossa.org>2011-08-08 14:43:14 -0300
committerLauro Neto <lauro.neto@openbossa.org>2011-08-08 15:26:09 -0300
commite1cd2f6675dae7ccec0f7c45cb42c356cdd14d68 (patch)
treeef9fd10e16e35e490af4ecba416c6c332a8ba96f /examples
parent4b3b716e1ce648d406d487e33ba355ed71e472d2 (diff)
Add qml-webkit-plugin example.
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org> Reviewer: Hugo Lima <hugo.lima@openbossa.org>
Diffstat (limited to 'examples')
-rw-r--r--examples/webkit/qml-webkit-plugin/HelloWorld.qml21
-rw-r--r--examples/webkit/qml-webkit-plugin/index.html5
-rw-r--r--examples/webkit/qml-webkit-plugin/main.py66
3 files changed, 92 insertions, 0 deletions
diff --git a/examples/webkit/qml-webkit-plugin/HelloWorld.qml b/examples/webkit/qml-webkit-plugin/HelloWorld.qml
new file mode 100644
index 0000000..98e0ab7
--- /dev/null
+++ b/examples/webkit/qml-webkit-plugin/HelloWorld.qml
@@ -0,0 +1,21 @@
+import QtQuick 1.1
+
+Rectangle {
+ id: root
+ width: 300
+ height: 300
+ color: "red"
+
+ Text {
+ text: "Hello World!"
+ font.pixelSize: 30
+ anchors.centerIn: parent
+
+ NumberAnimation on rotation {
+ from: 0
+ to: 360
+ duration: 2000
+ loops: Animation.Infinite
+ }
+ }
+}
diff --git a/examples/webkit/qml-webkit-plugin/index.html b/examples/webkit/qml-webkit-plugin/index.html
new file mode 100644
index 0000000..dd500fa
--- /dev/null
+++ b/examples/webkit/qml-webkit-plugin/index.html
@@ -0,0 +1,5 @@
+<html><body>
+ <h1>QML Plugin</h1>
+ <object type="application/x-qml" data="./HelloWorld.qml" width="300" height="300">
+ </object>
+</body></html>
diff --git a/examples/webkit/qml-webkit-plugin/main.py b/examples/webkit/qml-webkit-plugin/main.py
new file mode 100644
index 0000000..62e83d3
--- /dev/null
+++ b/examples/webkit/qml-webkit-plugin/main.py
@@ -0,0 +1,66 @@
+
+'''QML PLugin for WebKit.
+
+Adapted from QtLabs[1].
+
+Usage: python main.py index.html
+
+[1] http://blog.qtlabs.org.br/2011/05/30/transformando-o-qml-no-proximo-flash/
+'''
+import sys
+
+from PySide.QtCore import QUrl
+from PySide.QtGui import QApplication
+from PySide.QtDeclarative import QDeclarativeView
+from PySide.QtWebKit import QWebPluginFactory, QWebView, QWebSettings
+
+class PluginFactory(QWebPluginFactory):
+
+ def plugins(self):
+ plugins = []
+
+ mime = self.MimeType()
+ mime.name = 'QmlFile'
+ mime.fileExtensions = ['.qml']
+
+ plugin = self.Plugin()
+ plugin.name = 'QmlPlugin'
+ plugin.mimeTypes = [mime]
+
+ plugins.append(plugin)
+
+ return plugins
+
+ def create(self, mimeType, url, argumentNames, argumentValues):
+ if mimeType != 'application/x-qml':
+ return None
+
+ for name, value in zip(argumentNames, argumentValues):
+ if name == 'width':
+ width = int(value)
+ elif name == 'height':
+ height = int(value)
+
+ view = QDeclarativeView()
+ view.resize(width, height)
+ view.setSource(url)
+
+ return view
+
+def main():
+
+ app = QApplication([])
+
+ view = QWebView()
+ fac = PluginFactory()
+ view.page().setPluginFactory(fac)
+ QWebSettings.globalSettings().setAttribute(QWebSettings.PluginsEnabled, True)
+
+ view.load(QUrl(sys.argv[1]))
+
+ view.resize(840, 600)
+ view.show()
+
+ return app.exec_()
+if __name__ == '__main__':
+ main()