summaryrefslogtreecommitdiffstats
path: root/tests/manual
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@qt.io>2021-09-13 11:15:29 +0200
committerMorten Johan Sørvig <morten.sorvig@qt.io>2021-12-15 18:06:11 +0200
commit292bdac4cfaebcc905975aa0cdc2f87782c389f6 (patch)
tree60d293e14b18e8c15757519853b454bb572ca2c6 /tests/manual
parent4184a127fa08c3ffafad863f6dde5d4bdc349bf1 (diff)
wasm: add rasterwindow manual test
Simplest possible graphical app, with event logging. Change-Id: I6b1eb88c270a190becb23cc63d6d755ffbafcf52 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'tests/manual')
-rw-r--r--tests/manual/wasm/CMakeLists.txt1
-rw-r--r--tests/manual/wasm/README.md1
-rw-r--r--tests/manual/wasm/rasterwindow/CMakeLists.txt8
-rw-r--r--tests/manual/wasm/rasterwindow/main.cpp61
-rw-r--r--tests/manual/wasm/rasterwindow/rasterwindow.cpp224
-rw-r--r--tests/manual/wasm/rasterwindow/rasterwindow.h88
6 files changed, 383 insertions, 0 deletions
diff --git a/tests/manual/wasm/CMakeLists.txt b/tests/manual/wasm/CMakeLists.txt
index dd0d816a5d..4bd7341d66 100644
--- a/tests/manual/wasm/CMakeLists.txt
+++ b/tests/manual/wasm/CMakeLists.txt
@@ -1,4 +1,5 @@
add_subdirectory(eventloop)
+add_subdirectory(rasterwindow)
if(QT_FEATURE_widgets)
add_subdirectory(cursors)
add_subdirectory(localfiles)
diff --git a/tests/manual/wasm/README.md b/tests/manual/wasm/README.md
index 23dffe6045..5117e2f70b 100644
--- a/tests/manual/wasm/README.md
+++ b/tests/manual/wasm/README.md
@@ -11,3 +11,4 @@ Content
cursors Cursor handling
eventloop Event loops, application startup, dialog exec()
localfiles Local file download and upload
+ rasterwindow Basic GUI app, event handling
diff --git a/tests/manual/wasm/rasterwindow/CMakeLists.txt b/tests/manual/wasm/rasterwindow/CMakeLists.txt
new file mode 100644
index 0000000000..cd3a2eef3d
--- /dev/null
+++ b/tests/manual/wasm/rasterwindow/CMakeLists.txt
@@ -0,0 +1,8 @@
+qt_internal_add_manual_test(rasterwindow
+ GUI
+ SOURCES
+ main.cpp rasterwindow.cpp
+ PUBLIC_LIBRARIES
+ Qt::Core
+ Qt::Gui
+)
diff --git a/tests/manual/wasm/rasterwindow/main.cpp b/tests/manual/wasm/rasterwindow/main.cpp
new file mode 100644
index 0000000000..fad3803282
--- /dev/null
+++ b/tests/manual/wasm/rasterwindow/main.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <QtGui>
+#include "rasterwindow.h"
+
+int main(int argc, char **argv)
+{
+ QGuiApplication app(argc, argv);
+
+ RasterWindow window;
+ window.show();
+
+ return app.exec();
+}
diff --git a/tests/manual/wasm/rasterwindow/rasterwindow.cpp b/tests/manual/wasm/rasterwindow/rasterwindow.cpp
new file mode 100644
index 0000000000..d46a6bc5b6
--- /dev/null
+++ b/tests/manual/wasm/rasterwindow/rasterwindow.cpp
@@ -0,0 +1,224 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "rasterwindow.h"
+
+RasterWindow::RasterWindow()
+:m_eventCount(0)
+,m_timeoutCount(0)
+,m_pressed(false)
+{
+ qDebug() << "RasterWindow()";
+
+ // disable alpha; saves filling the window with transparent pixels
+ QSurfaceFormat format;
+ format.setAlphaBufferSize(0);
+ setFormat(format);
+
+ QTimer *timer = new QTimer(this);
+ connect(timer, &QTimer::timeout, [this](){
+ ++m_timeoutCount;
+ update();
+ });
+ timer->start(1000);
+}
+
+void RasterWindow::paintEvent(QPaintEvent * event)
+{
+ QRect r = event->rect();
+ qDebug() << "RasterWindow::paintEvent" << r;
+
+ QPainter p(this);
+
+ QColor fillColor(0, 102, 153);
+ QColor fillColor2(0, 85, 123);
+
+ int tileSize = 40;
+ for (int i = -tileSize * 2; i < r.width() + tileSize * 2; i += tileSize) {
+ for (int j = -tileSize * 2; j < r.height() + tileSize * 2; j += tileSize) {
+ QRect rect(i + (m_offset.x() % tileSize * 2), j + (m_offset.y() % tileSize * 2), tileSize, tileSize);
+ int colorIndex = abs((i/tileSize - j/tileSize) % 2);
+ p.fillRect(rect, colorIndex == 0 ? fillColor : fillColor2);
+ }
+ }
+
+ QRect g = geometry();
+ QRect sg = this->screen()->geometry();
+ QString text;
+ text += QString("Window Geometry: %1 %2 %3 %4\n").arg(g.x()).arg(g.y()).arg(g.width()).arg(g.height());
+ text += QString("Window devicePixelRatio: %1\n").arg(devicePixelRatio());
+ text += QString("Screen Geometry: %1 %2 %3 %4\n").arg(sg.x()).arg(sg.y()).arg(sg.width()).arg(sg.height());
+ text += QString("Received Events: %1\n").arg(m_eventCount);
+ text += QString("Received Timers: %1\n").arg(m_timeoutCount);
+
+ p.drawText(QRectF(0, 0, width(), height()), Qt::AlignCenter, text);
+}
+void RasterWindow::exposeEvent(QExposeEvent * ev)
+{
+ qDebug() << __PRETTY_FUNCTION__ << ev->region();
+ QRasterWindow::exposeEvent(ev);
+ incrementEventCount();
+}
+
+void RasterWindow::focusInEvent(QFocusEvent * ev)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ QRasterWindow::focusInEvent(ev);
+ incrementEventCount();
+}
+
+void RasterWindow::focusOutEvent(QFocusEvent * ev)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ QRasterWindow::focusOutEvent(ev);
+ incrementEventCount();
+}
+
+void RasterWindow::hideEvent(QHideEvent * ev)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ QRasterWindow::hideEvent(ev);
+ incrementEventCount();
+}
+
+void RasterWindow::keyPressEvent(QKeyEvent * ev)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ QRasterWindow::keyPressEvent(ev);
+ incrementEventCount();
+}
+
+void RasterWindow::keyReleaseEvent(QKeyEvent * ev)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ QRasterWindow::keyReleaseEvent(ev);
+ incrementEventCount();
+}
+
+void RasterWindow::mouseDoubleClickEvent(QMouseEvent * ev)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ QRasterWindow::mouseDoubleClickEvent(ev);
+ incrementEventCount();
+}
+
+void RasterWindow::mouseMoveEvent(QMouseEvent * ev)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ QRasterWindow::mouseMoveEvent(ev);
+ incrementEventCount();
+
+ if (m_pressed)
+ m_offset += ev->localPos().toPoint() - m_lastPos;
+ m_lastPos = ev->localPos().toPoint();
+}
+
+void RasterWindow::mousePressEvent(QMouseEvent * ev)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ QRasterWindow::mousePressEvent(ev);
+ incrementEventCount();
+ m_pressed = true;
+}
+
+void RasterWindow::mouseReleaseEvent(QMouseEvent * ev)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ QRasterWindow::mouseReleaseEvent(ev);
+ incrementEventCount();
+ m_pressed = false;
+}
+
+void RasterWindow::moveEvent(QMoveEvent * ev)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ QRasterWindow::moveEvent(ev);
+ incrementEventCount();
+}
+
+void RasterWindow::resizeEvent(QResizeEvent * ev)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ QRasterWindow::resizeEvent(ev);
+ incrementEventCount();
+}
+
+void RasterWindow::showEvent(QShowEvent * ev)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ QRasterWindow::showEvent(ev);
+ incrementEventCount();
+}
+
+void RasterWindow::tabletEvent(QTabletEvent * ev)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ QRasterWindow::tabletEvent(ev);
+ incrementEventCount();
+}
+
+void RasterWindow::touchEvent(QTouchEvent * ev)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ QRasterWindow::touchEvent(ev);
+ incrementEventCount();
+}
+
+void RasterWindow::wheelEvent(QWheelEvent * ev)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ QRasterWindow::wheelEvent(ev);
+ incrementEventCount();
+}
+
+void RasterWindow::incrementEventCount()
+{
+ ++m_eventCount;
+ update();
+}
diff --git a/tests/manual/wasm/rasterwindow/rasterwindow.h b/tests/manual/wasm/rasterwindow/rasterwindow.h
new file mode 100644
index 0000000000..8f13182015
--- /dev/null
+++ b/tests/manual/wasm/rasterwindow/rasterwindow.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef RASTERWINDOW_H
+#define RASTERWINDOW_H
+
+#include <QtGui>
+
+class RasterWindow : public QRasterWindow
+{
+public:
+ RasterWindow();
+
+ virtual void paintEvent(QPaintEvent * event);
+
+ virtual void exposeEvent(QExposeEvent * ev);
+ virtual void focusInEvent(QFocusEvent * ev);
+ virtual void focusOutEvent(QFocusEvent * ev);
+ virtual void hideEvent(QHideEvent * ev);
+ virtual void keyPressEvent(QKeyEvent * ev);
+ virtual void keyReleaseEvent(QKeyEvent * ev);
+ virtual void mouseDoubleClickEvent(QMouseEvent * ev);
+ virtual void mouseMoveEvent(QMouseEvent * ev);
+ virtual void mousePressEvent(QMouseEvent * ev);
+ virtual void mouseReleaseEvent(QMouseEvent * ev);
+ virtual void moveEvent(QMoveEvent * ev);
+// virtual bool nativeEvent(const QByteArray & eventType, void * message, long * result);
+ virtual void resizeEvent(QResizeEvent * ev);
+ virtual void showEvent(QShowEvent * ev);
+ virtual void tabletEvent(QTabletEvent * ev);
+ virtual void touchEvent(QTouchEvent * ev);
+ virtual void wheelEvent(QWheelEvent * ev);
+private:
+ void incrementEventCount();
+ int m_eventCount;
+ int m_timeoutCount;
+ QPoint m_offset;
+ QPoint m_lastPos;
+ bool m_pressed;
+};
+
+#endif // RASTERWINDOW_H