Warning, /plasma/qqc2-breeze-style/style/qtquickcontrols/TabButton.qml is written in an unsupported language. File is not indexed.
0001 /* SPDX-FileCopyrightText: 2020 Noah Davis <noahadvs@gmail.com>
0002 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0003 */
0004
0005 import QtQuick
0006 import QtQuick.Templates as T
0007 import org.kde.kirigami as Kirigami
0008 import org.kde.breeze
0009 import org.kde.breeze.impl as Impl
0010
0011 T.TabButton {
0012 id: control
0013
0014 readonly property bool __inTabBar: T.TabBar.tabBar != null
0015 readonly property bool __hasLeftSeparator: background && background.hasOwnProperty("leftSeparatorLine")
0016 readonly property bool __hasRightSeparator: background && background.hasOwnProperty("rightSeparatorLine")
0017 readonly property bool __inHeader: T.TabBar.position === T.TabBar.Header
0018 readonly property bool __inFooter: T.TabBar.position === T.TabBar.Footer
0019
0020 implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
0021 implicitContentWidth + leftPadding + rightPadding,
0022 implicitIndicatorWidth + leftPadding + rightPadding)
0023 implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
0024 implicitContentHeight + topPadding + bottomPadding,
0025 implicitIndicatorHeight + topPadding + bottomPadding)
0026
0027 padding: Kirigami.Units.mediumSpacing
0028 leftPadding: {
0029 if ((!contentItem.hasIcon && contentItem.textBesideIcon) // False if contentItem has been replaced
0030 || display == T.AbstractButton.TextOnly
0031 || display == T.AbstractButton.TextUnderIcon) {
0032 return Impl.Units.mediumHorizontalPadding
0033 } else {
0034 return control.horizontalPadding
0035 }
0036 }
0037 rightPadding: {
0038 if (contentItem.hasLabel && display != T.AbstractButton.IconOnly) { // False if contentItem has been replaced
0039 return Impl.Units.mediumHorizontalPadding
0040 } else {
0041 return control.horizontalPadding
0042 }
0043 }
0044
0045 leftInset: {
0046 if (!mirrored && __hasLeftSeparator && background.leftSeparatorLine.visible) {
0047 return background.leftSeparatorLine.width
0048 } else if (mirrored && __hasRightSeparator && background.rightSeparatorLine.visible) {
0049 return background.rightSeparatorLine.width
0050 } else {
0051 return 0
0052 }
0053 }
0054 rightInset: {
0055 if (!mirrored && __hasRightSeparator && background.leftSeparatorLine.visible) {
0056 return background.rightSeparatorLine.width
0057 } else if (mirrored && __hasLeftSeparator && background.rightSeparatorLine.visible) {
0058 return background.leftSeparatorLine.width
0059 } else {
0060 return 0
0061 }
0062 }
0063
0064 spacing: Kirigami.Units.mediumSpacing
0065
0066 icon.width: Kirigami.Units.iconSizes.sizeForLabels
0067 icon.height: Kirigami.Units.iconSizes.sizeForLabels
0068
0069 Kirigami.Theme.colorSet: {
0070 if (control.__inTabBar && !(control.checked)) {
0071 return T.TabBar.tabBar.Kirigami.Theme.colorSet
0072 } else {
0073 return Kirigami.Theme.Button
0074 }
0075 }
0076 Kirigami.Theme.inherit: !(background && background.visible)
0077
0078 contentItem:Impl.IconLabelContent {
0079 control: control
0080 }
0081
0082 //TODO: tweak the appearance. This is just to have something usable and reasonably close to what we want.
0083 background: Rectangle {
0084 implicitHeight: Impl.Units.mediumControlHeight + (Kirigami.Units.smallSpacing * 2) // fill TabBar
0085 implicitWidth: implicitHeight
0086 color: control.checked ? Kirigami.Theme.backgroundColor : "transparent"
0087
0088 property Rectangle leftSeparatorLine: Rectangle {
0089 parent: control.background
0090 visible: control.T.TabBar.index != 0 && control.checked
0091 Kirigami.Theme.colorSet: Kirigami.Theme.Button
0092 Kirigami.Theme.inherit: false
0093 anchors.left: parent.left
0094 anchors.leftMargin: -control.leftInset
0095 anchors.verticalCenter: parent.verticalCenter
0096 width: 1
0097 height: control.checked ? parent.height : Math.min(parent.height, Kirigami.Units.gridUnit)
0098 color: Impl.Theme.separatorColor()
0099 Behavior on height {
0100 NumberAnimation {
0101 easing.type: Easing.InOutQuad
0102 duration: Kirigami.Units.longDuration
0103 }
0104 }
0105 }
0106
0107 property Rectangle rightSeparatorLine: Rectangle {
0108 parent: control.background
0109 visible: control.__inTabBar && control.T.TabBar.index != control.T.TabBar.tabBar.count - 1 && control.checked
0110 Kirigami.Theme.colorSet: Kirigami.Theme.Button
0111 Kirigami.Theme.inherit: false
0112 anchors.right: parent.right
0113 anchors.rightMargin: -control.rightInset
0114 anchors.verticalCenter: parent.verticalCenter
0115 width: 1
0116 height: parent.leftSeparatorLine.height
0117 color: Impl.Theme.separatorColor()
0118 }
0119
0120 Rectangle {
0121 id: thickHighlightLine
0122 anchors.left: parent.left
0123 anchors.right: parent.right
0124 anchors.leftMargin: -control.leftInset
0125 anchors.rightMargin: -control.rightInset
0126 y: control.__inHeader ? 0 : parent.height - height
0127 height: Impl.Units.highlightLineThickness
0128 opacity: control.visualFocus || control.checked || control.hovered || control.down ? 1 : 0
0129 Kirigami.Theme.colorSet: Kirigami.Theme.Button
0130 Kirigami.Theme.inherit: false
0131 color: {
0132 if (control.visualFocus) {
0133 Kirigami.Theme.alternateBackgroundColor
0134 } else if (control.checked || control.down) {
0135 Kirigami.Theme.focusColor
0136 } else {
0137 Impl.Theme.separatorColor()
0138 }
0139 }
0140 Behavior on opacity {
0141 OpacityAnimator {
0142 easing.type: Easing.OutCubic
0143 duration: Kirigami.Units.shortDuration
0144 }
0145 }
0146 Behavior on color {
0147 ColorAnimation {
0148 easing.type: Easing.InOutQuad
0149 duration: Kirigami.Units.longDuration
0150 }
0151 }
0152 }
0153
0154 Rectangle {
0155 id: thinHighlightLine
0156 anchors.left: parent.left
0157 anchors.right: parent.right
0158 anchors.leftMargin: -control.leftInset
0159 anchors.rightMargin: -control.rightInset
0160 y: control.__inHeader ? 0 : parent.height - height
0161 height: 1
0162 opacity: control.visualFocus ? 1 : 0
0163 Kirigami.Theme.colorSet: Kirigami.Theme.Button
0164 Kirigami.Theme.inherit: false
0165 color: Kirigami.Theme.focusColor
0166 Behavior on opacity {
0167 OpacityAnimator {
0168 easing.type: Easing.OutCubic
0169 duration: Kirigami.Units.shortDuration
0170 }
0171 }
0172 }
0173 }
0174 }