From 3709cfa4edcd038fe36f3ad58c05f5072727d840 Mon Sep 17 00:00:00 2001 From: Nino van Hooff Date: Thu, 17 Oct 2019 15:54:03 +0200 Subject: [PATCH 1/4] 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 --- cura/Machines/Models/IntentCategoryModel.py | 39 ++++++++++++++----- cura/Settings/MachineManager.py | 5 ++- .../RecommendedQualityProfileSelector.qml | 19 +++++++++ 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/cura/Machines/Models/IntentCategoryModel.py b/cura/Machines/Models/IntentCategoryModel.py index d7d1ee2710..0268d067a9 100644 --- a/cura/Machines/Models/IntentCategoryModel.py +++ b/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 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", "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. # \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) diff --git a/cura/Settings/MachineManager.py b/cura/Settings/MachineManager.py index 35f3268cce..d1f8cad4b3 100755 --- a/cura/Settings/MachineManager.py +++ b/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) diff --git a/resources/qml/PrintSetupSelector/Recommended/RecommendedQualityProfileSelector.qml b/resources/qml/PrintSetupSelector/Recommended/RecommendedQualityProfileSelector.qml index d1f7dd7de2..a75783d096 100644 --- a/resources/qml/PrintSetupSelector/Recommended/RecommendedQualityProfileSelector.qml +++ b/resources/qml/PrintSetupSelector/Recommended/RecommendedQualityProfileSelector.qml @@ -163,6 +163,25 @@ 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: + { + print(model.description) + base.showTooltip( + intentCategoryLabel, + Qt.point(-(intentCategoryLabel.x - qualityRow.x) - UM.Theme.getSize("thick_margin").width, 0), + model.description + ) + } + onExited: base.hideTooltip() + } } } From b182830c2157ba3b539c6d92d561e3f9a04ea428 Mon Sep 17 00:00:00 2001 From: Nino van Hooff Date: Thu, 17 Oct 2019 17:17:06 +0200 Subject: [PATCH 2/4] Add tooltips for intent profiles to the Custom Quality panel. The description is optional. Tooltip will not show if no description is set CURA-6853 --- cura/Machines/Models/IntentCategoryModel.py | 2 +- .../Custom/QualitiesWithIntentMenu.qml | 21 ++++++++++++++++++- .../RecommendedQualityProfileSelector.qml | 1 - 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/cura/Machines/Models/IntentCategoryModel.py b/cura/Machines/Models/IntentCategoryModel.py index 0268d067a9..de909df534 100644 --- a/cura/Machines/Models/IntentCategoryModel.py +++ b/cura/Machines/Models/IntentCategoryModel.py @@ -37,7 +37,7 @@ class IntentCategoryModel(ListModel): } _translations["engineering"] = { "name": catalog.i18nc("@label", "Engineering"), - "description": catalog.i18nc("@text", "An profile which is suitable for engineering work") + "description": catalog.i18nc("@text", "A profile which is suitable for engineering work") } _translations["smooth"] = { diff --git a/resources/qml/PrintSetupSelector/Custom/QualitiesWithIntentMenu.qml b/resources/qml/PrintSetupSelector/Custom/QualitiesWithIntentMenu.qml index c9686a1519..c5a725285c 100644 --- a/resources/qml/PrintSetupSelector/Custom/QualitiesWithIntentMenu.qml +++ b/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 diff --git a/resources/qml/PrintSetupSelector/Recommended/RecommendedQualityProfileSelector.qml b/resources/qml/PrintSetupSelector/Recommended/RecommendedQualityProfileSelector.qml index a75783d096..05e7202f6d 100644 --- a/resources/qml/PrintSetupSelector/Recommended/RecommendedQualityProfileSelector.qml +++ b/resources/qml/PrintSetupSelector/Recommended/RecommendedQualityProfileSelector.qml @@ -173,7 +173,6 @@ Item onEntered: { - print(model.description) base.showTooltip( intentCategoryLabel, Qt.point(-(intentCategoryLabel.x - qualityRow.x) - UM.Theme.getSize("thick_margin").width, 0), From 915c8e560ca945e419af7bcd5e7a0b2908ffda8c Mon Sep 17 00:00:00 2001 From: Nino van Hooff Date: Fri, 18 Oct 2019 09:04:00 +0200 Subject: [PATCH 3/4] Fix mypy warning --- cura/Machines/Models/IntentCategoryModel.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cura/Machines/Models/IntentCategoryModel.py b/cura/Machines/Models/IntentCategoryModel.py index de909df534..8e7cd0fb5f 100644 --- a/cura/Machines/Models/IntentCategoryModel.py +++ b/cura/Machines/Models/IntentCategoryModel.py @@ -3,7 +3,7 @@ from PyQt5.QtCore import Qt import collections -from typing import TYPE_CHECKING, Optional +from typing import TYPE_CHECKING, Optional, Dict from cura.Machines.Models.IntentModel import IntentModel from cura.Settings.IntentManager import IntentManager @@ -31,7 +31,7 @@ class IntentCategoryModel(ListModel): # 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 = collections.OrderedDict() # type: "collections.OrderedDict[str,Dict[str,Optional[str]]]" _translations["default"] = { "name": catalog.i18nc("@label", "Default") } From b2f9dc612d3fe4a08caafaf9d5942421d9f06d09 Mon Sep 17 00:00:00 2001 From: Nino van Hooff Date: Mon, 21 Oct 2019 10:33:52 +0200 Subject: [PATCH 4/4] Change intent profile descriptions to not trigger pervs and prudes. CURA-6851 --- cura/Machines/Models/IntentCategoryModel.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cura/Machines/Models/IntentCategoryModel.py b/cura/Machines/Models/IntentCategoryModel.py index 8e7cd0fb5f..70165a33f1 100644 --- a/cura/Machines/Models/IntentCategoryModel.py +++ b/cura/Machines/Models/IntentCategoryModel.py @@ -37,12 +37,12 @@ class IntentCategoryModel(ListModel): } _translations["engineering"] = { "name": catalog.i18nc("@label", "Engineering"), - "description": catalog.i18nc("@text", "A profile which is suitable for engineering work") + "description": catalog.i18nc("@text", "Suitable for engineering work") } _translations["smooth"] = { "name": catalog.i18nc("@label", "Smooth"), - "description": catalog.i18nc("@text", "Ohhh yeah. So tender. So smooth. So Perfect.") + "description": catalog.i18nc("@text", "Optimized for a smooth surfaces") } ## Creates a new model for a certain intent category.