Browse Source

Merge branch 'CURA-6851' of github.com:Ultimaker/Cura

Jaime van Kessel 5 years ago
parent
commit
d3fb066cac

+ 29 - 10
cura/Machines/Models/IntentCategoryModel.py

@@ -3,7 +3,7 @@
 
 from PyQt5.QtCore import Qt
 import collections
-from typing import TYPE_CHECKING
+from typing import TYPE_CHECKING, Optional, Dict
 
 from cura.Machines.Models.IntentModel import IntentModel
 from cura.Settings.IntentManager import IntentManager
@@ -25,16 +25,26 @@ class IntentCategoryModel(ListModel):
     IntentCategoryRole = Qt.UserRole + 2
     WeightRole = Qt.UserRole + 3
     QualitiesRole = Qt.UserRole + 4
-
-    #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")
+    DescriptionRole = Qt.UserRole + 5
 
     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", "Suitable for engineering work")
+
+    }
+    _translations["smooth"] = {
+        "name": catalog.i18nc("@label", "Smooth"),
+        "description": catalog.i18nc("@text", "Optimized for a smooth surfaces")
+    }
+
     ##  Creates a new model for a certain intent category.
     #   \param The category to list the intent profiles for.
     def __init__(self, intent_category: str) -> None:
@@ -45,6 +55,7 @@ class IntentCategoryModel(ListModel):
         self.addRoleName(self.IntentCategoryRole, "intent_category")
         self.addRoleName(self.WeightRole, "weight")
         self.addRoleName(self.QualitiesRole, "qualities")
+        self.addRoleName(self.DescriptionRole, "description")
 
         application = cura.CuraApplication.CuraApplication.getInstance()
 
@@ -75,10 +86,18 @@ class IntentCategoryModel(ListModel):
             qualities = IntentModel()
             qualities.setIntentCategory(category)
             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,
-                "weight": list(self.name_translation.keys()).index(category),
+                "weight": list(self._translations.keys()).index(category),
                 "qualities": qualities
             })
         result.sort(key = lambda k: k["weight"])
         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)

+ 3 - 2
cura/Settings/MachineManager.py

@@ -1586,8 +1586,9 @@ class MachineManager(QObject):
 
         intent_category = self.activeIntentCategory
         if intent_category != "default":
-            intent_display_name = IntentCategoryModel.name_translation.get(intent_category,
-                                                                           catalog.i18nc("@label", "Unknown"))
+            intent_display_name = IntentCategoryModel.translation(intent_category,
+                                                                  "name",
+                                                                  catalog.i18nc("@label", "Unknown"))
             display_name = "{intent_name} - {the_rest}".format(intent_name = intent_display_name,
                                                                the_rest = display_name)
 

+ 20 - 1
resources/qml/PrintSetupSelector/Custom/QualitiesWithIntentMenu.qml

@@ -70,12 +70,31 @@ Popup
                         {
                             id: headerLabel
                             text: model.name
+                            color: UM.Theme.getColor("text_inactive")
                             renderType: Text.NativeRendering
+                            width: parent.width
                             height: visible ? contentHeight: 0
-                            enabled: false
                             visible: qualitiesList.visibleChildren.length > 0
                             anchors.left: parent.left
                             anchors.leftMargin: UM.Theme.getSize("default_margin").width
+
+                            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:
+                                {
+                                    base.showTooltip(
+                                        headerLabel,
+                                        Qt.point(- UM.Theme.getSize("default_margin").width, 0),
+                                        model.description
+                                    )
+                                }
+                                onExited: base.hideTooltip()
+                            }
                         }
 
                         Column

+ 18 - 0
resources/qml/PrintSetupSelector/Recommended/RecommendedQualityProfileSelector.qml

@@ -163,6 +163,24 @@ Item
 
                     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:
+                    {
+                        base.showTooltip(
+                            intentCategoryLabel,
+                            Qt.point(-(intentCategoryLabel.x - qualityRow.x) - UM.Theme.getSize("thick_margin").width, 0),
+                            model.description
+                        )
+                    }
+                    onExited: base.hideTooltip()
+                }
             }
 
         }