diff options
author | Paul Olav Tvete <paul.tvete@qt.io> | 2017-08-29 14:32:23 +0200 |
---|---|---|
committer | Paul Olav Tvete <paul.tvete@qt.io> | 2017-10-05 13:53:03 +0000 |
commit | 37a8e57d7b8ff9f4360d8a32a09618fbd16534be (patch) | |
tree | e34c196de61202067c5030e7b14e05f0542af834 /examples/wayland/custom-extension/cpp-client/main.cpp | |
parent | 00a99e631459eb7e52fde822c24d7b9d603008c4 (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/cpp-client/main.cpp')
-rw-r--r-- | examples/wayland/custom-extension/cpp-client/main.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/examples/wayland/custom-extension/cpp-client/main.cpp b/examples/wayland/custom-extension/cpp-client/main.cpp index 54c0bcc0b..da6230cc7 100644 --- a/examples/wayland/custom-extension/cpp-client/main.cpp +++ b/examples/wayland/custom-extension/cpp-client/main.cpp @@ -70,6 +70,7 @@ public: , rect1(50, 50, 100, 100) , rect2(50, 200, 100, 100) , rect3(50, 350, 100, 100) + , rect4(200,350, 100, 100) { m_extension->registerWindow(this); connect(m_extension, &CustomExtension::fontSize, this, &TestWindow::handleSetFontSize); @@ -101,6 +102,14 @@ public slots: w->show(); } + CustomExtensionObject *newObject() + { + m_objectCount++; + QColor col = QColor::fromHsv(0, 511/(m_objectCount+1), 255); + + return m_extension->createCustomObject(col.name(), QString::number(m_objectCount)); + } + void handleSetFontSize(QWindow *w, uint pixelSize) { if (w == this) { @@ -121,6 +130,9 @@ protected: p.drawText(rect2, Qt::TextWordWrap, "Press here to send bounce request."); p.fillRect(rect3, QColor("#7EA")); p.drawText(rect3, Qt::TextWordWrap, "Create new window."); + p.fillRect(rect4, QColor("#7EABA6")); + p.drawText(rect4, Qt::TextWordWrap, "Create custom object."); + } void mousePressEvent(QMouseEvent *ev) override @@ -131,6 +143,8 @@ protected: doBounce(); else if (rect3.contains(ev->pos())) newWindow(); + else if (rect4.contains(ev->pos())) + newObject(); } private: @@ -138,9 +152,15 @@ private: QRect rect1; QRect rect2; QRect rect3; + QRect rect4; QFont m_font; + static int m_objectCount; + static int m_hue; }; +int TestWindow::m_objectCount = 0; +int TestWindow::m_hue; + int main (int argc, char **argv) { QGuiApplication app(argc, argv); |