Merge pull request #4072 from Ultimaker/CURA-5536_installed_check

CURA-5536 Use an icon indicating when a package is installed
This commit is contained in:
Lipu Fei 2018-07-16 08:05:00 +02:00 committed by GitHub
commit 92da6e0ce3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 68 additions and 8 deletions

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 22.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Layer_3" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve">
<path d="M0,512h512V0L0,512z M440.4,318.3L331.2,431.6c-1.4,1.4-2.7,2-4.8,2c-2,0-3.4-0.7-4.8-2l-53.3-57.3l-1.4-2
c-1.4-1.4-2-3.4-2-4.8c0-1.4,0.7-3.4,2-4.8l9.6-9.6c2.7-2.7,6.8-2.7,9.6,0l0.7,0.7l37.6,40.2c1.4,1.4,3.4,1.4,4.8,0l91.4-94.9h0.7
c2.7-2.7,6.8-2.7,9.6,0l9.5,9.6C443.1,311.5,443.1,315.6,440.4,318.3z"/>
</svg>

After

Width:  |  Height:  |  Size: 667 B

View File

@ -9,6 +9,8 @@ import UM 1.1 as UM
Item
{
property int packageCount: toolbox.viewCategory == "material" ? toolbox.getTotalNumberOfPackagesByAuthor(model.id) : 1
property int installedPackages: toolbox.viewCategory == "material" ? toolbox.getNumberOfInstalledPackagesByAuthor(model.id) : (toolbox.isInstalled(model.id) ? 1 : 0)
height: childrenRect.height
Layout.alignment: Qt.AlignTop | Qt.AlignLeft
Rectangle
@ -40,6 +42,21 @@ Item
source: model.icon_url || "../images/logobot.svg"
mipmap: true
}
UM.RecolorImage
{
width: (parent.width * 0.4) | 0
height: (parent.height * 0.4) | 0
anchors
{
bottom: parent.bottom
right: parent.right
}
sourceSize.width: width
sourceSize.height: height
visible: installedPackages != 0
color: (installedPackages == packageCount) ? UM.Theme.getColor("primary") : UM.Theme.getColor("border")
source: "../images/installed_check.svg"
}
}
Column
{

View File

@ -9,6 +9,8 @@ import UM 1.1 as UM
Rectangle
{
property int packageCount: toolbox.viewCategory == "material" ? toolbox.getTotalNumberOfPackagesByAuthor(model.id) : 1
property int installedPackages: toolbox.viewCategory == "material" ? toolbox.getNumberOfInstalledPackagesByAuthor(model.id) : (toolbox.isInstalled(model.id) ? 1 : 0)
id: tileBase
width: UM.Theme.getSize("toolbox_thumbnail_large").width + (2 * UM.Theme.getSize("default_lining").width)
height: thumbnail.height + packageNameBackground.height + (2 * UM.Theme.getSize("default_lining").width)
@ -36,6 +38,22 @@ Rectangle
source: model.icon_url || "../images/logobot.svg"
mipmap: true
}
UM.RecolorImage
{
width: (parent.width * 0.3) | 0
height: (parent.height * 0.3) | 0
anchors
{
bottom: parent.bottom
right: parent.right
bottomMargin: UM.Theme.getSize("default_lining").width
}
sourceSize.width: width
sourceSize.height: height
visible: installedPackages != 0
color: (installedPackages == packageCount) ? UM.Theme.getColor("primary") : UM.Theme.getColor("border")
source: "../images/installed_check.svg"
}
}
Rectangle
{

View File

@ -43,7 +43,7 @@ class AuthorsModel(ListModel):
"package_count": author["package_count"] if "package_count" in author else 0,
"package_types": author["package_types"] if "package_types" in author else [],
"icon_url": author["icon_url"] if "icon_url" in author else None,
"description": "Material and quality profiles from {author_name}".format( author_name = author["display_name"])
"description": "Material and quality profiles from {author_name}".format(author_name = author["display_name"])
})
# Filter on all the key-word arguments.

View File

@ -228,6 +228,7 @@ class Toolbox(QObject, Extension):
self._makeRequestByType("authors")
self._makeRequestByType("plugins_showcase")
self._makeRequestByType("materials_showcase")
self._makeRequestByType("materials_available")
# Gather installed packages:
self._updateInstalledModels()
@ -501,6 +502,22 @@ class Toolbox(QObject, Extension):
def isInstalled(self, package_id: str) -> bool:
return self._package_manager.isPackageInstalled(package_id)
@pyqtSlot(str, result = int)
def getNumberOfInstalledPackagesByAuthor(self, author_id: str) -> int:
count = 0
for package in self._metadata["materials_installed"]:
if package["author"]["author_id"] == author_id:
count += 1
return count
@pyqtSlot(str, result = int)
def getTotalNumberOfPackagesByAuthor(self, author_id: str) -> int:
count = 0
for package in self._metadata["materials_available"]:
if package["author"]["author_id"] == author_id:
count += 1
return count
@pyqtSlot(str, result = bool)
def isEnabled(self, package_id: str) -> bool:
if package_id in self._plugin_registry.getActivePlugins():
@ -722,27 +739,27 @@ class Toolbox(QObject, Extension):
# --------------------------------------------------------------------------
@pyqtProperty(QObject, notify = metadataChanged)
def authorsModel(self) -> AuthorsModel:
return self._models["authors"]
return cast(AuthorsModel, self._models["authors"])
@pyqtProperty(QObject, notify = metadataChanged)
def packagesModel(self) -> PackagesModel:
return self._models["packages"]
return cast(PackagesModel, self._models["packages"])
@pyqtProperty(QObject, notify = metadataChanged)
def pluginsShowcaseModel(self) -> PackagesModel:
return self._models["plugins_showcase"]
return cast(PackagesModel, self._models["plugins_showcase"])
@pyqtProperty(QObject, notify = metadataChanged)
def pluginsInstalledModel(self) -> PackagesModel:
return self._models["plugins_installed"]
return cast(PackagesModel, self._models["plugins_installed"])
@pyqtProperty(QObject, notify = metadataChanged)
def materialsShowcaseModel(self) -> PackagesModel:
return self._models["materials_showcase"]
def materialsShowcaseModel(self) -> AuthorsModel:
return cast(AuthorsModel, self._models["materials_showcase"])
@pyqtProperty(QObject, notify = metadataChanged)
def materialsInstalledModel(self) -> PackagesModel:
return self._models["materials_installed"]
return cast(PackagesModel, self._models["materials_installed"])