From 9ae8d2f88cdd7a9d768831ace96117ab96cbef26 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Mon, 1 Apr 2019 11:52:33 +0200 Subject: [PATCH] Use NotificationIcon and simplify code CURA-6151 --- .../Toolbox/resources/qml/ToolboxHeader.qml | 32 +++++-------------- resources/qml/MainWindow/MainWindowHeader.qml | 25 +++------------ 2 files changed, 12 insertions(+), 45 deletions(-) diff --git a/plugins/Toolbox/resources/qml/ToolboxHeader.qml b/plugins/Toolbox/resources/qml/ToolboxHeader.qml index c3f9318316..491567eb5f 100644 --- a/plugins/Toolbox/resources/qml/ToolboxHeader.qml +++ b/plugins/Toolbox/resources/qml/ToolboxHeader.qml @@ -1,9 +1,11 @@ // Copyright (c) 2018 Ultimaker B.V. // Toolbox is released under the terms of the LGPLv3 or higher. -import QtQuick 2.2 +import QtQuick 2.10 import QtQuick.Controls 1.4 -import UM 1.1 as UM + +import UM 1.4 as UM +import Cura 1.0 as Cura Item { @@ -66,37 +68,19 @@ Item width: UM.Theme.getSize("toolbox_header_tab").width + marketplaceNotificationIcon.width - UM.Theme.getSize("default_margin").width } - Rectangle + Cura.NotificationIcon { id: marketplaceNotificationIcon - color: UM.Theme.getColor("notification_icon") - width: (installedTabButton.height / 3) | 0 - height: width - radius: (0.5 * width) | 0 visible: CuraApplication.getPackageManager().packagesWithUpdate.length > 0 anchors.right: installedTabButton.right anchors.verticalCenter: installedTabButton.verticalCenter - Label + labelText: { - id: marketplaceNotificationText - anchors.centerIn: parent - anchors.fill: parent - text: - { - if(CuraApplication.getPackageManager().packagesWithUpdate.length > 9) - { - return "9+" // More than 2 characters don't fit. - } - - return CuraApplication.getPackageManager().packagesWithUpdate.length - } - color: UM.Theme.getColor("primary_text") - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - font: UM.Theme.getFont("small") + const itemCount = CuraApplication.getPackageManager().packagesWithUpdate.length + return itemCount > 9 ? "9+" : itemCount } } diff --git a/resources/qml/MainWindow/MainWindowHeader.qml b/resources/qml/MainWindow/MainWindowHeader.qml index ebe2b6ff6c..43ec03d947 100644 --- a/resources/qml/MainWindow/MainWindowHeader.qml +++ b/resources/qml/MainWindow/MainWindowHeader.qml @@ -118,13 +118,9 @@ Item verticalCenter: parent.verticalCenter } - Rectangle + Cura.NotificationIcon { id: marketplaceNotificationIcon - color: UM.Theme.getColor("notification_icon") - width: (marketplaceButton.height / 1.5) | 0 - height: width - radius: (0.5 * width) | 0 anchors { top: parent.top @@ -134,23 +130,10 @@ Item } visible: CuraApplication.getPackageManager().packagesWithUpdate.length > 0 - Label + labelText: { - id: marketplaceNotificationText - anchors.centerIn: parent - anchors.fill: parent - text: - { - if(CuraApplication.getPackageManager().packagesWithUpdate.length > 9) - { - return "9+" // More than 2 characters don't fit. - } - return CuraApplication.getPackageManager().packagesWithUpdate.length - } - color: UM.Theme.getColor("primary_text") - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - font: UM.Theme.getFont("small") + const itemCount = CuraApplication.getPackageManager().packagesWithUpdate.length + return itemCount > 9 ? "9+" : itemCount } } }