From 3c5e1ad2735fdab7aef744fbed59b2abb5f601a6 Mon Sep 17 00:00:00 2001 From: Aurore LAFAURIE Date: Thu, 20 Jun 2024 14:43:00 +0200 Subject: [PATCH] [ui] Format GB to string for occupied cache size --- meshroom/ui/qml/Utils/format.js | 58 ++++++++++++++++++----- meshroom/ui/qml/Viewer/SequencePlayer.qml | 9 ++-- 2 files changed, 50 insertions(+), 17 deletions(-) diff --git a/meshroom/ui/qml/Utils/format.js b/meshroom/ui/qml/Utils/format.js index 6f70173941..139dc11ced 100644 --- a/meshroom/ui/qml/Utils/format.js +++ b/meshroom/ui/qml/Utils/format.js @@ -10,16 +10,16 @@ function intToString(v) { // Convert a plain text to an html escaped string. function plainToHtml(t) { - var escaped = t.replace(/&/g, '&').replace(//g, '>') // escape text - return escaped.replace(/\n/g, '
') // replace line breaks + var escaped = t.replace(/&/g, '&').replace(//g, '>') // escape text + return escaped.replace(/\n/g, '
') // replace line breaks } function divmod(x, y) { // Perform the division and get the quotient - const quotient = Math.floor(x / y); + const quotient = Math.floor(x / y) // Compute the remainder - const remainder = x % y; - return [quotient, remainder]; + const remainder = x % y + return [quotient, remainder] } function sec2timeHMS(totalSeconds) { @@ -30,7 +30,7 @@ function sec2timeHMS(totalSeconds) { hours: hours, minutes: minutes, seconds: seconds - }; + } } function sec2timecode(timeSeconds) { @@ -43,22 +43,22 @@ function sec2timecode(timeSeconds) { function sec2timeStr(timeSeconds) { // Need to decide the rounding precision first // to propagate the right values - if(timeSeconds >= 60.0) { + if (timeSeconds >= 60.0) { timeSeconds = Math.round(timeSeconds) } else { timeSeconds = parseFloat(timeSeconds.toFixed(2)) } var timeObj = sec2timeHMS(timeSeconds) var timeStr = "" - if(timeObj.hours > 0) { + if (timeObj.hours > 0) { timeStr += timeObj.hours + "h" } - if(timeObj.hours > 0 || timeObj.minutes > 0) { + if (timeObj.hours > 0 || timeObj.minutes > 0) { timeStr += timeObj.minutes + "m" } - if(timeObj.hours === 0) { + if (timeObj.hours === 0) { // seconds only matter if the elapsed time is less than 1 hour - if(timeObj.minutes === 0) { + if (timeObj.minutes === 0) { // If less than a minute, keep millisecond precision timeStr += timeObj.seconds.toFixed(2) + "s" } else { @@ -68,3 +68,39 @@ function sec2timeStr(timeSeconds) { } return timeStr } + +function GB2GBMBKB(GB) { + // Convert GB to GB, MB, KB + var GBInt = Math.floor(GB) + var MB = Math.floor((GB - GBInt) * 1024) + var KB = Math.floor(((GB - GBInt) * 1024 - MB) * 1024) + return { + GB: GBInt, + MB: MB, + KB: KB + } +} + +function GB2SizeStr(GB) { + // Convert GB to a human readable size string + // e.g. 1.23GB, 456MB, 789KB + // We only use one unit at a time + var sizeObj = GB2GBMBKB(GB) + var sizeStr = "" + if (sizeObj.GB > 0) { + sizeStr += sizeObj.GB + if (sizeObj.MB > 0 && sizeObj.GB < 10) { + sizeStr += "." + Math.floor(sizeObj.MB / 1024 * 1000) + } + sizeStr += "GB" + } else if (sizeObj.MB > 0) { + sizeStr = sizeObj.MB + if (sizeObj.KB > 0 && sizeObj.MB < 10) { + sizeStr += "." + Math.floor(sizeObj.KB / 1024 * 1000) + } + sizeStr += "MB" + } else if (sizeObj.GB === 0 && sizeObj.MB === 0) { + sizeStr += sizeObj.KB + "KB" + } + return sizeStr +} \ No newline at end of file diff --git a/meshroom/ui/qml/Viewer/SequencePlayer.qml b/meshroom/ui/qml/Viewer/SequencePlayer.qml index 4962657695..647017a7a9 100644 --- a/meshroom/ui/qml/Viewer/SequencePlayer.qml +++ b/meshroom/ui/qml/Viewer/SequencePlayer.qml @@ -485,18 +485,15 @@ FloatingPane { ProgressBar { id: occupiedCacheProgressBar + property string occupiedCache: viewer.ramInfo ? Format.GB2SizeStr(viewer.ramInfo.y) : 0 + width: parent.width from: 0 to: settings_SequencePlayer.maxCacheMemory value: viewer && viewer.ramInfo != undefined ? viewer.ramInfo.y : 0 - ToolTip.text: { - if (viewer && viewer.ramInfo != undefined) { - return "Occupied cache: "+ viewer.ramInfo.y + " GB" + "\n" + "On max cache memory set: " + settings_SequencePlayer.maxCacheMemory + " GB" - } - return "Unknown occupied cache (max cache memory set: " + settings_SequencePlayer.maxCacheMemory + ")" - } + ToolTip.text: "Occupied cache: " + occupiedCache + "\n" + "On max cache memory set: " + settings_SequencePlayer.maxCacheMemory + " GB" ToolTip.visible: hovered ToolTip.delay: 100 }