mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-05-18 11:36:27 +02:00
[ui] add string <--> file representation convertors
* convenient methods to conform strings to Qt file reprensentation using the "file:/" protocol prefix * use those methodes when manipulating files
This commit is contained in:
parent
62726b4663
commit
2cdc83f06f
7 changed files with 38 additions and 6 deletions
|
@ -2,6 +2,7 @@ import QtQuick 2.9
|
||||||
import QtQuick.Layouts 1.3
|
import QtQuick.Layouts 1.3
|
||||||
import QtQuick.Controls 2.2
|
import QtQuick.Controls 2.2
|
||||||
import MaterialIcons 2.2
|
import MaterialIcons 2.2
|
||||||
|
import Utils 1.0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
A component to display and edit a Node's attributes.
|
A component to display and edit a Node's attributes.
|
||||||
|
@ -43,7 +44,7 @@ ColumnLayout {
|
||||||
id: settingsMenu
|
id: settingsMenu
|
||||||
MenuItem {
|
MenuItem {
|
||||||
text: "Open Cache Folder"
|
text: "Open Cache Folder"
|
||||||
onClicked: Qt.openUrlExternally("file://" + node.internalFolder)
|
onClicked: Qt.openUrlExternally(Filepath.stringToFile(node.internalFolder))
|
||||||
ToolTip.text: node.internalFolder
|
ToolTip.text: node.internalFolder
|
||||||
ToolTip.visible: hovered
|
ToolTip.visible: hovered
|
||||||
ToolTip.delay: 500
|
ToolTip.delay: 500
|
||||||
|
|
|
@ -108,7 +108,7 @@ RowLayout {
|
||||||
_reconstruction.setAttribute(root.attribute, Number(value))
|
_reconstruction.setAttribute(root.attribute, Number(value))
|
||||||
break;
|
break;
|
||||||
case "File":
|
case "File":
|
||||||
_reconstruction.setAttribute(root.attribute, value.replace("file://", "").trim())
|
_reconstruction.setAttribute(root.attribute, Filepath.fileToString(value.trim()))
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
_reconstruction.setAttribute(root.attribute, value.trim())
|
_reconstruction.setAttribute(root.attribute, value.trim())
|
||||||
|
|
|
@ -3,6 +3,8 @@ import QtQuick.Controls 2.3
|
||||||
import QtQuick.Controls 1.4 as Controls1 // SplitView
|
import QtQuick.Controls 1.4 as Controls1 // SplitView
|
||||||
import QtQuick.Layouts 1.3
|
import QtQuick.Layouts 1.3
|
||||||
import MaterialIcons 2.2
|
import MaterialIcons 2.2
|
||||||
|
import Utils 1.0
|
||||||
|
|
||||||
import "common.js" as Common
|
import "common.js" as Common
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -195,7 +197,7 @@ FocusScope {
|
||||||
function loadCurrentFile(keepCursorPosition)
|
function loadCurrentFile(keepCursorPosition)
|
||||||
{
|
{
|
||||||
var xhr = new XMLHttpRequest;
|
var xhr = new XMLHttpRequest;
|
||||||
xhr.open("GET", fileSelector.currentFile);
|
xhr.open("GET", Filepath.stringToFile(fileSelector.currentFile));
|
||||||
xhr.onreadystatechange = function() {
|
xhr.onreadystatechange = function() {
|
||||||
if(xhr.readyState == XMLHttpRequest.HEADERS_RECEIVED)
|
if(xhr.readyState == XMLHttpRequest.HEADERS_RECEIVED)
|
||||||
{
|
{
|
||||||
|
|
|
@ -68,7 +68,7 @@ Item {
|
||||||
Image {
|
Image {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.margins: 4
|
anchors.margins: 4
|
||||||
source: imageDelegate.source
|
source: Filepath.stringToFile(imageDelegate.source)
|
||||||
sourceSize: Qt.size(100, 100)
|
sourceSize: Qt.size(100, 100)
|
||||||
asynchronous: true
|
asynchronous: true
|
||||||
autoTransform: true
|
autoTransform: true
|
||||||
|
|
|
@ -22,3 +22,29 @@ function extension(path) {
|
||||||
function isFile(path) {
|
function isFile(path) {
|
||||||
return extension(path) !== ""
|
return extension(path) !== ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Conform 'path' to the Qt file representation relying on "file:" protocol prefix
|
||||||
|
function stringToFile(path) {
|
||||||
|
// already containing the file protocol
|
||||||
|
if(path.startsWith("file:"))
|
||||||
|
return path
|
||||||
|
// network path
|
||||||
|
if(path.startsWith("//"))
|
||||||
|
return "file:" + path
|
||||||
|
// assumed local path
|
||||||
|
if(path.trim() == "")
|
||||||
|
return ""
|
||||||
|
return "file:/" + path
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Remove any "file:" protocol prefix from 'path'
|
||||||
|
function fileToString(path)
|
||||||
|
{
|
||||||
|
// local path
|
||||||
|
if(path.startsWith("file:///"))
|
||||||
|
return path.replace("file:///", "")
|
||||||
|
// network path
|
||||||
|
else if(path.startsWith("file://"))
|
||||||
|
return path.replace("file://", "")
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
|
|
@ -2,12 +2,13 @@ import QtQuick 2.7
|
||||||
import QtQuick.Controls 2.0
|
import QtQuick.Controls 2.0
|
||||||
import QtQuick.Layouts 1.3
|
import QtQuick.Layouts 1.3
|
||||||
import MaterialIcons 2.2
|
import MaterialIcons 2.2
|
||||||
|
import Utils 1.0
|
||||||
|
|
||||||
FocusScope {
|
FocusScope {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
clip: true
|
clip: true
|
||||||
property alias source: image.source
|
property string source
|
||||||
property var metadata
|
property var metadata
|
||||||
|
|
||||||
// slots
|
// slots
|
||||||
|
@ -48,6 +49,7 @@ FocusScope {
|
||||||
fillMode: Image.PreserveAspectFit
|
fillMode: Image.PreserveAspectFit
|
||||||
autoTransform: true
|
autoTransform: true
|
||||||
onWidthChanged: if(status==Image.Ready) fit()
|
onWidthChanged: if(status==Image.Ready) fit()
|
||||||
|
source: Filepath.stringToFile(root.source)
|
||||||
onStatusChanged: {
|
onStatusChanged: {
|
||||||
// update cache source when image is loaded
|
// update cache source when image is loaded
|
||||||
if(status === Image.Ready)
|
if(status === Image.Ready)
|
||||||
|
|
|
@ -31,6 +31,7 @@ Item {
|
||||||
// Load a 3D media file in the 3D viewer
|
// Load a 3D media file in the 3D viewer
|
||||||
function load3DMedia(filepath)
|
function load3DMedia(filepath)
|
||||||
{
|
{
|
||||||
|
filepath = Filepath.stringToFile(filepath)
|
||||||
if(Filepath.extension(filepath) === ".abc")
|
if(Filepath.extension(filepath) === ".abc")
|
||||||
{
|
{
|
||||||
viewer3D.abcSource = filepath
|
viewer3D.abcSource = filepath
|
||||||
|
@ -154,7 +155,7 @@ Item {
|
||||||
anchors.bottomMargin: 10
|
anchors.bottomMargin: 10
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
visible: meshFile != '' && (viewer3D.source != meshFile)
|
visible: meshFile != '' && (viewer3D.source != meshFile)
|
||||||
onClicked: viewer3D.source = meshFile
|
onClicked: load3DMedia(meshFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue