From 6d4ea381f0b9420b2ae89805915a985b743eb4c9 Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Sun, 29 Oct 2017 11:44:36 +0100 Subject: [PATCH] Create cost specification tooltip --- resources/qml/Sidebar.qml | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/resources/qml/Sidebar.qml b/resources/qml/Sidebar.qml index ed6b07cc4e..582fb346c5 100644 --- a/resources/qml/Sidebar.qml +++ b/resources/qml/Sidebar.qml @@ -355,7 +355,7 @@ Rectangle { if(!print_time[feature].isTotalDurationZero) { - content += "" + feature + + content += "" + feature + ":" + "  " + print_time[feature].getDisplayString(UM.DurationFormat.Short) + "  " + Math.round(100 * parseInt(print_time[feature].getDisplayString(UM.DurationFormat.Seconds)) / total_seconds) + "%" + ""; @@ -382,12 +382,16 @@ Rectangle color: UM.Theme.getColor("text_subtext") elide: Text.ElideMiddle width: parent.width + property string tooltipText: "test" text: { var lengths = []; + var total_length = 0; var weights = []; + var total_weight = 0; var costs = []; - var someCostsKnown = false; + var total_cost = 0; + var some_costs_known = false; if(base.printMaterialLengths) { for(var index = 0; index < base.printMaterialLengths.length; index++) { @@ -399,8 +403,12 @@ Rectangle costs.push(cost); if(cost > 0) { - someCostsKnown = true; + some_costs_known = true; } + + total_length += base.printMaterialLengths[index]; + total_weight += base.printMaterialWeights[index]; + total_cost += base.printMaterialCosts[index]; } } } @@ -410,10 +418,21 @@ Rectangle weights = ["0"]; costs = ["0.00"]; } - if(someCostsKnown) + + tooltipText = catalog.i18nc("@tooltip", "Cost specification
"); + for(var index = 0; index < lengths.length; index++) + { + tooltipText += catalog.i18nc("@label Print estimates: m for meters, g for grams, %4 is currency and %3 is print cost", "").arg(index + 1).arg(lengths[index]) + .arg(weights[index]).arg(costs[index]).arg(UM.Preferences.getValue("cura/currency")); + } + tooltipText += catalog.i18nc("@label Print totals: m for meters, g for grams, %4 is currency and %3 is print cost", "").arg(total_length.toFixed(2)) + .arg(Math.round(total_weight)).arg(total_cost.toFixed(2)).arg(UM.Preferences.getValue("cura/currency")); + tooltipText += "
Extruder %0:  %1m  %2g  %4 %3
Total:  %1m  %2g  %4 %3
"; + + if(some_costs_known) { return catalog.i18nc("@label Print estimates: m for meters, g for grams, %4 is currency and %3 is print cost", "%1m / ~ %2g / ~ %4 %3").arg(lengths.join(" + ")) - .arg(weights.join(" + ")).arg(costs.join(" + ")).arg(UM.Preferences.getValue("cura/currency")); + .arg(Math.round(total_weight)).arg(total_cost.toFixed(2)).arg(UM.Preferences.getValue("cura/currency")); } else { @@ -431,15 +450,7 @@ Rectangle if(base.printDuration.valid && !base.printDuration.isTotalDurationZero) { - // All the time information for the different features is achieved - var print_time = PrintInformation.getFeaturePrintTimes(); - var total_seconds = parseInt(base.printDuration.getDisplayString(UM.DurationFormat.Seconds)) - - // A message is created and displayed when the user hover the time label - var content = catalog.i18nc("@tooltip", "Cost specification
"); - content += "
"; - - base.showTooltip(parent, Qt.point(-UM.Theme.getSize("sidebar_margin").width, 0), content); + base.showTooltip(parent, Qt.point(-UM.Theme.getSize("sidebar_margin").width, 0), costSpec.tooltipText); } } onExited: