popups: add popup windows

This commit is contained in:
outfoxxed 2024-03-11 05:44:56 -07:00
parent 8cf0659444
commit b675b3676c
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
20 changed files with 586 additions and 71 deletions

View file

@ -0,0 +1,15 @@
function (qs_test name)
add_executable(${name} ${ARGN})
target_link_libraries(${name} PRIVATE ${QT_DEPS} Qt6::Test)
add_test(NAME ${name} WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" COMMAND $<TARGET_FILE:${name}>)
endfunction()
qs_test(popupwindow
popupwindow.cpp
../popupwindow.cpp
../proxywindow.cpp
../qmlscreen.cpp
../region.cpp
../reload.cpp
../windowinterface.cpp
)

View file

@ -0,0 +1,182 @@
#include "popupwindow.hpp"
#include <qlogging.h>
#include <qquickwindow.h>
#include <qsignalspy.h>
#include <qtest.h>
#include <qtestcase.h>
#include <qwindow.h>
#include "../popupwindow.hpp"
#include "../proxywindow.hpp"
void TestPopupWindow::initiallyVisible() { // NOLINT
auto parent = ProxyWindowBase();
auto popup = ProxyPopupWindow();
popup.setParentWindow(&parent);
popup.setVisible(true);
parent.onReload(nullptr);
popup.onReload(nullptr);
QVERIFY(popup.isVisible());
QVERIFY(popup.backingWindow()->isVisible());
QCOMPARE(popup.backingWindow()->transientParent(), parent.backingWindow());
}
void TestPopupWindow::reloadReparent() { // NOLINT
// first generation
auto parent = ProxyWindowBase();
auto popup = ProxyPopupWindow();
auto* win2 = new QQuickWindow();
win2->setVisible(true);
parent.setVisible(true);
popup.setParentWindow(&parent);
popup.setVisible(true);
parent.onReload(nullptr);
popup.onReload(nullptr);
// second generation
auto newParent = ProxyWindowBase();
auto newPopup = ProxyPopupWindow();
newPopup.setParentWindow(&newParent);
newPopup.setVisible(true);
auto* oldWindow = popup.backingWindow();
auto* oldTransientParent = oldWindow->transientParent();
auto spy = QSignalSpy(oldWindow, &QWindow::visibleChanged);
qDebug() << "reload";
newParent.onReload(&parent);
newPopup.onReload(&popup);
QVERIFY(newPopup.isVisible());
QVERIFY(newPopup.backingWindow()->isVisible());
QCOMPARE(newPopup.backingWindow()->transientParent(), oldTransientParent);
QCOMPARE(newPopup.backingWindow()->transientParent(), newParent.backingWindow());
QCOMPARE(spy.length(), 0);
}
void TestPopupWindow::reloadUnparent() { // NOLINT
// first generation
auto parent = ProxyWindowBase();
auto popup = ProxyPopupWindow();
popup.setParentWindow(&parent);
popup.setVisible(true);
parent.onReload(nullptr);
popup.onReload(nullptr);
// second generation
auto newPopup = ProxyPopupWindow();
// parent not set
newPopup.setVisible(true);
newPopup.onReload(&popup);
QVERIFY(!newPopup.isVisible());
QVERIFY(!newPopup.backingWindow()->isVisible());
QCOMPARE(newPopup.backingWindow()->transientParent(), nullptr);
}
void TestPopupWindow::invisibleWithoutParent() { // NOLINT
auto popup = ProxyPopupWindow();
popup.setVisible(true);
popup.onReload(nullptr);
QVERIFY(!popup.isVisible());
}
void TestPopupWindow::moveWithParent() { // NOLINT
auto parent = ProxyWindowBase();
auto popup = ProxyPopupWindow();
popup.setParentWindow(&parent);
popup.setRelativeX(10);
popup.setRelativeY(10);
popup.setVisible(true);
parent.onReload(nullptr);
popup.onReload(nullptr);
QCOMPARE(popup.x(), parent.x() + 10);
QCOMPARE(popup.y(), parent.y() + 10);
parent.backingWindow()->setX(10);
parent.backingWindow()->setY(10);
QCOMPARE(popup.x(), parent.x() + 10);
QCOMPARE(popup.y(), parent.y() + 10);
}
void TestPopupWindow::attachParentLate() { // NOLINT
auto parent = ProxyWindowBase();
auto popup = ProxyPopupWindow();
popup.setVisible(true);
parent.onReload(nullptr);
popup.onReload(nullptr);
QVERIFY(!popup.isVisible());
popup.setParentWindow(&parent);
QVERIFY(popup.isVisible());
QVERIFY(popup.backingWindow()->isVisible());
QCOMPARE(popup.backingWindow()->transientParent(), parent.backingWindow());
}
void TestPopupWindow::reparentLate() { // NOLINT
auto parent = ProxyWindowBase();
auto popup = ProxyPopupWindow();
popup.setParentWindow(&parent);
popup.setVisible(true);
parent.onReload(nullptr);
popup.onReload(nullptr);
QCOMPARE(popup.x(), parent.x());
QCOMPARE(popup.y(), parent.y());
auto parent2 = ProxyWindowBase();
parent2.onReload(nullptr);
parent2.backingWindow()->setX(10);
parent2.backingWindow()->setY(10);
popup.setParentWindow(&parent2);
QVERIFY(popup.isVisible());
QVERIFY(popup.backingWindow()->isVisible());
QCOMPARE(popup.backingWindow()->transientParent(), parent2.backingWindow());
QCOMPARE(popup.x(), parent2.x());
QCOMPARE(popup.y(), parent2.y());
}
void TestPopupWindow::xMigrationFix() { // NOLINT
auto parent = ProxyWindowBase();
auto popup = ProxyPopupWindow();
popup.setParentWindow(&parent);
popup.setVisible(true);
parent.onReload(nullptr);
popup.onReload(nullptr);
QCOMPARE(popup.x(), parent.x());
popup.setVisible(false);
popup.setVisible(true);
QCOMPARE(popup.x(), parent.x());
}
QTEST_MAIN(TestPopupWindow);

View file

@ -0,0 +1,18 @@
#pragma once
#include <qobject.h>
#include <qtmetamacros.h>
class TestPopupWindow: public QObject {
Q_OBJECT;
private slots:
void initiallyVisible();
void reloadReparent();
void reloadUnparent();
void invisibleWithoutParent();
void moveWithParent();
void attachParentLate();
void reparentLate();
void xMigrationFix();
};