From e0ff70dc7850a0809dc79f46e9b2ab93333fec5d Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Wed, 10 Nov 2021 13:47:41 +0100 Subject: [PATCH] Convert stage buttons to controls 2 --- resources/qml/MainWindow/MainWindowHeader.qml | 72 ++++++++++++++---- resources/themes/cura-light/styles.qml | 73 ------------------- 2 files changed, 59 insertions(+), 86 deletions(-) diff --git a/resources/qml/MainWindow/MainWindowHeader.qml b/resources/qml/MainWindow/MainWindowHeader.qml index 815ddff732..5ed3929125 100644 --- a/resources/qml/MainWindow/MainWindowHeader.qml +++ b/resources/qml/MainWindow/MainWindowHeader.qml @@ -1,10 +1,8 @@ -// Copyright (c) 2018 Ultimaker B.V. +// Copyright (c) 2021 Ultimaker B.V. // Cura is released under the terms of the LGPLv3 or higher. import QtQuick 2.7 -import QtQuick.Controls 2.0 as Controls2 -import QtQuick.Controls 1.4 -import QtQuick.Controls.Styles 1.1 +import QtQuick.Controls 2.4 import UM 1.4 as UM import Cura 1.0 as Cura @@ -33,6 +31,10 @@ Item sourceSize.width: width sourceSize.height: height } + ButtonGroup + { + buttons: stagesListContainer.children + } Row { @@ -61,15 +63,61 @@ Item checked: UM.Controller.activeStage !== null && model.id == UM.Controller.activeStage.stageId anchors.verticalCenter: parent.verticalCenter - exclusiveGroup: mainWindowHeaderMenuGroup - style: UM.Theme.styles.main_window_header_tab + //style: UM.Theme.styles.main_window_header_tab height: Math.round(0.5 * UM.Theme.getSize("main_window_header").height) - iconSource: model.stage.iconSource - - property color overlayColor: "transparent" - property string overlayIconSource: "" // This id is required to find the stage buttons through Squish property string stageId: model.id + hoverEnabled: true + leftPadding: 2 * UM.Theme.getSize("default_margin").width + rightPadding: 2 * UM.Theme.getSize("default_margin").width + + // Set top & bottom padding to whatever space is left from height and the size of the text. + bottomPadding: Math.round((height - buttonLabel.contentHeight) / 2) + topPadding: bottomPadding + + background: Rectangle + { + radius: UM.Theme.getSize("action_button_radius").width + width: contents.width + color: + { + if (stageSelectorButton.checked) + { + return UM.Theme.getColor("main_window_header_button_background_active") + } + else + { + if (stageSelectorButton.hovered) + { + return UM.Theme.getColor("main_window_header_button_background_hovered") + } + return UM.Theme.getColor("main_window_header_button_background_inactive") + } + } + } + + contentItem: Label + { + id: buttonLabel + text: stageSelectorButton.text + anchors.centerIn: stageSelectorButton + font: UM.Theme.getFont("medium") + color: + { + if (stageSelectorButton.checked) + { + return UM.Theme.getColor("main_window_header_button_text_active") + } + else + { + if (stageSelectorButton.hovered) + { + return UM.Theme.getColor("main_window_header_button_text_hovered") + } + return UM.Theme.getColor("main_window_header_button_text_inactive") + } + } + } // This is a trick to assure the activeStage is correctly changed. It doesn't work properly if done in the onClicked (see CURA-6028) MouseArea @@ -79,12 +127,10 @@ Item } } } - - ExclusiveGroup { id: mainWindowHeaderMenuGroup } } // Shortcut button to quick access the Toolbox - Controls2.Button + Button { id: marketplaceButton text: catalog.i18nc("@action:button", "Marketplace") diff --git a/resources/themes/cura-light/styles.qml b/resources/themes/cura-light/styles.qml index 1320b54f37..0a7ac47461 100755 --- a/resources/themes/cura-light/styles.qml +++ b/resources/themes/cura-light/styles.qml @@ -96,79 +96,6 @@ QtObject } } - property Component main_window_header_tab: Component - { - ButtonStyle - { - // This property will be back-propagated when the width of the label is calculated - property var buttonWidth: 0 - - background: Rectangle - { - id: backgroundRectangle - implicitHeight: control.height - implicitWidth: buttonWidth - radius: UM.Theme.getSize("action_button_radius").width - - color: - { - if (control.checked) - { - return UM.Theme.getColor("main_window_header_button_background_active") - } - else - { - if (control.hovered) - { - return UM.Theme.getColor("main_window_header_button_background_hovered") - } - return UM.Theme.getColor("main_window_header_button_background_inactive") - } - } - - } - - label: Item - { - id: contents - anchors.horizontalCenter: parent.horizontalCenter - anchors.verticalCenter: parent.verticalCenter - height: control.height - width: buttonLabel.width + 4 * UM.Theme.getSize("default_margin").width - - Label - { - id: buttonLabel - text: control.text - anchors.verticalCenter: parent.verticalCenter - anchors.horizontalCenter: parent.horizontalCenter - font: UM.Theme.getFont("medium") - color: - { - if (control.checked) - { - return UM.Theme.getColor("main_window_header_button_text_active") - } - else - { - if (control.hovered) - { - return UM.Theme.getColor("main_window_header_button_text_hovered") - } - return UM.Theme.getColor("main_window_header_button_text_inactive") - } - } - } - Component.onCompleted: - { - buttonWidth = width - } - } - - - } - } - property Component tool_button: Component { ButtonStyle