Fix tooltips for settings

CURA-5772
This commit is contained in:
Jaime van Kessel 2018-10-15 11:07:03 +02:00
parent 8cac5e1de2
commit d2baef97c4
3 changed files with 24 additions and 242 deletions

View file

@ -10,6 +10,10 @@ Row
{ {
spacing: UM.Theme.getSize("default_margin").width spacing: UM.Theme.getSize("default_margin").width
// This widget doesn't show tooltips by itself. Instead it emits signals so others can do something with it.
signal showTooltip(Item item, point location, string text)
signal hideTooltip()
UM.I18nCatalog UM.I18nCatalog
{ {
id: catalog id: catalog
@ -18,12 +22,12 @@ Row
Button Button
{ {
id: openFileButton; id: openFileButton
text: catalog.i18nc("@action:button", "Open File"); text: catalog.i18nc("@action:button", "Open File")
iconSource: UM.Theme.getIcon("load") iconSource: UM.Theme.getIcon("load")
style: UM.Theme.styles.tool_button style: UM.Theme.styles.tool_button
tooltip: "" tooltip: ""
action: Cura.Actions.open; action: Cura.Actions.open
} }
Cura.MachineAndConfigurationSelector Cura.MachineAndConfigurationSelector
@ -38,5 +42,7 @@ Row
Cura.ProfileAndSettingComponent Cura.ProfileAndSettingComponent
{ {
width: UM.Theme.getSize("sidebar").width width: UM.Theme.getSize("sidebar").width
onShowTooltip: parent.showTooltip(item, location, text)
onHideTooltip: parent.hideTooltip()
} }
} }

View file

@ -163,10 +163,16 @@ UM.MainWindow
} }
height: 50 height: 50
source: UM.Controller.activeStage.stageMenuComponent source: UM.Controller.activeStage.stageMenuComponent
} }
Connections
{
target: stageMenu.item
onShowTooltip: base.showTooltip(item, location, text)
onHideTooltop: base.hideTooltip()
}
JobSpecs JobSpecs
{ {
id: jobSpecs id: jobSpecs

View file

@ -28,6 +28,10 @@ Rectangle
color: UM.Theme.getColor("sidebar") color: UM.Theme.getColor("sidebar")
UM.I18nCatalog { id: catalog; name:"cura"} UM.I18nCatalog { id: catalog; name:"cura"}
// This widget doesn't show tooltips by itself. Instead it emits signals so others can do something with it.
signal showTooltip(Item item, point location, string text)
signal hideTooltip()
Timer Timer
{ {
id: tooltipDelayTimer id: tooltipDelayTimer
@ -42,18 +46,6 @@ Rectangle
} }
} }
function showTooltip(item, position, text)
{
tooltip.text = text;
position = item.mapToItem(base, position.x - UM.Theme.getSize("default_arrow").width, position.y);
tooltip.show(position);
}
function hideTooltip()
{
tooltip.hide();
}
function strPadLeft(string, pad, length) function strPadLeft(string, pad, length)
{ {
return (new Array(length + 1).join(pad) + string).slice(-length); return (new Array(length + 1).join(pad) + string).slice(-length);
@ -205,241 +197,19 @@ Rectangle
{ {
anchors.fill: parent anchors.fill: parent
visible: currentModeIndex == 1 visible: currentModeIndex == 1
onShowTooltip: base.showTooltip(item, location, text)
onHideTooltip: base.hideTooltip()
} }
SidebarSimple SidebarSimple
{ {
anchors.fill: parent anchors.fill: parent
visible: currentModeIndex != 1 visible: currentModeIndex != 1
onShowTooltip: base.showTooltip(item, location, text)
onHideTooltip: base.hideTooltip()
} }
} }
/*Item
{
id: printSpecs
anchors.left: parent.left
anchors.bottom: parent.bottom
anchors.leftMargin: UM.Theme.getSize("sidebar_margin").width
anchors.bottomMargin: UM.Theme.getSize("sidebar_margin").height
height: timeDetails.height + costSpec.height
width: base.width - (saveButton.buttonRowWidth + UM.Theme.getSize("sidebar_margin").width)
Label
{
id: timeDetails
anchors.left: parent.left
anchors.bottom: costSpec.top
font: UM.Theme.getFont("large")
color: UM.Theme.getColor("text_subtext")
text: (!base.printDuration || !base.printDuration.valid) ? catalog.i18nc("@label Hours and minutes", "00h 00min") : base.printDuration.getDisplayString(UM.DurationFormat.Short)
renderType: Text.NativeRendering
MouseArea
{
id: timeDetailsMouseArea
anchors.fill: parent
hoverEnabled: true
onEntered:
{
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 tooltip_html = "<b>%1</b><br/><table width=\"100%\">".arg(catalog.i18nc("@tooltip", "Time specification"));
for(var feature in print_time)
{
if(!print_time[feature].isTotalDurationZero)
{
tooltip_html += "<tr><td>" + feature + ":</td>" +
"<td align=\"right\" valign=\"bottom\">&nbsp;&nbsp;%1</td>".arg(print_time[feature].getDisplayString(UM.DurationFormat.ISO8601).slice(0,-3)) +
"<td align=\"right\" valign=\"bottom\">&nbsp;&nbsp;%1%</td>".arg(Math.round(100 * parseInt(print_time[feature].getDisplayString(UM.DurationFormat.Seconds)) / total_seconds)) +
"</td></tr>";
}
}
tooltip_html += "</table>";
base.showTooltip(parent, Qt.point(-UM.Theme.getSize("sidebar_margin").width, 0), tooltip_html);
}
}
onExited:
{
base.hideTooltip();
}
}
}
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()
{
var lengths = [];
var total_length = 0;
var weights = [];
var total_weight = 0;
var costs = [];
var total_cost = 0;
var some_costs_known = false;
var names = [];
if(base.printMaterialLengths)
{
for(var index = 0; index < base.printMaterialLengths.length; index++)
{
if(base.printMaterialLengths[index] > 0)
{
names.push(base.printMaterialNames[index]);
lengths.push(base.printMaterialLengths[index].toFixed(2));
weights.push(String(Math.round(base.printMaterialWeights[index])));
var cost = base.printMaterialCosts[index] == undefined ? 0 : base.printMaterialCosts[index].toFixed(2);
costs.push(cost);
if(cost > 0)
{
some_costs_known = true;
}
total_length += base.printMaterialLengths[index];
total_weight += base.printMaterialWeights[index];
total_cost += base.printMaterialCosts[index];
}
}
}
if(lengths.length == 0)
{
lengths = ["0.00"];
weights = ["0"];
costs = ["0.00"];
}
var tooltip_html = "<b>%1</b><br/><table width=\"100%\">".arg(catalog.i18nc("@label", "Cost specification"));
for(var index = 0; index < lengths.length; index++)
{
tooltip_html += formatRow([
"%1:".arg(names[index]),
catalog.i18nc("@label m for meter", "%1m").arg(lengths[index]),
catalog.i18nc("@label g for grams", "%1g").arg(weights[index]),
"%1&nbsp;%2".arg(UM.Preferences.getValue("cura/currency")).arg(costs[index]),
]);
}
if(lengths.length > 1)
{
tooltip_html += formatRow([
catalog.i18nc("@label", "Total:"),
catalog.i18nc("@label m for meter", "%1m").arg(total_length.toFixed(2)),
catalog.i18nc("@label g for grams", "%1g").arg(Math.round(total_weight)),
"%1 %2".arg(UM.Preferences.getValue("cura/currency")).arg(total_cost.toFixed(2)),
]);
}
tooltip_html += "</table>";
tooltipText = tooltip_html;
return tooltipText
}
id: costSpec
anchors.left: parent.left
anchors.bottom: parent.bottom
font: UM.Theme.getFont("very_small")
renderType: Text.NativeRendering
color: UM.Theme.getColor("text_subtext")
elide: Text.ElideMiddle
width: parent.width
property string tooltipText
text:
{
var lengths = [];
var weights = [];
var costs = [];
var someCostsKnown = false;
if(base.printMaterialLengths) {
for(var index = 0; index < base.printMaterialLengths.length; index++)
{
if(base.printMaterialLengths[index] > 0)
{
lengths.push(base.printMaterialLengths[index].toFixed(2));
weights.push(String(Math.round(base.printMaterialWeights[index])));
var cost = base.printMaterialCosts[index] == undefined ? 0 : base.printMaterialCosts[index].toFixed(2);
costs.push(cost);
if(cost > 0)
{
someCostsKnown = true;
}
}
}
}
if(lengths.length == 0)
{
lengths = ["0.00"];
weights = ["0"];
costs = ["0.00"];
}
var result = lengths.join(" + ") + "m / ~ " + weights.join(" + ") + "g";
if(someCostsKnown)
{
result += " / ~ " + costs.join(" + ") + " " + UM.Preferences.getValue("cura/currency");
}
return result;
}
MouseArea
{
id: costSpecMouseArea
anchors.fill: parent
hoverEnabled: true
onEntered:
{
if(base.printDuration.valid && !base.printDuration.isTotalDurationZero)
{
var show_data = costSpec.getSpecsData()
base.showTooltip(parent, Qt.point(-UM.Theme.getSize("sidebar_margin").width, 0), show_data);
}
}
onExited:
{
base.hideTooltip();
}
}
}
}*/
// SaveButton is actually the bottom footer panel.
/*SaveButton
{
id: saveButton
implicitWidth: base.width
anchors.top: footerSeparator.bottom
anchors.topMargin: UM.Theme.getSize("sidebar_margin").height
anchors.bottom: parent.bottom
}*/
/*
SidebarTooltip
{
id: tooltip
}*/
// Setting mode: Recommended or Custom // Setting mode: Recommended or Custom
ListModel ListModel
{ {