diff options
author | Paul Olav Tvete <paul.tvete@theqtcompany.com> | 2015-12-14 15:46:11 +0100 |
---|---|---|
committer | Paul Olav Tvete <paul.tvete@theqtcompany.com> | 2016-04-20 13:13:50 +0000 |
commit | 5cfdd57ddaac7ea1c1fc1189fb03aa716d3ed128 (patch) | |
tree | a8f30864e62d84f090b408910941bb9f32e7498b | |
parent | 33e89749bcf88932e7c3dd515ffcc4da911a765d (diff) | |
download | qtwayland-5cfdd57ddaac7ea1c1fc1189fb03aa716d3ed128.tar.gz |
QML API for subsurfaces
Task-number: QTBUG-49809
Change-Id: I433fd5ee4d920e6fc6696627b45738631ab329c4
Reviewed-by: Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
-rw-r--r-- | src/compositor/compositor_api/qwaylandquickitem.cpp | 68 | ||||
-rw-r--r-- | src/compositor/compositor_api/qwaylandquickitem.h | 9 | ||||
-rw-r--r-- | src/compositor/compositor_api/qwaylandquickitem_p.h | 1 |
3 files changed, 76 insertions, 2 deletions
diff --git a/src/compositor/compositor_api/qwaylandquickitem.cpp b/src/compositor/compositor_api/qwaylandquickitem.cpp index bee12b4a..ded65e87 100644 --- a/src/compositor/compositor_api/qwaylandquickitem.cpp +++ b/src/compositor/compositor_api/qwaylandquickitem.cpp @@ -486,6 +486,62 @@ void QWaylandQuickItem::surfaceChangedEvent(QWaylandSurface *newSurface, QWaylan Q_UNUSED(oldSurface); } +void QWaylandQuickItem::handleSubsurfaceAdded(QWaylandSurface *childSurface) +{ + Q_D(QWaylandQuickItem); + if (d->subsurfaceHandler.isNull()) { + QWaylandQuickItem *childItem = new QWaylandQuickItem; + childItem->setSurface(childSurface); + childItem->setVisible(true); + childItem->setParentItem(this); + connect(childSurface, &QWaylandSurface::subsurfacePositionChanged, childItem, &QWaylandQuickItem::handleSubsurfacePosition); + } else { + bool success = QMetaObject::invokeMethod(d->subsurfaceHandler, "handleSubsurfaceAdded", Q_ARG(QWaylandSurface *, childSurface)); + if (!success) + qWarning("QWaylandQuickItem: subsurfaceHandler does not implement handleSubsurfaceAdded()"); + } +} + + + +/*! + \qmlproperty bool QtWaylandCompositor::WaylandQuickItem::subsurfaceHandler + + This property provides a way to override the default subsurface behavior. + + By default, Qt will create a new SurfaceItem as a child of this item, and maintain the correct position. + + To override the default, assign a handler object to this property. The handler should implement + a handleSubsurfaceAdded(WaylandSurface) function. + + \code + ShellSurfaceItem { + subsurfaceHandler: QtObject { + function handleSubsurfaceAdded(child) { + //create custom surface item, and connect the subsurfacePositionChanged signal + } + } + \endcode + + The default value of this property is \c null. + */ + + +QObject *QWaylandQuickItem::subsurfaceHandler() const +{ + Q_D(const QWaylandQuickItem); + return d->subsurfaceHandler.data(); +} + +void QWaylandQuickItem::setSubsurfaceHandler(QObject *handler) +{ + Q_D(QWaylandQuickItem); + if (d->subsurfaceHandler.data() != handler) { + d->subsurfaceHandler = handler; + emit subsurfaceHandlerChanged(); + } +} + /*! * \internal */ @@ -498,6 +554,7 @@ void QWaylandQuickItem::handleSurfaceChanged() disconnect(d->oldSurface, &QWaylandSurface::sizeChanged, this, &QWaylandQuickItem::updateSize); disconnect(d->oldSurface, &QWaylandSurface::configure, this, &QWaylandQuickItem::updateBuffer); disconnect(d->oldSurface, &QWaylandSurface::redraw, this, &QQuickItem::update); + disconnect(d->oldSurface, &QWaylandSurface::childAdded, this, &QWaylandQuickItem::handleSubsurfaceAdded); #ifndef QT_NO_IM disconnect(d->oldSurface->inputMethodControl(), &QWaylandInputMethodControl::updateInputMethod, this, &QWaylandQuickItem::updateInputMethod); #endif @@ -508,6 +565,7 @@ void QWaylandQuickItem::handleSurfaceChanged() connect(newSurface, &QWaylandSurface::sizeChanged, this, &QWaylandQuickItem::updateSize); connect(newSurface, &QWaylandSurface::configure, this, &QWaylandQuickItem::updateBuffer); connect(newSurface, &QWaylandSurface::redraw, this, &QQuickItem::update); + connect(newSurface, &QWaylandSurface::childAdded, this, &QWaylandQuickItem::handleSubsurfaceAdded); #ifndef QT_NO_IM connect(newSurface->inputMethodControl(), &QWaylandInputMethodControl::updateInputMethod, this, &QWaylandQuickItem::updateInputMethod); #endif @@ -835,4 +893,14 @@ void QWaylandQuickItem::raise() stackAfter(top); } +/*! + * \internal + * + * Sets the position of this item relative to the parent item. + */ +void QWaylandQuickItem::handleSubsurfacePosition(const QPoint &pos) +{ + QQuickItem::setPosition(pos); +} + QT_END_NAMESPACE diff --git a/src/compositor/compositor_api/qwaylandquickitem.h b/src/compositor/compositor_api/qwaylandquickitem.h index 9dab65ac..20b28b5f 100644 --- a/src/compositor/compositor_api/qwaylandquickitem.h +++ b/src/compositor/compositor_api/qwaylandquickitem.h @@ -67,7 +67,7 @@ class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandQuickItem : public QQuickItem Q_PROPERTY(bool inputEventsEnabled READ inputEventsEnabled WRITE setInputEventsEnabled NOTIFY inputEventsEnabledChanged) Q_PROPERTY(bool focusOnClick READ focusOnClick WRITE setFocusOnClick NOTIFY focusOnClickChanged) Q_PROPERTY(bool sizeFollowsSurface READ sizeFollowsSurface WRITE setSizeFollowsSurface NOTIFY sizeFollowsSurfaceChanged) - + Q_PROPERTY(QObject *subsurfaceHandler READ subsurfaceHandler WRITE setSubsurfaceHandler NOTIFY subsurfaceHandlerChanged) public: QWaylandQuickItem(QQuickItem *parent = 0); ~QWaylandQuickItem(); @@ -104,6 +104,9 @@ public: Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery query, QVariant argument) const; #endif + QObject *subsurfaceHandler() const; + void setSubsurfaceHandler(QObject*); + protected: void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; @@ -138,6 +141,8 @@ private Q_SLOTS: void updateBuffer(bool hasBuffer); void updateWindow(); void beforeSync(); + void handleSubsurfaceAdded(QWaylandSurface *childSurface); + void handleSubsurfacePosition(const QPoint &pos); #ifndef QT_NO_IM void updateInputMethod(Qt::InputMethodQueries queries); #endif @@ -152,7 +157,7 @@ Q_SIGNALS: void mouseMove(const QPointF &windowPosition); void mouseRelease(); void sizeFollowsSurfaceChanged(); - + void subsurfaceHandlerChanged(); protected: QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) Q_DECL_OVERRIDE; diff --git a/src/compositor/compositor_api/qwaylandquickitem_p.h b/src/compositor/compositor_api/qwaylandquickitem_p.h index 2a5686f3..62c01ace 100644 --- a/src/compositor/compositor_api/qwaylandquickitem_p.h +++ b/src/compositor/compositor_api/qwaylandquickitem_p.h @@ -119,6 +119,7 @@ public: QQuickWindow *connectedWindow; QWaylandSurface::Origin origin; + QPointer<QObject> subsurfaceHandler; }; QT_END_NAMESPACE |