123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- import QtQuick 2.7
- import QtQuick.Controls 2.3
- import UM 1.2 as UM
- import Cura 1.0 as Cura
- import QtGraphicalEffects 1.0
- Item
- {
- id: base
-
- enum ContentAlignment
- {
- AlignLeft,
- AlignRight
- }
-
- property alias headerItem: headerItemLoader.sourceComponent
-
- property alias contentItem: content.contentItem
- property color contentBackgroundColor: UM.Theme.getColor("action_button")
- property color headerBackgroundColor: UM.Theme.getColor("action_button")
- property color headerActiveColor: UM.Theme.getColor("secondary")
- property color headerHoverColor: UM.Theme.getColor("action_button_hovered")
- property alias mouseArea: headerMouseArea
- property alias enabled: headerMouseArea.enabled
-
- property alias disabledText: disabledLabel.text
-
- property int contentAlignment: ExpandablePopup.ContentAlignment.AlignRight
-
- property alias contentPadding: content.padding
-
- property alias headerPadding: background.padding
-
- property alias iconSource: collapseButton.source
- property alias iconColor: collapseButton.color
-
- property alias iconSize: collapseButton.height
-
- readonly property alias expanded: content.visible
- property alias expandedHighlightColor: expandedHighlight.color
-
- property alias headerRadius: background.radius
-
- property alias headerCornerSide: background.cornerSide
-
- property alias contentClosePolicy : content.closePolicy
- property alias headerShadowColor: shadow.color
- property alias enableHeaderShadow: shadow.visible
- property int shadowOffset: 2
- onEnabledChanged:
- {
- if (!base.enabled && expanded)
- {
- toggleContent()
- }
- }
- function toggleContent()
- {
- if (content.visible)
- {
- content.close()
- }
- else
- {
- content.open()
- }
- }
-
- Binding
- {
- target: background
- property: "color"
- value: base.enabled ? headerBackgroundColor : UM.Theme.getColor("disabled")
- }
- implicitHeight: 100 * screenScaleFactor
- implicitWidth: 400 * screenScaleFactor
- RoundedRectangle
- {
- id: background
- property real padding: UM.Theme.getSize("default_margin").width
- color: base.enabled ? headerBackgroundColor : UM.Theme.getColor("disabled")
- anchors.fill: parent
- Label
- {
- id: disabledLabel
- visible: !base.enabled
- leftPadding: background.padding
- text: ""
- font: UM.Theme.getFont("default")
- renderType: Text.NativeRendering
- verticalAlignment: Text.AlignVCenter
- color: UM.Theme.getColor("text")
- height: parent.height
- }
- Item
- {
- anchors.fill: parent
- visible: base.enabled
- MouseArea
- {
- id: headerMouseArea
- anchors.fill: parent
- onClicked: toggleContent()
- hoverEnabled: true
- onEntered: background.color = headerHoverColor
- onExited: background.color = base.enabled ? headerBackgroundColor : UM.Theme.getColor("disabled")
- }
- Loader
- {
- id: headerItemLoader
- anchors
- {
- left: parent.left
- right: collapseButton.visible ? collapseButton.left : parent.right
- top: parent.top
- bottom: parent.bottom
- margins: background.padding
- }
- }
-
- Rectangle
- {
- id: expandedHighlight
- width: parent.width
- height: UM.Theme.getSize("thick_lining").height
- color: UM.Theme.getColor("primary")
- visible: expanded
- anchors.bottom: parent.bottom
- }
- UM.RecolorImage
- {
- id: collapseButton
- anchors
- {
- right: parent.right
- verticalCenter: parent.verticalCenter
- margins: background.padding
- }
- source: expanded ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_left")
- visible: source != ""
- width: UM.Theme.getSize("standard_arrow").width
- height: UM.Theme.getSize("standard_arrow").height
- color: UM.Theme.getColor("small_button_text")
- }
- }
- }
- DropShadow
- {
- id: shadow
-
- radius: 0
- anchors.fill: background
- source: background
- verticalOffset: base.shadowOffset
- visible: true
- color: UM.Theme.getColor("action_button_shadow")
-
- z: background.z - 1
- }
- Popup
- {
- id: content
-
- y: background.height + base.shadowOffset
-
-
- x: contentAlignment == ExpandablePopup.ContentAlignment.AlignRight ? -width + collapseButton.width + headerItemLoader.width + 3 * background.padding : 0
- padding: UM.Theme.getSize("default_margin").width
- closePolicy: Popup.CloseOnPressOutsideParent
- background: Cura.RoundedRectangle
- {
- cornerSide: Cura.RoundedRectangle.Direction.Down
- color: contentBackgroundColor
- border.width: UM.Theme.getSize("default_lining").width
- border.color: UM.Theme.getColor("lining")
- radius: UM.Theme.getSize("default_radius").width
- height: contentItem.implicitHeight || content.height
- }
- contentItem: Item {}
- onContentItemChanged:
- {
-
-
- content.width = contentItem.width + 2 * content.padding
- content.height = contentItem.height + 2 * content.padding
- }
- }
-
-
- Connections
- {
-
- target: content.contentItem
- function onWidthChanged() { content.width = content.contentItem.width + 2 * content.padding }
- function onHeightChanged() { content.height = content.contentItem.height + 2 * content.padding }
- }
- }
|