Make it possible to create WaylandSurfaceItem from QML
authorPaul Olav Tvete <paul.tvete@nokia.com>
Fri, 1 Apr 2011 15:10:46 +0000 (17:10 +0200)
committerPaul Olav Tvete <paul.tvete@nokia.com>
Fri, 1 Apr 2011 15:10:46 +0000 (17:10 +0200)
Rev-by: Samuel
src/qt-compositor/compositor_api/compositor_api.pri
src/qt-compositor/compositor_api/waylandcompositor.cpp
src/qt-compositor/compositor_api/waylandsurfaceitem.cpp
src/qt-compositor/compositor_api/waylandsurfaceitem.h

index d3378d8..e605c8c 100644 (file)
@@ -11,4 +11,6 @@ SOURCES += \
 contains(QT, declarative) {
     SOURCES += $$PWD/waylandsurfaceitem.cpp
     HEADERS += $$PWD/waylandsurfaceitem.h
+
+   DEFINES += QT_COMPOSITOR_DECLARATIVE
 }
index 29ec409..cbe49ff 100644 (file)
 #include "wayland_wrapper/wlcompositor.h"
 #include "wayland_wrapper/wlsurface.h"
 
+#ifdef QT_COMPOSITOR_DECLARATIVE
+#include "waylandsurfaceitem.h"
+#endif
+
 WaylandCompositor::WaylandCompositor(QWidget *topLevelWidget)
     : m_compositor(0)
     , m_toplevel_widget(topLevelWidget)
 {
     m_compositor = new Wayland::Compositor(this);
+#ifdef QT_COMPOSITOR_DECLARATIVE
+    qmlRegisterType<WaylandSurfaceItem>("WaylandCompositor", 1, 0, "WaylandSurfaceItem");
+    qRegisterMetaType<WaylandSurface*>("WaylandSurface*");
+#endif
 }
 
 WaylandCompositor::~WaylandCompositor()
index 66927a3..6966da2 100644 (file)
@@ -99,11 +99,28 @@ void WaylandSurfaceTextureProvider::surfaceDamaged(const QRect &)
     emit textureChanged();
 }
 
+WaylandSurfaceItem::WaylandSurfaceItem(QSGItem *parent)
+    : QSGItem(parent)
+    , m_surface(0)
+    , m_textureProvider(0)
+{
+}
+
 WaylandSurfaceItem::WaylandSurfaceItem(WaylandSurface *surface, QSGItem *parent)
     : QSGItem(parent)
-    , m_surface(surface)
-    , m_textureProvider(new WaylandSurfaceTextureProvider(surface))
+    , m_surface(0)
+    , m_textureProvider(0)
+{
+    init(surface);
+}
+
+void WaylandSurfaceItem::init(WaylandSurface *surface)
 {
+    if (!surface)
+        return;
+    m_surface = surface;
+    m_textureProvider = new WaylandSurfaceTextureProvider(surface);
+
     setWidth(surface->geometry().width());
     setHeight(surface->geometry().height());
 
@@ -119,6 +136,10 @@ WaylandSurfaceItem::~WaylandSurfaceItem()
     delete m_textureProvider;
 }
 
+void WaylandSurfaceItem::setSurface(WaylandSurface *surface)
+{
+    init(surface);
+}
 
 QSGTextureProvider *WaylandSurfaceItem::textureProvider() const
 {
index f335732..aa9b8a4 100644 (file)
 
 class WaylandSurface;
 class WaylandSurfaceTextureProvider;
+Q_DECLARE_METATYPE(WaylandSurface*)
 
 class WaylandSurfaceItem : public QSGItem, public QSGTextureProviderInterface
 {
     Q_OBJECT
     Q_INTERFACES(QSGTextureProviderInterface)
+    Q_PROPERTY(WaylandSurface* surface READ surface WRITE setSurface)
+
 public:
+    WaylandSurfaceItem(QSGItem *parent = 0);
     WaylandSurfaceItem(WaylandSurface *surface, QSGItem *parent = 0);
     ~WaylandSurfaceItem();
 
+    void setSurface(WaylandSurface *surface);
+    WaylandSurface *surface() const {return m_surface; }
+
     QSGTextureProvider *textureProvider() const;
 
 protected:
@@ -76,6 +83,7 @@ protected:
 
 private:
     QPoint toSurface(const QPointF &pos) const;
+    void init(WaylandSurface *);
 
     WaylandSurface *m_surface;
     WaylandSurfaceTextureProvider *m_textureProvider;