Convert stage buttons to controls 2

This commit is contained in:
Jaime van Kessel 2021-11-10 13:47:41 +01:00
parent 8998738237
commit e0ff70dc78
2 changed files with 59 additions and 86 deletions

View File

@ -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. // Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.7 import QtQuick 2.7
import QtQuick.Controls 2.0 as Controls2 import QtQuick.Controls 2.4
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.1
import UM 1.4 as UM import UM 1.4 as UM
import Cura 1.0 as Cura import Cura 1.0 as Cura
@ -33,6 +31,10 @@ Item
sourceSize.width: width sourceSize.width: width
sourceSize.height: height sourceSize.height: height
} }
ButtonGroup
{
buttons: stagesListContainer.children
}
Row Row
{ {
@ -61,15 +63,61 @@ Item
checked: UM.Controller.activeStage !== null && model.id == UM.Controller.activeStage.stageId checked: UM.Controller.activeStage !== null && model.id == UM.Controller.activeStage.stageId
anchors.verticalCenter: parent.verticalCenter 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) 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 // This id is required to find the stage buttons through Squish
property string stageId: model.id 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) // 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 MouseArea
@ -79,12 +127,10 @@ Item
} }
} }
} }
ExclusiveGroup { id: mainWindowHeaderMenuGroup }
} }
// Shortcut button to quick access the Toolbox // Shortcut button to quick access the Toolbox
Controls2.Button Button
{ {
id: marketplaceButton id: marketplaceButton
text: catalog.i18nc("@action:button", "Marketplace") text: catalog.i18nc("@action:button", "Marketplace")

View File

@ -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 property Component tool_button: Component
{ {
ButtonStyle ButtonStyle