diff options
author | Mikolaj Boc <[email protected]> | 2023-02-22 09:46:51 +0100 |
---|---|---|
committer | Mikolaj Boc <[email protected]> | 2023-06-15 13:34:02 +0200 |
commit | 7264f141cf87755193d9b8d6264e7c3590a68463 (patch) | |
tree | 4ad225f0063b96a34867dab7c3ef14c6d3ca099a /tests/manual/wasm/qwasmwindow/qwasmwindow_harness.cpp | |
parent | 8393922e7071221a9c6c0811eb714f20bf4ed02b (diff) |
Add window painting testcase to the QWasmWindow test
The test checks whether windows repaint correctly by sampling the
background after their backing stores have been flushed.
Change-Id: Ib544457074d7d477a4acdc5c331ef83e5ba471d2
Reviewed-by: Piotr Wierciński <[email protected]>
Reviewed-by: Mikołaj Boc <[email protected]>
Diffstat (limited to 'tests/manual/wasm/qwasmwindow/qwasmwindow_harness.cpp')
-rw-r--r-- | tests/manual/wasm/qwasmwindow/qwasmwindow_harness.cpp | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/tests/manual/wasm/qwasmwindow/qwasmwindow_harness.cpp b/tests/manual/wasm/qwasmwindow/qwasmwindow_harness.cpp index 04a947d0ba4..a155ac2052f 100644 --- a/tests/manual/wasm/qwasmwindow/qwasmwindow_harness.cpp +++ b/tests/manual/wasm/qwasmwindow/qwasmwindow_harness.cpp @@ -6,6 +6,8 @@ #include <QtGui/qevent.h> #include <QtCore/qobject.h> #include <QtCore/qregularexpression.h> +#include <QtGui/qpainter.h> +#include <QtGui/qrasterwindow.h> #include <QtGui/qscreen.h> #include <QtGui/qwindow.h> #include <QtGui/qguiapplication.h> @@ -18,10 +20,17 @@ #include <sstream> #include <vector> -class DeleteOnCloseWindow : public QWindow +class TestWindow : public QRasterWindow { Q_OBJECT +public: + void setBackgroundColor(int r, int g, int b) + { + m_backgroundColor = QColor::fromRgb(r, g, b); + update(); + } + private: void closeEvent(QCloseEvent *ev) override { @@ -48,16 +57,24 @@ private: data.set("key", emscripten::val(event->text().toStdString())); emscripten::val::global("window")["testSupport"].call<void>("reportEvent", std::move(data)); } + + void paintEvent(QPaintEvent *e) final + { + QPainter painter(this); + painter.fillRect(e->rect(), m_backgroundColor); + } + + QColor m_backgroundColor = Qt::white; }; namespace { -DeleteOnCloseWindow *findWindowByTitle(const std::string &title) +TestWindow *findWindowByTitle(const std::string &title) { auto windows = qGuiApp->allWindows(); auto window_it = std::find_if(windows.begin(), windows.end(), [&title](QWindow *window) { return window->title() == QString::fromLatin1(title); }); - return window_it == windows.end() ? nullptr : static_cast<DeleteOnCloseWindow *>(*window_it); + return window_it == windows.end() ? nullptr : static_cast<TestWindow *>(*window_it); } } // namespace @@ -175,7 +192,7 @@ void createWindow(int x, int y, int w, int h, std::string parentType, std::strin return; } - auto *window = new DeleteOnCloseWindow; + auto *window = new TestWindow; window->setFlag(Qt::WindowTitleHint); window->setFlag(Qt::WindowMaximizeButtonHint); @@ -185,6 +202,16 @@ void createWindow(int x, int y, int w, int h, std::string parentType, std::strin window->setParent(parentWindow); } +void setWindowBackgroundColor(std::string title, int r, int g, int b) +{ + auto *window = findWindowByTitle(title); + if (!window) { + qWarning() << "No such window: " << title; + return; + } + window->setBackgroundColor(r, g, b); +} + void setWindowVisible(int windowId, bool visible) { auto windows = qGuiApp->allWindows(); auto window_it = std::find_if(windows.begin(), windows.end(), [windowId](QWindow *window) { @@ -229,6 +256,7 @@ EMSCRIPTEN_BINDINGS(qwasmwindow) emscripten::function("setWindowVisible", &setWindowVisible); emscripten::function("setWindowParent", &setWindowParent); emscripten::function("closeWindow", &closeWindow); + emscripten::function("setWindowBackgroundColor", &setWindowBackgroundColor); } int main(int argc, char **argv) |