Quarts/Quartz/qml/LoadFolderDialog.qml
Станислав Хозяенок b786de552d bug fux add 1
2025-05-28 13:21:37 +07:00

98 lines
2.9 KiB
QML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import Qt.labs.folderlistmodel 2.15
Dialog {
id: folderDialog
title: "Выберите папку"
modal: true
standardButtons: Dialog.Ok | Dialog.Cancel
property string selectedFolder: ""
width: 200
height: 400
anchors.centerIn: Overlay.overlay
ColumnLayout {
anchors.fill: parent
// Панель навигации
RowLayout {
Button {
text: "↑ Наверх"
onClicked: {
// Проверяем, не является ли текущая папка корнем
if (folderModel.folder.toString() === "file:///" ||
folderModel.folder.toString().match(/^file:\/\/\/[A-Za-z]:\/?$/)) {
console.log("Уже в корне диска, нельзя подняться выше");
return;
}
folderModel.folder = folderModel.parentFolder;
}
enabled: folderModel.parentFolder !== ""
}
TextField {
id: pathField
Layout.fillWidth: true
text: folderModel.folder.toString().replace("file:///", "")
onAccepted: folderModel.folder = "file://" + text
}
}
// Список папок
GridView {
id: folderView
Layout.fillWidth: true
Layout.fillHeight: true
clip: true
model: folderModel
cellWidth: 150
cellHeight: 80
delegate: Button {
width: folderView.width
text: fileName
onClicked: {
if (fileIsDir) {
folderModel.folder = folder + "/" + fileName
}
}
onDoubleClicked: {
selectedFolder = folderModel.folder + "/" + fileName
folderDialog.accept()
}
}
ScrollBar.vertical: ScrollBar {}
}
}
FolderListModel {
id: folderModel
folder: "file:///" + Qt.resolvedUrl(".").toString().substring(8) // Убираем лишний "file:///"
showDirs: true
showFiles: false
nameFilters: ["*"] // Показываем все папки
onFolderChanged: {
pathField.text = folder.toString().replace("file:///", "")
selectedFolder = folder
}
}
// Функция для открытия диалога с начальным путем
function openWithPath(initialPath) {
folderModel.folder = initialPath //"file://" + initialPath
open()
}
onAccepted: {
console.log("Выбрана папка:", selectedFolder)
}
}