Merge pull request #2882 from fieldOfView/fix_sidebar_estimation_tooltips

Tweak layout and alignment of print time and cost estimation
This commit is contained in:
ChrisTerBeke 2017-12-01 15:08:37 +01:00 committed by GitHub
commit c3ddd12e16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -350,21 +350,20 @@ Rectangle
var total_seconds = parseInt(base.printDuration.getDisplayString(UM.DurationFormat.Seconds)) var total_seconds = parseInt(base.printDuration.getDisplayString(UM.DurationFormat.Seconds))
// A message is created and displayed when the user hover the time label // A message is created and displayed when the user hover the time label
var content = catalog.i18nc("@tooltip", "<b>Time specification</b><br/><table>"); var tooltip_html = "<b>%1</b><br/><table width=\"100%\">".arg(catalog.i18nc("@tooltip", "Time specification"));
for(var feature in print_time) for(var feature in print_time)
{ {
if(!print_time[feature].isTotalDurationZero) if(!print_time[feature].isTotalDurationZero)
{ {
content += "<tr><td colspan='2'>" + feature + "</td></tr>" + tooltip_html += "<tr><td>" + feature + ":</td>" +
"<tr>" + "<td align=\"right\" valign=\"bottom\">&nbsp;&nbsp;%1</td>".arg(print_time[feature].getDisplayString(UM.DurationFormat.ISO8601).slice(0,-3)) +
"<td width='60%'>" + print_time[feature].getDisplayString(UM.DurationFormat.Short) + "</td>" + "<td align=\"right\" valign=\"bottom\">&nbsp;&nbsp;%1%</td>".arg(Math.round(100 * parseInt(print_time[feature].getDisplayString(UM.DurationFormat.Seconds)) / total_seconds)) +
"<td width='40%'>&nbsp;&nbsp;" + Math.round(100 * parseInt(print_time[feature].getDisplayString(UM.DurationFormat.Seconds)) / total_seconds) + "%" +
"</td></tr>"; "</td></tr>";
} }
} }
content += "</table>"; tooltip_html += "</table>";
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), tooltip_html);
} }
} }
onExited: onExited:
@ -376,9 +375,26 @@ Rectangle
Label Label
{ {
function formatRow(items)
{
var row_html = "<tr>";
for(var item = 0; item < items.length; item++)
{
if (item == 0)
{
row_html += "<td valign=\"bottom\">%1</td>".arg(items[item]);
}
else
{
row_html += "<td align=\"right\" valign=\"bottom\">&nbsp;&nbsp;%1</td>".arg(items[item]);
}
}
row_html += "</tr>";
return row_html;
}
function getSpecsData(){ function getSpecsData()
{
var lengths = []; var lengths = [];
var total_length = 0; var total_length = 0;
var weights = []; var weights = [];
@ -387,7 +403,8 @@ Rectangle
var total_cost = 0; var total_cost = 0;
var some_costs_known = false; var some_costs_known = false;
var names = []; var names = [];
if(base.printMaterialLengths) { if(base.printMaterialLengths)
{
for(var index = 0; index < base.printMaterialLengths.length; index++) for(var index = 0; index < base.printMaterialLengths.length; index++)
{ {
if(base.printMaterialLengths[index] > 0) if(base.printMaterialLengths[index] > 0)
@ -415,34 +432,28 @@ Rectangle
costs = ["0.00"]; costs = ["0.00"];
} }
var tooltip_html = "<b>%1</b><br/><table>".arg(catalog.i18nc("@label", "Cost specification")); var tooltip_html = "<b>%1</b><br/><table width=\"100%\">".arg(catalog.i18nc("@label", "Cost specification"));
for(var index = 0; index < lengths.length; index++) for(var index = 0; index < lengths.length; index++)
{ {
var item_strings = [ tooltip_html += formatRow([
"%1:".arg(names[index]), "%1:".arg(names[index]),
catalog.i18nc("@label m for meter", "%1m").arg(lengths[index]), catalog.i18nc("@label m for meter", "%1m").arg(lengths[index]),
catalog.i18nc("@label g for grams", "%1g").arg(weights[index]), catalog.i18nc("@label g for grams", "%1g").arg(weights[index]),
"%1 %2".arg(UM.Preferences.getValue("cura/currency")).arg(costs[index]), "%1&nbsp;%2".arg(UM.Preferences.getValue("cura/currency")).arg(costs[index]),
]; ]);
tooltip_html += "<tr>";
for(var item = 0; item < item_strings.length; item++) {
tooltip_html += "<td>%1&nbsp;&nbsp;</td>".arg(item_strings[item]);
}
} }
var item_strings = [ if(lengths.length > 1)
catalog.i18nc("@label", "Total:"), {
catalog.i18nc("@label m for meter", "%1m").arg(total_length.toFixed(2)), tooltip_html += formatRow([
catalog.i18nc("@label g for grams", "%1g").arg(Math.round(total_weight)), catalog.i18nc("@label", "Total:"),
"%1 %2".arg(UM.Preferences.getValue("cura/currency")).arg(total_cost.toFixed(2)), catalog.i18nc("@label m for meter", "%1m").arg(total_length.toFixed(2)),
]; catalog.i18nc("@label g for grams", "%1g").arg(Math.round(total_weight)),
tooltip_html += "<tr>"; "%1 %2".arg(UM.Preferences.getValue("cura/currency")).arg(total_cost.toFixed(2)),
for(var item = 0; item < item_strings.length; item++) { ]);
tooltip_html += "<td>%1&nbsp;&nbsp;</td>".arg(item_strings[item]);
} }
tooltip_html += "</tr></table>"; tooltip_html += "</table>";
tooltipText = tooltip_html; tooltipText = tooltip_html;
return tooltipText return tooltipText
} }