diff --git a/src/FileListView.qml b/src/FileListView.qml new file mode 100644 index 00000000..3178b320 --- /dev/null +++ b/src/FileListView.qml @@ -0,0 +1,15 @@ +import QtQuick +import QtQuick.Controls + +// A folder's items one per row, as the list and each of the columns show +// them: clipped to its edges, scrolled by the wheel but not dragged, with +// Folio's scroll bar. +ListView { + clip: true + acceptedButtons: Qt.NoButton + boundsBehavior: Flickable.StopAtBounds + // No cache buffer, here or in the grid: Qt's 16 ms pause before filling + // one can leave an idle window drawing every refresh. + cacheBuffer: 0 + ScrollBar.vertical: FolioScrollBar { } +} diff --git a/src/FolderColumns.qml b/src/FolderColumns.qml index 7e802fff..162565ab 100644 --- a/src/FolderColumns.qml +++ b/src/FolderColumns.qml @@ -93,14 +93,10 @@ Item { required property string next height: row.height - ListView { + FileListView { id: column width: view.columnWidth height: parent.height - clip: true - acceptedButtons: Qt.NoButton - boundsBehavior: Flickable.StopAtBounds - ScrollBar.vertical: FolioScrollBar { } model: FolderModel { id: folder path: ancestor.path @@ -139,22 +135,18 @@ Item { } // The folder being shown: its selection is the window's. - ListView { + FileListView { id: here width: view.columnWidth height: row.height - clip: true focus: true keyNavigationEnabled: true // No cursor of its own to start with: the pane puts it back // where the last view had it, and one on the first item would // select that instead. currentIndex: -1 - acceptedButtons: Qt.NoButton - boundsBehavior: Flickable.StopAtBounds highlightFollowsCurrentItem: false model: backend.folder - ScrollBar.vertical: FolioScrollBar { } TapHandler { acceptedButtons: Qt.RightButton @@ -189,15 +181,11 @@ Item { Separator { } // A look inside the selected folder; clicking in it goes there. - ListView { + FileListView { id: inside width: view.columnWidth height: row.height visible: view.selected.isDir === true - clip: true - acceptedButtons: Qt.NoButton - boundsBehavior: Flickable.StopAtBounds - ScrollBar.vertical: FolioScrollBar { } TapHandler { acceptedButtons: Qt.RightButton onTapped: (point) => { diff --git a/src/FolderGrid.qml b/src/FolderGrid.qml index 37385b8a..9c5e0cfe 100644 --- a/src/FolderGrid.qml +++ b/src/FolderGrid.qml @@ -60,6 +60,8 @@ GridView { // still scroll, which turning the view's interactive off would stop too. acceptedButtons: Qt.NoButton boundsBehavior: Flickable.StopAtBounds + // No cache buffer, as in FileListView. + cacheBuffer: 0 model: backend.folder // Tiles grow with the zoom; the name and details under them don't. A // narrow pane (one side of a split) caps it at a tile its width holds. diff --git a/src/FolderList.qml b/src/FolderList.qml index 8e93a633..7f76beb3 100644 --- a/src/FolderList.qml +++ b/src/FolderList.qml @@ -3,7 +3,7 @@ import QtQuick.Controls // The folder as a list: name, size and date (the date, then the size, step // aside in a narrow window). No headings: the sort menu and S sort it. -ListView { +FileListView { id: list function select(row, keep) { selecting.select(row, keep) } @@ -41,17 +41,13 @@ ListView { onTapped: (point) => list.contextMenu(selecting.menuAt(point), backend.path, point.scenePosition) } - clip: true focus: true keyNavigationEnabled: true // No cursor of its own to start with: the pane puts it back where the // last view had it, and one on the first item would select that instead. currentIndex: -1 - acceptedButtons: Qt.NoButton - boundsBehavior: Flickable.StopAtBounds highlightFollowsCurrentItem: false model: backend.folder - ScrollBar.vertical: FolioScrollBar { } delegate: FileRow { width: list.width diff --git a/src/resources.qrc b/src/resources.qrc index a4118dfc..72b8f406 100644 --- a/src/resources.qrc +++ b/src/resources.qrc @@ -20,6 +20,7 @@ FolioMenuItem.qml MenuLine.qml FolioScrollBar.qml + FileListView.qml PlainButton.qml PlainField.qml SortMenu.qml diff --git a/tests/folio_tests.cpp b/tests/folio_tests.cpp index e5278791..f5232193 100644 --- a/tests/folio_tests.cpp +++ b/tests/folio_tests.cpp @@ -5731,6 +5731,60 @@ private slots: } } + void folderViewsKeepNoCacheBuffer_data() + { + QTest::addColumn("pane"); + QTest::newRow("grid") << QString("FolderGrid"); + QTest::newRow("list") << QString("FolderList"); + QTest::newRow("columns") << QString("FolderColumns"); + } + + void folderViewsKeepNoCacheBuffer() + { + // An idle window draws no frames offscreen, so this checks the cause + // instead: Qt's pause before filling a cache buffer can leave it drawing. + QFETCH(QString, pane); + QTemporaryDir home; + QVERIFY(QDir(home.path()).mkpath("a/b")); + Backend backend(home.path()); + backend.navigate(home.filePath("a")); + QTRY_COMPARE(backend.folder()->rowCount(), 1); + Theme theme(home.filePath("theme")); + FileOps fileOps; + Translator translator(home.filePath("language"), home.path()); + Thumbnails thumbnails(home.filePath("cache"), {home.filePath("none")}); + qmlRegisterType("Folio", 1, 0, "FolderModel"); + QQmlEngine engine; + engine.rootContext()->setContextProperty("backend", &backend); + engine.rootContext()->setContextProperty("theme", &theme); + engine.rootContext()->setContextProperty("fileOps", &fileOps); + engine.rootContext()->setContextProperty("translator", &translator); + engine.rootContext()->setContextProperty("plugins", QVariantMap{{"views", QVariantMap{}}}); + engine.addImageProvider("thumb", new ThumbnailProvider(&thumbnails)); + QQmlComponent component(&engine); + component.setData(QString(R"( + import QtQuick + Window { + width: 800; height: 300; visible: true + %1 { id: pane; anchors.fill: parent } + function buffersIn(item) { + const own = item instanceof ListView || item instanceof GridView ? [item.cacheBuffer] : [] + return own.concat(...Array.from(item.children, child => buffersIn(child))) + } + function buffers() { return buffersIn(pane) } + } + )").arg(pane).toUtf8(), QUrl::fromLocalFile(sourceFolder() + "/CacheBufferTest.qml")); + std::unique_ptr root(component.create()); + QVERIFY2(root, qPrintable(component.errorString())); + const auto buffers = [&] { + QVariant found; + QMetaObject::invokeMethod(root.get(), "buffers", Q_RETURN_ARG(QVariant, found)); + return found.toList(); + }; + QTRY_COMPARE(buffers().size(), pane == "FolderColumns" ? 3 : 1); + QCOMPARE(buffers(), QVariantList(buffers().size(), 0)); + } + void themeFallsBack() { QTemporaryDir dir;