diff options
author | Paul Olav Tvete <paul.tvete@gmail.com> | 2016-09-07 10:15:28 +0200 |
---|---|---|
committer | Paul Olav Tvete <paul.tvete@qt.io> | 2016-09-30 13:56:36 +0000 |
commit | 5372ec5c131e23cccfbabc43d700ffbbbad973ec (patch) | |
tree | 270f29ece9b8c58dd0b22faf3006f6260b9bb488 /examples/wayland/custom-extension/cpp-client | |
parent | f7896fdc6505d8c6f3b3a239884dadab034e1fb5 (diff) | |
download | qtwayland-5372ec5c131e23cccfbabc43d700ffbbbad973ec.tar.gz |
Make the custom extension example more interesting
Define a protocol that does something visible.
Change-Id: I29133eeffbb2c98a61ee59b241dcf6a6a0f543cb
Reviewed-by: Johan Helsing <johan.helsing@qt.io>
Diffstat (limited to 'examples/wayland/custom-extension/cpp-client')
-rw-r--r-- | examples/wayland/custom-extension/cpp-client/cpp-client.pro | 2 | ||||
-rw-r--r-- | examples/wayland/custom-extension/cpp-client/main.cpp | 71 |
2 files changed, 58 insertions, 15 deletions
diff --git a/examples/wayland/custom-extension/cpp-client/cpp-client.pro b/examples/wayland/custom-extension/cpp-client/cpp-client.pro index 9636d110..54fead07 100644 --- a/examples/wayland/custom-extension/cpp-client/cpp-client.pro +++ b/examples/wayland/custom-extension/cpp-client/cpp-client.pro @@ -1,4 +1,4 @@ -QT += waylandclient-private +QT += waylandclient-private gui-private CONFIG += c++11 CONFIG += wayland-scanner diff --git a/examples/wayland/custom-extension/cpp-client/main.cpp b/examples/wayland/custom-extension/cpp-client/main.cpp index f5894dc8..af8de53b 100644 --- a/examples/wayland/custom-extension/cpp-client/main.cpp +++ b/examples/wayland/custom-extension/cpp-client/main.cpp @@ -42,9 +42,13 @@ #include <QRasterWindow> #include <QPainter> #include <QMouseEvent> +#include <QPlatformSurfaceEvent> + #include "../client-common/customextension.h" #include <QDebug> +#include <QtGui/qpa/qplatformnativeinterface.h> +#include <QTimer> class TestWindow : public QRasterWindow { @@ -53,39 +57,78 @@ class TestWindow : public QRasterWindow public: TestWindow(CustomExtension *customExtension) : m_extension(customExtension) + , rect1(50, 50, 100, 100) + , rect2(50, 200, 100, 100) + , rect3(50, 350, 100, 100) { - connect(customExtension, SIGNAL(eventReceived(const QString &, uint)), - this, SLOT(handleEvent(const QString &, uint))); + m_extension->registerWindow(this); + connect(m_extension, &CustomExtension::fontSize, this, &TestWindow::handleSetFontSize); } public slots: - void handleEvent(const QString &text, uint value) + void doSpin() + { + if (!m_extension->isActive()) { + qWarning() << "Extension is not active"; + return; + } + qDebug() << "sending spin..."; + m_extension->sendSpin(this, 500); + } + void doBounce() + { + if (!m_extension->isActive()) { + qWarning() << "Extension is not active"; + return; + } + qDebug() << "sending bounce..."; + m_extension->sendBounce(this, 500); + } + + void newWindow() { - qDebug() << "Client application received event" << text << value; + auto w = new TestWindow(m_extension); + w->show(); + } + + void handleSetFontSize(QWindow *w, uint pixelSize) + { + if (w == this) { + m_font.setPixelSize(pixelSize); + update(); + } } protected: - void paintEvent(QPaintEvent *) + void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE { QPainter p(this); + p.setFont(m_font); p.fillRect(QRect(0,0,width(),height()),Qt::gray); - p.fillRect(50,50,100,100, QColor("#C0FFEE")); + p.fillRect(rect1, QColor("#C0FFEE")); + p.drawText(rect1, Qt::TextWordWrap, "Press here to send spin request."); + p.fillRect(rect2, QColor("#decaff")); + p.drawText(rect2, Qt::TextWordWrap, "Press here to send bounce request."); + p.fillRect(rect3, QColor("#7EA")); + p.drawText(rect3, Qt::TextWordWrap, "Create new window."); } void mousePressEvent(QMouseEvent *ev) Q_DECL_OVERRIDE { - bool insideRect = QRect(50,50,100,100).contains(ev->pos()); - - QString text = insideRect ? "Click inside" : "Click outside"; - int value = ev->pos().x(); - - qDebug() << "Client application sending request:" << text << value; - - m_extension->sendRequest(text, value); + if (rect1.contains(ev->pos())) + doSpin(); + else if (rect2.contains(ev->pos())) + doBounce(); + else if (rect3.contains(ev->pos())) + newWindow(); } private: CustomExtension *m_extension; + QRect rect1; + QRect rect2; + QRect rect3; + QFont m_font; }; int main (int argc, char **argv) |