mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-15 10:47:49 -06:00
Add tooltips for intent profiles to the Recommended Quality panel.
The description is optional. Tooltip will not show if no description is set CURA-6853
This commit is contained in:
parent
ad2077b76b
commit
3709cfa4ed
3 changed files with 51 additions and 12 deletions
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
from PyQt5.QtCore import Qt
|
from PyQt5.QtCore import Qt
|
||||||
import collections
|
import collections
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING, Optional
|
||||||
|
|
||||||
from cura.Machines.Models.IntentModel import IntentModel
|
from cura.Machines.Models.IntentModel import IntentModel
|
||||||
from cura.Settings.IntentManager import IntentManager
|
from cura.Settings.IntentManager import IntentManager
|
||||||
|
@ -25,16 +25,26 @@ class IntentCategoryModel(ListModel):
|
||||||
IntentCategoryRole = Qt.UserRole + 2
|
IntentCategoryRole = Qt.UserRole + 2
|
||||||
WeightRole = Qt.UserRole + 3
|
WeightRole = Qt.UserRole + 3
|
||||||
QualitiesRole = Qt.UserRole + 4
|
QualitiesRole = Qt.UserRole + 4
|
||||||
|
DescriptionRole = Qt.UserRole + 5
|
||||||
#Translations to user-visible string. Ordered by weight.
|
|
||||||
#TODO: Create a solution for this name and weight to be used dynamically.
|
|
||||||
name_translation = collections.OrderedDict() #type: "collections.OrderedDict[str,str]"
|
|
||||||
name_translation["default"] = catalog.i18nc("@label", "Default")
|
|
||||||
name_translation["engineering"] = catalog.i18nc("@label", "Engineering")
|
|
||||||
name_translation["smooth"] = catalog.i18nc("@label", "Smooth")
|
|
||||||
|
|
||||||
modelUpdated = pyqtSignal()
|
modelUpdated = pyqtSignal()
|
||||||
|
|
||||||
|
# Translations to user-visible string. Ordered by weight.
|
||||||
|
# TODO: Create a solution for this name and weight to be used dynamically.
|
||||||
|
_translations = collections.OrderedDict() # type: "collections.OrderedDict[str,Dict[str,Optional[str]]"
|
||||||
|
_translations["default"] = {
|
||||||
|
"name": catalog.i18nc("@label", "Default")
|
||||||
|
}
|
||||||
|
_translations["engineering"] = {
|
||||||
|
"name": catalog.i18nc("@label", "Engineering"),
|
||||||
|
"description": catalog.i18nc("@text", "An profile which is suitable for engineering work")
|
||||||
|
|
||||||
|
}
|
||||||
|
_translations["smooth"] = {
|
||||||
|
"name": catalog.i18nc("@label", "Smooth"),
|
||||||
|
"description": catalog.i18nc("@text", "Ohhh yeah. So tender. So smooth. So Perfect.")
|
||||||
|
}
|
||||||
|
|
||||||
## Creates a new model for a certain intent category.
|
## Creates a new model for a certain intent category.
|
||||||
# \param The category to list the intent profiles for.
|
# \param The category to list the intent profiles for.
|
||||||
def __init__(self, intent_category: str) -> None:
|
def __init__(self, intent_category: str) -> None:
|
||||||
|
@ -45,6 +55,7 @@ class IntentCategoryModel(ListModel):
|
||||||
self.addRoleName(self.IntentCategoryRole, "intent_category")
|
self.addRoleName(self.IntentCategoryRole, "intent_category")
|
||||||
self.addRoleName(self.WeightRole, "weight")
|
self.addRoleName(self.WeightRole, "weight")
|
||||||
self.addRoleName(self.QualitiesRole, "qualities")
|
self.addRoleName(self.QualitiesRole, "qualities")
|
||||||
|
self.addRoleName(self.DescriptionRole, "description")
|
||||||
|
|
||||||
application = cura.CuraApplication.CuraApplication.getInstance()
|
application = cura.CuraApplication.CuraApplication.getInstance()
|
||||||
|
|
||||||
|
@ -75,10 +86,18 @@ class IntentCategoryModel(ListModel):
|
||||||
qualities = IntentModel()
|
qualities = IntentModel()
|
||||||
qualities.setIntentCategory(category)
|
qualities.setIntentCategory(category)
|
||||||
result.append({
|
result.append({
|
||||||
"name": self.name_translation.get(category, catalog.i18nc("@label", "Unknown")),
|
"name": IntentCategoryModel.translation(category, "name", catalog.i18nc("@label", "Unknown")),
|
||||||
|
"description": IntentCategoryModel.translation(category, "description", None),
|
||||||
"intent_category": category,
|
"intent_category": category,
|
||||||
"weight": list(self.name_translation.keys()).index(category),
|
"weight": list(self._translations.keys()).index(category),
|
||||||
"qualities": qualities
|
"qualities": qualities
|
||||||
})
|
})
|
||||||
result.sort(key = lambda k: k["weight"])
|
result.sort(key = lambda k: k["weight"])
|
||||||
self.setItems(result)
|
self.setItems(result)
|
||||||
|
|
||||||
|
## Get a display value for a category. See IntenCategoryModel._translations
|
||||||
|
## for categories and keys
|
||||||
|
@staticmethod
|
||||||
|
def translation(category: str, key: str, default: Optional[str] = None):
|
||||||
|
display_strings = IntentCategoryModel._translations.get(category, {})
|
||||||
|
return display_strings.get(key, default)
|
||||||
|
|
|
@ -1586,7 +1586,8 @@ class MachineManager(QObject):
|
||||||
|
|
||||||
intent_category = self.activeIntentCategory
|
intent_category = self.activeIntentCategory
|
||||||
if intent_category != "default":
|
if intent_category != "default":
|
||||||
intent_display_name = IntentCategoryModel.name_translation.get(intent_category,
|
intent_display_name = IntentCategoryModel.translation(intent_category,
|
||||||
|
"name",
|
||||||
catalog.i18nc("@label", "Unknown"))
|
catalog.i18nc("@label", "Unknown"))
|
||||||
display_name = "{intent_name} - {the_rest}".format(intent_name = intent_display_name,
|
display_name = "{intent_name} - {the_rest}".format(intent_name = intent_display_name,
|
||||||
the_rest = display_name)
|
the_rest = display_name)
|
||||||
|
|
|
@ -163,6 +163,25 @@ Item
|
||||||
|
|
||||||
isCheckedFunction: checkedFunction
|
isCheckedFunction: checkedFunction
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MouseArea // tooltip hover area
|
||||||
|
{
|
||||||
|
anchors.fill: parent
|
||||||
|
hoverEnabled: true
|
||||||
|
enabled: model.description !== undefined
|
||||||
|
acceptedButtons: Qt.NoButton // react to hover only, don't steal clicks
|
||||||
|
|
||||||
|
onEntered:
|
||||||
|
{
|
||||||
|
print(model.description)
|
||||||
|
base.showTooltip(
|
||||||
|
intentCategoryLabel,
|
||||||
|
Qt.point(-(intentCategoryLabel.x - qualityRow.x) - UM.Theme.getSize("thick_margin").width, 0),
|
||||||
|
model.description
|
||||||
|
)
|
||||||
|
}
|
||||||
|
onExited: base.hideTooltip()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue