summaryrefslogtreecommitdiffstats
path: root/examples/wayland/custom-extension/client-common
diff options
context:
space:
mode:
authorPaul Olav Tvete <paul.tvete@qt.io>2017-08-29 14:32:23 +0200
committerPaul Olav Tvete <paul.tvete@qt.io>2017-10-05 13:53:03 +0000
commit37a8e57d7b8ff9f4360d8a32a09618fbd16534be (patch)
treee34c196de61202067c5030e7b14e05f0542af834 /examples/wayland/custom-extension/client-common
parent00a99e631459eb7e52fde822c24d7b9d603008c4 (diff)
Add non-global object to custom extension example
Show how to create non-global objects on the client side. Also fix error in the XML file: move the enum outside the event. Change-Id: I85b4cae115a57d60eda4a54d652ea98a8cd39548 Reviewed-by: Johan Helsing <johan.helsing@qt.io>
Diffstat (limited to 'examples/wayland/custom-extension/client-common')
-rw-r--r--examples/wayland/custom-extension/client-common/customextension.cpp26
-rw-r--r--examples/wayland/custom-extension/client-common/customextension.h34
2 files changed, 60 insertions, 0 deletions
diff --git a/examples/wayland/custom-extension/client-common/customextension.cpp b/examples/wayland/custom-extension/client-common/customextension.cpp
index 81f524d9d..41b4a30e9 100644
--- a/examples/wayland/custom-extension/client-common/customextension.cpp
+++ b/examples/wayland/custom-extension/client-common/customextension.cpp
@@ -109,6 +109,12 @@ void CustomExtension::registerWindow(QWindow *window)
sendWindowRegistration(window);
}
+CustomExtensionObject *CustomExtension::createCustomObject(const QString &color, const QString &text)
+{
+ auto *obj = create_local_object(color, text);
+ return new CustomExtensionObject(obj, text);
+}
+
void CustomExtension::sendBounce(QWindow *window, uint ms)
{
QtWayland::qt_example_extension::bounce(getWlSurface(window), ms);
@@ -152,4 +158,24 @@ void CustomExtension::example_extension_set_window_decoration(uint32_t state)
}
}
+CustomExtensionObject::CustomExtensionObject(struct ::qt_example_local_object *wl_object, const QString &text)
+ : QWaylandClientExtensionTemplate<CustomExtensionObject>(1)
+ , QtWayland::qt_example_local_object(wl_object)
+ , m_text(text)
+{
+
+}
+
+void CustomExtensionObject::example_local_object_clicked()
+{
+ qDebug() << "Object clicked:" << m_text;
+ emit clicked();
+}
+
+void CustomExtensionObject::setText(const QString &text)
+{
+ m_text = text;
+ set_text(text);
+}
+
QT_END_NAMESPACE
diff --git a/examples/wayland/custom-extension/client-common/customextension.h b/examples/wayland/custom-extension/client-common/customextension.h
index e76682f62..003a5a008 100644
--- a/examples/wayland/custom-extension/client-common/customextension.h
+++ b/examples/wayland/custom-extension/client-common/customextension.h
@@ -58,6 +58,8 @@
QT_BEGIN_NAMESPACE
+class CustomExtensionObject;
+
class CustomExtension : public QWaylandClientExtensionTemplate<CustomExtension>
, public QtWayland::qt_example_extension
{
@@ -66,6 +68,8 @@ public:
CustomExtension();
Q_INVOKABLE void registerWindow(QWindow *window);
+ CustomExtensionObject *createCustomObject(const QString &color, const QString &text);
+
public slots:
void sendBounce(QWindow *window, uint ms);
void sendSpin(QWindow *window, uint ms);
@@ -92,6 +96,36 @@ private:
bool m_activated;
};
+class CustomExtensionObject : public QWaylandClientExtensionTemplate<CustomExtensionObject>
+ , public QtWayland::qt_example_local_object
+{
+ Q_OBJECT
+ Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
+public:
+ CustomExtensionObject(struct ::qt_example_local_object *wl_object, const QString &text);
+
+ QString text() const
+ {
+ return m_text;
+ }
+
+protected:
+ void example_local_object_clicked() override;
+
+public slots:
+ void setText(const QString &text);
+
+
+signals:
+ void textChanged(const QString &text);
+ void clicked();
+
+private:
+ QString m_text;
+};
+
+
+
QT_END_NAMESPACE
#endif // CUSTOMEXTENSION_H