contains(QT, declarative) {
SOURCES += $$PWD/waylandsurfaceitem.cpp
HEADERS += $$PWD/waylandsurfaceitem.h
+
+ DEFINES += QT_COMPOSITOR_DECLARATIVE
}
#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()
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());
delete m_textureProvider;
}
+void WaylandSurfaceItem::setSurface(WaylandSurface *surface)
+{
+ init(surface);
+}
QSGTextureProvider *WaylandSurfaceItem::textureProvider() const
{
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:
private:
QPoint toSurface(const QPointF &pos) const;
+ void init(WaylandSurface *);
WaylandSurface *m_surface;
WaylandSurfaceTextureProvider *m_textureProvider;