From e05f5a552c2faf8870e9ce4e87a39340604c3954 Mon Sep 17 00:00:00 2001 From: Kirill Kostin <15322854+k-kostin@users.noreply.github.com> Date: Wed, 18 Nov 2026 19:13:33 +0300 Subject: [PATCH 1/4] Pilot tree-list row reuse for rendered-frame measurements --- src/FileRow.qml | 55 ++++++++++++++++++++++++++++++++++++---------- src/FolderList.qml | 9 ++++++++ 2 files changed, 52 insertions(+), 12 deletions(-) diff --git a/src/FileRow.qml b/src/FileRow.qml index 26031f46..5f993c7c 100644 --- a/src/FileRow.qml +++ b/src/FileRow.qml @@ -32,6 +32,33 @@ Item { // it in place (or closes it). property bool tree: false + // Model roles change on reuse; drag assets belong to the old file. + property bool pooled: false + property int dragGeneration: 0 + function clearDragAssets() { + ++dragGeneration + Drag.imageSource = "" + Drag.mimeData = ({}) + } + onPathChanged: clearDragAssets() + ListView.onPooled: { + pooled = true + clearDragAssets() + } + ListView.onReused: pooled = false + + function captureDragPicture() { + const target = row + const generation = ++dragGeneration + const path = row.path + return grabToImage(result => { + if (target && !target.pooled && target.path === path && target.dragGeneration === generation) { + target.Drag.imageSource = "" + target.Drag.imageSource = result.url + } + }) + } + signal clicked(int modifiers) signal activated() signal toggled() @@ -56,7 +83,7 @@ Item { DropArea { id: folderDrop anchors.fill: parent - enabled: row.isDir + enabled: !row.pooled && row.isDir keys: ["text/uri-list"] onEntered: (drag) => { drag.accepted = fileOps.canDrop(drag.urls, row.path) } onDropped: (drop) => { fileOps.dropInto(drop.urls, row.path); drop.accept(Qt.MoveAction) } @@ -96,9 +123,9 @@ Item { rotation: row.expanded ? (row.LayoutMirroring.enabled ? -90 : 90) : 0 color: arrowHover.hovered ? theme.foreground : theme.secondaryForeground } - HoverHandler { id: arrowHover; enabled: row.isDir } + HoverHandler { id: arrowHover; enabled: !row.pooled && row.isDir } TapHandler { - enabled: row.isDir + enabled: !row.pooled && row.isDir // Before the row's own tap, which would select it instead. grabPermissions: PointerHandler.CanTakeOverFromAnything onTapped: row.toggled() @@ -124,7 +151,7 @@ Item { // A small picture of any file there's one of, as the tiles // have; a text's opening lines would be unreadable this // small, and folders and plugins' items keep their glyph. - source: row.isDir || row.kind === "item" || row.kind === "text" ? "" : Format.thumb(row.path, row.mime, 128, row.modified) + source: row.pooled || row.isDir || row.kind === "item" || row.kind === "text" ? "" : Format.thumb(row.path, row.mime, 128, row.modified) visible: status === Image.Ready } Rectangle { @@ -189,14 +216,18 @@ Item { HoverHandler { id: hover - // Cleared first: Qt (6.12) reloads a new picture at the size of the - // one before, which for a grab only warns ("Ignoring sourceSize"). - onHoveredChanged: if (hovered) row.grabToImage(result => { row.Drag.imageSource = ""; row.Drag.imageSource = result.url }) + enabled: !row.pooled + onHoveredChanged: if (hovered) row.captureDragPicture() } - TapHandler { - id: tap - onTapped: row.clicked(tap.point.modifiers) - onDoubleTapped: row.activated() + // Tap history belongs to a file, not to the next file using its row. + Loader { + active: !row.pooled + sourceComponent: TapHandler { + id: tap + parent: row + onTapped: row.clicked(tap.point.modifiers) + onDoubleTapped: row.activated() + } } // Like the tiles: dragged, a row is a file for the sidebar or another app. @@ -207,7 +238,7 @@ Item { Drag.hotSpot.x: LayoutMirroring.enabled ? row.width : 0 DragHandler { target: null - enabled: row.kind !== "item" + enabled: !row.pooled && row.kind !== "item" // Dragging a selected item takes the whole selection along. The list // is built as the drag starts, not again on every change of selection. onActiveChanged: { diff --git a/src/FolderList.qml b/src/FolderList.qml index 2a79ebe9..d064787b 100644 --- a/src/FolderList.qml +++ b/src/FolderList.qml @@ -72,6 +72,10 @@ FileListView { onTapped: (point) => list.contextMenu(selecting.menuAt(point), backend.path, point.scenePosition) } + // Keep an active drag on its original file, following the existing + // non-reusing behavior until it ends. + property Item dragSource: null + reuseItems: dragSource === null focus: true keyNavigationEnabled: true // No cursor of its own to start with: the pane puts it back where the @@ -81,6 +85,11 @@ FileListView { model: backend.folder delegate: FileRow { + id: entry + Drag.onActiveChanged: { + if (Drag.active) list.dragSource = entry + else if (list.dragSource === entry) list.dragSource = null + } width: list.width detailed: true tree: backend.folder.expandable From 1eccf9c72cb3ecabe625d1dd116e01f364dda0ca Mon Sep 17 00:00:00 2001 From: Kirill Kostin <15322854+k-kostin@users.noreply.github.com> Date: Wed, 18 Nov 2026 20:05:01 +0300 Subject: [PATCH 2/4] Cancel a tree arrow press when its row is pooled --- src/FileRow.qml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/FileRow.qml b/src/FileRow.qml index 5f993c7c..10e13d88 100644 --- a/src/FileRow.qml +++ b/src/FileRow.qml @@ -125,10 +125,13 @@ Item { } HoverHandler { id: arrowHover; enabled: !row.pooled && row.isDir } TapHandler { + property string pressedPath: "" enabled: !row.pooled && row.isDir + onPressedChanged: if (pressed) pressedPath = row.path + onEnabledChanged: if (!enabled) pressedPath = "" // Before the row's own tap, which would select it instead. grabPermissions: PointerHandler.CanTakeOverFromAnything - onTapped: row.toggled() + onTapped: if (pressedPath.length > 0 && pressedPath === row.path) row.toggled() } } From 3a78b4e781fbe89a8524dab681b658776ccb44c1 Mon Sep 17 00:00:00 2001 From: Kirill Kostin <15322854+k-kostin@users.noreply.github.com> Date: Thu, 19 Nov 2026 08:01:32 +0300 Subject: [PATCH 3/4] Cover reused tree rows, thumbnails and pointer lifecycles in the main test suite --- tests/folio_tests.cpp | 468 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 468 insertions(+) diff --git a/tests/folio_tests.cpp b/tests/folio_tests.cpp index 1de00c72..2e72474f 100644 --- a/tests/folio_tests.cpp +++ b/tests/folio_tests.cpp @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include #include #include @@ -541,11 +543,178 @@ static ChooserRequest chooserRequest(ChooserRequest::Mode mode, const QVariantMa return ChooserRequest::read(mode, "Pick", overDBus(options), error); } +// Only opening another program is fenced. The folder, selection and file +// operations exercised by the QML are the real ones. +class RowTestBackend : public QObject { + Q_OBJECT + Q_PROPERTY(FolderModel *folder READ folder CONSTANT) + Q_PROPERTY(QString path READ path NOTIFY pathChanged) + public: + explicit RowTestBackend(const QString &home) : backend(home) + { + connect(&backend, &Backend::pathChanged, this, &RowTestBackend::pathChanged); + } + FolderModel *folder() { return backend.folder(); } + QString path() const { return backend.path(); } + QStringList opened; + Q_INVOKABLE void open(const QString &path) { opened << path; } + Q_INVOKABLE void navigate(const QString &path) { backend.navigate(path); } + Q_INVOKABLE void goUp() { backend.goUp(); } + signals: + void pathChanged(); + + private: + Backend backend; +}; + +struct RowLocaleGuard { + QLocale before; + ~RowLocaleGuard() { QLocale::setDefault(before); } +}; + +class RowList { + static void makeFile(const QString &path) + { + QFile file(path); + if (!file.open(QIODevice::WriteOnly) || file.write("x") != 1) + qFatal("Cannot write row fixture"); + } + + public: + RowLocaleGuard locale; + QTemporaryDir home; + RowTestBackend backend{home.path()}; + Theme theme{home.filePath("theme")}; + FileOps ops; + Translator translator{home.filePath("language"), sourceFolder() + "/i18n"}; + std::unique_ptr plugins{QQmlPropertyMap::create()}; + Thumbnails thumbnails{home.filePath("cache"), {home.filePath("none")}}; + QQmlEngine engine; + std::unique_ptr root; + QQuickItem *list = nullptr; + QString error; + + RowList(bool pictures = false, bool tree = false) + { + if (!home.isValid()) + qFatal("temporary home unavailable"); + QDir().mkpath(folder()); + for (int i = 0; i < 400; ++i) { + const QString file = folder() + QString("/file%1").arg(i, 3, 10, QChar('0')); + if (pictures && i % 3 == 0) { + QImage image(32, 32, QImage::Format_RGB32); + image.fill(i % 2 ? Qt::blue : Qt::red); + if (!image.save(file + ".png")) + qFatal("picture fixture"); + } else + makeFile(file + ".txt"); + } + if (tree) + for (int i = 0; i < 200; ++i) { + const QString dir = folder() + QString("/branch%1").arg(i, 3, 10, QChar('0')); + if (!QDir().mkpath(dir + "/nested")) + qFatal("tree fixture"); + makeFile(dir + "/a.txt"); + makeFile(dir + "/nested/leaf.txt"); + } + plugins->insert("views", QVariantMap{}); + auto *context = engine.rootContext(); + context->setContextProperty("backend", &backend); + context->setContextProperty("theme", &theme); + context->setContextProperty("fileOps", &ops); + context->setContextProperty("translator", &translator); + context->setContextProperty("plugins", plugins.get()); + engine.addImageProvider("thumb", new ThumbnailProvider(&thumbnails)); + } + ~RowList() + { + root.reset(); + QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); + QThreadPool::globalInstance()->waitForDone(); + } + QString folder() const { return home.filePath("folder"); } + QQuickWindow *window() const { return qobject_cast(root.get()); } + bool show(bool mirrored = false) + { + backend.navigate(folder()); + if (!QTest::qWaitFor([&] { return !backend.folder()->loading(); })) + return false; + QQmlComponent component(&engine); + component.setData("import QtQuick\nWindow { width: 900; height: 480; visible: true\n" + " Item { anchors.fill: parent; LayoutMirroring.enabled: " + + QByteArray(mirrored ? "true" : "false") + + "; LayoutMirroring.childrenInherit: true; FolderList { objectName: 'list'; " + "anchors.fill: parent } } }", + QUrl::fromLocalFile(sourceFolder() + "/RowReuseTest.qml")); + root.reset(component.create()); + error = component.errorString(); + if (!root) + return false; + list = root->findChild("list"); + return list && QTest::qWaitForWindowExposed(window()) && + QTest::qWaitFor([&] { return item(4) != nullptr; }); + } + QQuickItem *item(int index) const + { + QQuickItem *found = nullptr; + QMetaObject::invokeMethod(list, "itemAtIndex", Q_RETURN_ARG(QQuickItem *, found), Q_ARG(int, index)); + return found; + } + void move(int index) + { + QMetaObject::invokeMethod(list, "positionViewAtIndex", Q_ARG(int, index), Q_ARG(int, 0)); + QMetaObject::invokeMethod(list, "forceLayout"); + } + QVariant eval(QObject *object, const QString &code) + { + QQmlExpression expression(qmlContext(object), object, code); + QVariant result = expression.evaluate(); + if (expression.hasError()) + error = expression.error().toString(); + return result; + } + QPoint point(QQuickItem *item) const + { + return item->mapToItem(window()->contentItem(), QPointF(100, item->height() / 2)).toPoint(); + } +}; + +static void rowMouseAt(QQuickWindow *window, const QPoint &at, bool down, ulong timestamp) +{ + QMouseEvent event(down ? QEvent::MouseButtonPress : QEvent::MouseButtonRelease, at, + window->mapToGlobal(at), Qt::LeftButton, down ? Qt::LeftButton : Qt::NoButton, + Qt::NoModifier); + event.setTimestamp(timestamp); + QGuiApplication::sendEvent(window, &event); +} + +static void rowClickAt(QQuickWindow *window, const QPoint &at, ulong timestamp) +{ + rowMouseAt(window, at, true, timestamp); + rowMouseAt(window, at, false, timestamp + 1); +} + class FolioTests : public QObject { Q_OBJECT // Where the tests' folders keep their orders, away from the real ones. QTemporaryDir settings; + static QQuickItem *rowImage(QQuickItem *row) + { + for (auto *item : row->findChildren()) + if (item->inherits("QQuickImage") && + item->property("source").toUrl().toString().startsWith("image://thumb/")) + return item; + return nullptr; + } + static QQuickItem *rowArrow(QQuickItem *row) + { + for (auto *item : row->findChildren()) + if (item->implicitWidth() == 18 && item->implicitHeight() == 32) + return item; + return nullptr; + } + private slots: void initTestCase() { @@ -7213,6 +7382,305 @@ private slots: QCOMPARE(backend.folder()->selectedCount(), 2 * paged + 1); } + // Recycling a row must preserve file identity, including its image and + // the new tree roles; folders can change while their delegates are pooled. + void listReuseKeepsThumbnails_data() + { + QTest::addColumn("mirrored"); + QTest::newRow("ltr") << false; + QTest::newRow("rtl") << true; + } + + void listReuseKeepsThumbnails() + { + QFETCH(bool, mirrored); + RowList f(true); + QVERIFY2(f.show(mirrored), qPrintable(f.error)); + QPointer row = f.item(3); + QVERIFY(row); + auto *image = rowImage(row); + QVERIFY(image); + QTRY_COMPARE(image->property("status").toInt(), 1); + const QString original = row->property("path").toString(); + f.move(120); + QTRY_VERIFY(row && row->property("pooled").toBool()); + QTRY_VERIFY2(image->property("source").toUrl().isEmpty(), "Pooled thumbnail source was not cleared"); + for (auto *handler : row->findChildren()) + if (handler->inherits("QQuickHoverHandler")) + QVERIFY(!handler->property("enabled").toBool()); + int step = 0; + const auto seek = [&](const QString &kind) { + for (int tries = 0; tries < 20; ++tries) { + f.move((++step * 47 + 192) % 360); + QCoreApplication::processEvents(); + if (row && !row->property("pooled").toBool() && row->property("path").toString() != original && + row->property("kind") == kind) + return true; + } + return false; + }; + QVERIFY(seek("image")); + const QString picture = row->property("path").toString(); + f.move(qMax(0, row->property("index").toInt() - 4)); + QTRY_COMPARE(image->property("status").toInt(), 1); + QVERIFY(image->property("source").toUrl().toString().contains( + QString::fromLatin1(QUrl::toPercentEncoding(picture)))); + const auto frame = f.window()->grabWindow(); + const QPoint at = + image->mapToItem(f.window()->contentItem(), QPointF(image->width() / 2, image->height() / 2)) + .toPoint(); + QVERIFY(frame.rect().contains(at)); + const int number = QFileInfo(picture).completeBaseName().mid(4).toInt(); + QCOMPARE(frame.pixelColor(at).rgb(), QColor(number % 2 ? Qt::blue : Qt::red).rgb()); + QVERIFY(seek("text")); + QTRY_VERIFY(image->property("source").toUrl().isEmpty()); + } + + void listReuseKeepsTreeState_data() + { + QTest::addColumn("mirrored"); + QTest::newRow("ltr") << false; + QTest::newRow("rtl") << true; + } + + void listReuseKeepsTreeState() + { + QFETCH(bool, mirrored); + RowList f(false, true); + QVERIFY2(f.show(mirrored), qPrintable(f.error)); + QPointer row = f.item(4); + const QString original = row->property("path").toString(); + f.move(120); + QTRY_VERIFY(row && row->property("pooled").toBool()); + auto *model = f.backend.folder(); + model->setExpanded(model->indexOfPath(original), true); + QTRY_VERIFY(model->indexOfPath(original + "/nested") >= 0); + f.move(40); + QTRY_VERIFY(row && row->property("path").toString() != original && row->property("isDir").toBool()); + f.move(qMax(0, row->property("index").toInt() - 4)); + auto *arrow = rowArrow(row); + QVERIFY(arrow); + const QString reused = row->property("path").toString(); + const QPoint at = + arrow->mapToItem(f.window()->contentItem(), QPointF(arrow->width() / 2, arrow->height() / 2)) + .toPoint(); + rowClickAt(f.window(), at, 2000); + QTRY_VERIFY(row->property("expanded").toBool()); + auto *folder = f.backend.folder(); + QTRY_VERIFY(folder->indexOfPath(reused + "/nested") >= 0); + const int childIndex = folder->indexOfPath(reused + "/nested"); + QTRY_VERIFY(f.item(childIndex)); + QTRY_COMPARE(f.item(childIndex)->property("path").toString(), reused + "/nested"); + auto *child = f.item(childIndex); + QTRY_COMPARE(child->property("depth").toInt(), 1); + QQuickItem *layout = nullptr; + for (auto *item : child->childItems()) + if (item->inherits("QQuickRowLayout")) + layout = item; + QVERIFY(layout); + QCOMPARE(QQmlProperty(layout, "anchors.leftMargin").read().toReal(), 24.0); + auto *childArrow = rowArrow(child); + QVERIFY(childArrow); + const QPoint childAt = + childArrow + ->mapToItem(f.window()->contentItem(), QPointF(childArrow->width() / 2, childArrow->height() / 2)) + .toPoint(); + rowClickAt(f.window(), childAt, 2400); + QTRY_VERIFY(child->property("expanded").toBool()); + QTRY_VERIFY(folder->indexOfPath(reused + "/nested/leaf.txt") >= 0); + QTRY_VERIFY(f.item(folder->indexOfPath(reused + "/nested/leaf.txt"))); + QTRY_COMPARE(f.item(folder->indexOfPath(reused + "/nested/leaf.txt"))->property("path").toString(), + reused + "/nested/leaf.txt"); + QTRY_COMPARE(f.item(folder->indexOfPath(reused + "/nested/leaf.txt"))->property("depth").toInt(), 2); + rowClickAt(f.window(), at, 2800); + QTRY_VERIFY(!row->property("expanded").toBool()); + QTRY_VERIFY(folder->indexOfPath(reused + "/nested") == -1); + QVERIFY(folder->get(folder->indexOfPath(original)).value("expanded").toBool()); + f.move(120); + folder->setExpanded(folder->indexOfPath(original), false); + QTRY_VERIFY(folder->indexOfPath(original + "/nested") == -1); + f.move(0); + QTRY_VERIFY(f.item(folder->indexOfPath(original))); + QTRY_COMPARE(f.item(folder->indexOfPath(original))->property("path").toString(), original); + QTRY_VERIFY(!f.item(folder->indexOfPath(original))->property("expanded").toBool()); + QVERIFY(f.backend.opened.isEmpty()); + } + + void listReuseKeepsClicks_data() + { + QTest::addColumn("mirrored"); + QTest::newRow("ltr") << false; + QTest::newRow("rtl") << true; + } + + void listReuseKeepsClicks() + { + QFETCH(bool, mirrored); + + RowList f; + QVERIFY2(f.show(mirrored), qPrintable(f.error)); + QPointer row = f.item(4); + const QString original = row->property("path").toString(); + const QPoint at = f.point(row); + rowClickAt(f.window(), at, 1000); + QCOMPARE(f.backend.folder()->selectedPaths(), QStringList{original}); + // Another row becomes current, making the first one reusable. + f.list->setProperty("currentIndex", -1); + f.move(120); + f.move(240); + QTRY_VERIFY(row && row->property("path").toString() != original); + f.move(row->property("index").toInt() - 4); + QTRY_COMPARE(f.point(row), at); + const QString reused = row->property("path").toString(); + rowClickAt(f.window(), at, 1100); + QCOMPARE(f.backend.folder()->selectedPaths(), QStringList{reused}); + QVERIFY2(f.backend.opened.isEmpty(), "First click on the new file activated it"); + rowClickAt(f.window(), at, 1150); + QCOMPARE(f.backend.opened, QStringList{reused}); + // Releasing a press after the delegate changed cannot click its new file. + f.list->setProperty("currentIndex", -1); + f.move(0); + const auto selected = f.backend.folder()->selectedPaths(); + rowMouseAt(f.window(), f.point(f.item(4)), true, 2000); + f.move(120); + f.move(240); + rowMouseAt(f.window(), at, false, 2001); + QCOMPARE(f.backend.folder()->selectedPaths(), selected); + QCOMPARE(f.backend.opened, QStringList{reused}); + // A drag keeps its file identity and restores reuse when it ends. + f.move(0); + f.list->setProperty("currentIndex", 4); + QPointer drag = f.item(4); + const QString dragPath = drag->property("path").toString(); + f.eval(drag, "Drag.dragType = Drag.Internal; Drag.active = true"); + QVERIFY(!f.list->property("reuseItems").toBool()); + f.move(120); + f.move(240); + QVERIFY(!drag || drag->property("path").toString() == dragPath); + if (drag) + f.eval(drag, "Drag.active = false"); + QTRY_VERIFY(f.list->property("reuseItems").toBool()); + QVERIFY2(f.error.isEmpty(), qPrintable(f.error)); + f.move(0); + QPointer closing = f.item(4); + QVERIFY(f.eval(closing, "captureDragPicture()").toBool()); + f.root.reset(); + QVERIFY(!closing); + QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); + } + + void listReuseCancelsArrowPress_data() + { + QTest::addColumn("mirrored"); + QTest::newRow("ltr") << false; + QTest::newRow("rtl") << true; + } + + void listReuseCancelsArrowPress() + { + QFETCH(bool, mirrored); + RowList f(false, true); + QVERIFY2(f.show(mirrored), qPrintable(f.error)); + QPointer row = f.item(4); + const QString original = row->property("path").toString(); + auto *arrow = rowArrow(row); + QVERIFY(arrow); + const QPoint at = + arrow->mapToItem(f.window()->contentItem(), QPointF(arrow->width() / 2, arrow->height() / 2)) + .toPoint(); + QTest::mousePress(f.window(), Qt::LeftButton, Qt::NoModifier, at, 1); + for (int index = 0; index < f.backend.folder()->count(); ++index) + QVERIFY(!f.backend.folder()->get(index).value("expanded").toBool()); + f.move(120); + f.move(40); + { + QTRY_VERIFY(row && row->property("path").toString() != original && row->property("isDir").toBool()); + f.move(qMax(0, row->property("index").toInt() - 4)); + } + for (int index = 0; index < f.backend.folder()->count(); ++index) + QVERIFY(!f.backend.folder()->get(index).value("expanded").toBool()); + QTest::mouseRelease(f.window(), Qt::LeftButton, Qt::NoModifier, at, 1); + for (int index = 0; index < f.backend.folder()->count(); ++index) + QVERIFY(!f.backend.folder()->get(index).value("expanded").toBool()); + QVERIFY(f.backend.opened.isEmpty()); + const QString target = row->property("path").toString(); + QTest::mouseClick(f.window(), Qt::LeftButton, Qt::NoModifier, at, 1); + QTRY_VERIFY(f.backend.folder()->get(f.backend.folder()->indexOfPath(target)).value("expanded").toBool()); + for (int index = 0; index < f.backend.folder()->count(); ++index) { + const auto entry = f.backend.folder()->get(index); + if (entry.value("expanded").toBool()) + QCOMPARE(entry.value("path").toString(), target); + } + } + + void rowDragPicturesIgnorePreviousFiles() + { + RowList f; + QQmlComponent component(&f.engine); + component.setData(R"(import QtQuick + Window { + id: host + width: 900; height: 480; visible: true + property var callbacks: [] + function take() { return callbacks.shift() } + function clear() { callbacks = [] } + FileRow { + objectName: "row"; width: 900 + depth: 0; expanded: false; index: 0; name: "a"; path: "/a"; isDir: false; kind: "text"; mime: "text/plain" + extension: "TXT"; size: 1; modified: new Date(0); itemCount: -1; icon: ""; selected: false + function grabToImage(callback) { host.callbacks.push(callback); return true } + function pool() { ListView.pooled() } + function reuse() { ListView.reused() } + } + })", + QUrl::fromLocalFile(sourceFolder() + "/DelayedRowTest.qml")); + std::unique_ptr root(component.create()); + QVERIFY2(root, qPrintable(component.errorString())); + QPointer row = root->findChild("row"); + QVERIFY(row); + // This test delivers replies explicitly, independent of the mouse. + for (auto *handler : row->findChildren()) + if (handler->inherits("QQuickHoverHandler")) + handler->setProperty("enabled", false); + QVERIFY(QMetaObject::invokeMethod(root.get(), "clear")); + QVERIFY(f.eval(row, "captureDragPicture()").toBool()); + QVariant callback; + QVERIFY(QMetaObject::invokeMethod(root.get(), "take", Q_RETURN_ARG(QVariant, callback))); + QJSValue old = callback.value(); + QVERIFY(old.isCallable()); + f.eval(row, "pool()"); + row->setProperty("path", "/b"); + f.eval(row, "reuse()"); + f.eval(row, "pool()"); + row->setProperty("path", "/a"); + f.eval(row, "reuse()"); + const QString dragFile = f.home.filePath("drag.png"); + QImage pixels(16, 16, QImage::Format_RGB32); + pixels.fill(Qt::red); + QVERIFY(pixels.save(dragFile)); + const QString pictureUrl = QUrl::fromLocalFile(dragFile).toString(); + QJSValue picture = f.engine.newObject(); + picture.setProperty("url", pictureUrl); + QVERIFY(!old.call({picture}).isError()); + QCOMPARE(f.eval(row, "String(Drag.imageSource)").toString(), QString()); + // The current request still succeeds: rejecting stale ones must not + // disable drag pictures altogether. + QVERIFY(f.eval(row, "captureDragPicture()").toBool()); + QVERIFY(QMetaObject::invokeMethod(root.get(), "take", Q_RETURN_ARG(QVariant, callback))); + QJSValue current = callback.value(); + QVERIFY(current.isCallable()); + QVERIFY(!current.call({picture}).isError()); + QCOMPARE(f.eval(row, "String(Drag.imageSource)").toString(), pictureUrl); + QVERIFY(f.eval(row, "captureDragPicture()").toBool()); + QVERIFY(QMetaObject::invokeMethod(root.get(), "take", Q_RETURN_ARG(QVariant, callback))); + QJSValue pending = callback.value(); + QVERIFY(pending.isCallable()); + root.reset(); + QVERIFY(row.isNull()); + QVERIFY(!pending.call({picture}).isError()); + QVERIFY2(f.error.isEmpty(), qPrintable(f.error)); + } + // The list's keys for its tree, as the Finder's: → opens a folder in // place, then steps into it; ← steps back out to the folder, closes it, // and from the top goes up a folder. A click on a folder's arrow opens From 7c2593c006e804e4c314705bf4e031723f56f1f9 Mon Sep 17 00:00:00 2001 From: Kirill Kostin <15322854+k-kostin@users.noreply.github.com> Date: Thu, 19 Nov 2026 08:07:07 +0300 Subject: [PATCH 4/4] Check thumbnail pixels at display scale and assert reused tree arrows --- tests/folio_tests.cpp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/tests/folio_tests.cpp b/tests/folio_tests.cpp index 2e72474f..a969ece7 100644 --- a/tests/folio_tests.cpp +++ b/tests/folio_tests.cpp @@ -7402,8 +7402,14 @@ private slots: QVERIFY(image); QTRY_COMPARE(image->property("status").toInt(), 1); const QString original = row->property("path").toString(); + f.eval(row, "Drag.imageSource = Qt.resolvedUrl(path); Drag.mimeData = {'text/uri-list': fileOps.uriList([path])}"); + QCOMPARE(f.eval(row, "Object.keys(Drag.mimeData).length").toInt(), 1); + QVERIFY(!f.eval(row, "String(Drag.imageSource)").toString().isEmpty()); + QVERIFY2(f.error.isEmpty(), qPrintable(f.error)); f.move(120); QTRY_VERIFY(row && row->property("pooled").toBool()); + QCOMPARE(f.eval(row, "Object.keys(Drag.mimeData).length").toInt(), 0); + QCOMPARE(f.eval(row, "String(Drag.imageSource)").toString(), QString()); QTRY_VERIFY2(image->property("source").toUrl().isEmpty(), "Pooled thumbnail source was not cleared"); for (auto *handler : row->findChildren()) if (handler->inherits("QQuickHoverHandler")) @@ -7427,13 +7433,14 @@ private slots: QString::fromLatin1(QUrl::toPercentEncoding(picture)))); const auto frame = f.window()->grabWindow(); const QPoint at = - image->mapToItem(f.window()->contentItem(), QPointF(image->width() / 2, image->height() / 2)) - .toPoint(); + (image->mapToItem(f.window()->contentItem(), QPointF(image->width() / 2, image->height() / 2)) * + f.window()->devicePixelRatio()).toPoint(); QVERIFY(frame.rect().contains(at)); const int number = QFileInfo(picture).completeBaseName().mid(4).toInt(); QCOMPARE(frame.pixelColor(at).rgb(), QColor(number % 2 ? Qt::blue : Qt::red).rgb()); QVERIFY(seek("text")); QTRY_VERIFY(image->property("source").toUrl().isEmpty()); + QVERIFY2(f.error.isEmpty(), qPrintable(f.error)); } void listReuseKeepsTreeState_data() @@ -7460,12 +7467,22 @@ private slots: f.move(qMax(0, row->property("index").toInt() - 4)); auto *arrow = rowArrow(row); QVERIFY(arrow); + QQuickItem *glyph = nullptr; + for (auto *item : arrow->childItems()) + if (item->property("name").isValid()) + glyph = item; + QVERIFY(glyph); + QVERIFY(glyph->isVisible()); + QCOMPARE(glyph->property("name").toString(), mirrored ? QString("back") : QString("forward")); + QCOMPARE(glyph->rotation(), 0.0); const QString reused = row->property("path").toString(); const QPoint at = arrow->mapToItem(f.window()->contentItem(), QPointF(arrow->width() / 2, arrow->height() / 2)) .toPoint(); rowClickAt(f.window(), at, 2000); QTRY_VERIFY(row->property("expanded").toBool()); + QTRY_COMPARE(glyph->rotation(), mirrored ? -90.0 : 90.0); + QVERIFY(glyph->isVisible()); auto *folder = f.backend.folder(); QTRY_VERIFY(folder->indexOfPath(reused + "/nested") >= 0); const int childIndex = folder->indexOfPath(reused + "/nested"); @@ -7494,6 +7511,8 @@ private slots: QTRY_COMPARE(f.item(folder->indexOfPath(reused + "/nested/leaf.txt"))->property("depth").toInt(), 2); rowClickAt(f.window(), at, 2800); QTRY_VERIFY(!row->property("expanded").toBool()); + QTRY_COMPARE(glyph->rotation(), 0.0); + QVERIFY(glyph->isVisible()); QTRY_VERIFY(folder->indexOfPath(reused + "/nested") == -1); QVERIFY(folder->get(folder->indexOfPath(original)).value("expanded").toBool()); f.move(120); @@ -7611,6 +7630,13 @@ private slots: if (entry.value("expanded").toBool()) QCOMPARE(entry.value("path").toString(), target); } + // Returning to the same file must not revive its interrupted press. + QTest::mousePress(f.window(), Qt::LeftButton, Qt::NoModifier, at, 1); + f.eval(row, "ListView.pooled()"); + f.eval(row, "ListView.reused()"); + QTest::mouseRelease(f.window(), Qt::LeftButton, Qt::NoModifier, at, 1); + QVERIFY(f.backend.folder()->get(f.backend.folder()->indexOfPath(target)).value("expanded").toBool()); + QVERIFY2(f.error.isEmpty(), qPrintable(f.error)); } void rowDragPicturesIgnorePreviousFiles()