diff options
author | Paul Olav Tvete <paul.tvete@qt.io> | 2018-08-15 13:31:21 +0200 |
---|---|---|
committer | Paul Olav Tvete <paul.tvete@qt.io> | 2018-08-16 12:56:52 +0000 |
commit | bc9fc09caf4f638005977281dc57e7d9c99cfddf (patch) | |
tree | 1ab1396a264c28afcc5b260cdc9445c44bb87a27 /examples/wayland/minimal-cpp/window.cpp | |
parent | 70f0f02568e3d577452e45b49deee47cf7d465b3 (diff) |
Add mouse and keyboard handling to minimal-cpp example
...and do some other minor cleanups.
Change-Id: I7fe2c70d8b2de37cee5cc114cc0148d31821e10f
Reviewed-by: Johan Helsing <johan.helsing@qt.io>
Diffstat (limited to 'examples/wayland/minimal-cpp/window.cpp')
-rw-r--r-- | examples/wayland/minimal-cpp/window.cpp | 46 |
1 files changed, 35 insertions, 11 deletions
diff --git a/examples/wayland/minimal-cpp/window.cpp b/examples/wayland/minimal-cpp/window.cpp index c43255dfc..673e15fd8 100644 --- a/examples/wayland/minimal-cpp/window.cpp +++ b/examples/wayland/minimal-cpp/window.cpp @@ -55,7 +55,7 @@ #include <QMatrix4x4> #include <QOpenGLFunctions> #include <QOpenGLTexture> -#include <QRandomGenerator> +#include <QMouseEvent> Window::Window() { @@ -70,14 +70,6 @@ void Window::initializeGL() m_textureBlitter.create(); } -static QPoint sillyrandom(int seed, QSize screenSize, QSize surfaceSize) -{ - QRandomGenerator rand(seed); - int xrange = qMax(screenSize.width() - surfaceSize.width(), 200); - int yrange = qMax(screenSize.height() - surfaceSize.height(), 200); - return QPoint(rand.bounded(xrange), rand.bounded(yrange)); -} - void Window::paintGL() { m_compositor->startRender(); @@ -91,7 +83,8 @@ void Window::paintGL() functions->glEnable(GL_BLEND); functions->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - Q_FOREACH (View *view, m_compositor->views()) { + const auto views = m_compositor->views(); + for (View *view : views) { auto texture = view->getTexture(); if (!texture) continue; @@ -103,7 +96,8 @@ void Window::paintGL() QWaylandSurface *surface = view->surface(); if (surface && surface->hasContent()) { QSize s = surface->size(); - QPointF pos = sillyrandom(view->iviId(), size(), s); + view->initPosition(size(), s); + QPointF pos = view->globalPosition(); QRectF surfaceGeometry(pos, s); QOpenGLTextureBlitter::Origin surfaceOrigin = view->currentBuffer().origin() == QWaylandSurface::OriginTopLeft @@ -116,3 +110,33 @@ void Window::paintGL() m_textureBlitter.release(); m_compositor->endRender(); } + +void Window::mousePressEvent(QMouseEvent *event) +{ + m_compositor->handleMousePress(event->localPos().toPoint(), event->button()); +} + +void Window::mouseReleaseEvent(QMouseEvent *event) +{ + m_compositor->handleMouseRelease(event->localPos().toPoint(), event->button(), event->buttons()); +} + +void Window::mouseMoveEvent(QMouseEvent *event) +{ + m_compositor->handleMouseMove(event->localPos().toPoint()); +} + +void Window::wheelEvent(QWheelEvent *event) +{ + m_compositor->handleMouseWheel(event->orientation(), event->delta()); +} + +void Window::keyPressEvent(QKeyEvent *e) +{ + m_compositor->handleKeyPress(e->nativeScanCode()); +} + +void Window::keyReleaseEvent(QKeyEvent *e) +{ + m_compositor->handleKeyRelease(e->nativeScanCode()); +} |