diff --git a/src/declarativeimports/plasmastyle/ToolButtonStyle.qml b/src/declarativeimports/plasmastyle/ToolButtonStyle.qml --- a/src/declarativeimports/plasmastyle/ToolButtonStyle.qml +++ b/src/declarativeimports/plasmastyle/ToolButtonStyle.qml @@ -36,6 +36,7 @@ property int minimumHeight property bool flat: control.flat !== undefined ? control.flat : !(control.checkable && control.checked) property bool controlHovered: control.hovered && !(QtQuickControlsPrivate.Settings.hasTouchScreen && QtQuickControlsPrivate.Settings.isMobile) + property bool isRound: control.text.length == 0 && (control.parent && (control.parent.spacing === undefined || control.parent.spacing !== 0)) && !flat && !control.menu label: Item { //wrapper is needed as we are adjusting the preferredHeight of the layout from the default @@ -49,15 +50,15 @@ Layout.preferredHeight: Math.max(units.iconSizes.small, label.implicitHeight) - property real minimumWidth: Layout.minimumWidth + style.padding.left + style.padding.right + property real minimumWidth: Layout.minimumWidth onMinimumWidthChanged: { if (control.minimumWidth !== undefined) { style.minimumWidth = minimumWidth; control.minimumWidth = minimumWidth; } } - property real minimumHeight: Layout.preferredHeight + style.padding.top + style.padding.bottom + property real minimumHeight: Layout.preferredHeight onMinimumHeightChanged: { if (control.minimumHeight !== undefined) { style.minimumHeight = minimumHeight; @@ -123,7 +124,7 @@ } background: { - if (control.text.length == 0 && (control.parent && (control.parent.spacing === undefined || control.parent.spacing !== 0)) && !style.flat && !control.menu) { + if (isRound) { return roundButtonComponent } else { return buttonComponent @@ -206,151 +207,32 @@ } } - Private.ButtonShadow { - id: shadow - visible: !style.flat || control.activeFocus - anchors.fill: parent - enabledBorders: surfaceNormal.enabledBorders - state: { - if (control.pressed) { - return "hidden" - } else if (style.controlHovered) { - return "hover" - } else if (control.activeFocus) { - return "focus" - } else { - return "shadow" - } - } - } - - - //This code is duplicated here and Button and ToolButton - //maybe we can make an AbstractButton class? - PlasmaCore.FrameSvgItem { + Rectangle { id: surfaceNormal anchors.fill: parent - imagePath: "widgets/button" - prefix: "normal" - - enabledBorders: { - if (style.flat || !control.parent || - control.parent.width < control.parent.implicitWidth || - control.parent.spacing !== 0 || - !bordersSvg.hasElement("pressed-hint-compose-over-border")) { - if (shadows !== null) { - shadows.destroy() - } - return "AllBorders" - } - - var borders = new Array() - if (control.x == 0) { - borders.push("LeftBorder") - shadow.anchors.leftMargin = 0; - } else { - shadow.anchors.leftMargin = -1; - } - if (control.y == 0) { - borders.push("TopBorder") - shadow.anchors.topMargin = 0; - } else { - shadow.anchors.topMargin = -1; - } - if (control.x + control.width >= control.parent.width) { - borders.push("RightBorder") - shadow.anchors.rightMargin = 0; - } else { - shadow.anchors.rightMargin = -1; - } - if (control.y + control.height >= control.parent.height) { - borders.push("BottomBorder") - shadow.anchors.bottomMargin = 0; - } else { - shadow.anchors.bottomMargin = -1; - } - - if (shadows === null) { - shadows = shadowsComponent.createObject(buttonSurface) - } - - return borders.join("|") - } - - PlasmaCore.Svg { - id: bordersSvg - imagePath: "widgets/button" + radius: Math.min(height, width) * 0.1 + color: "transparent" + border { + width: Math.ceil(units.gridUnit / 30) + color: theme.highlightColor } - } - PlasmaCore.FrameSvgItem { + Rectangle { id: surfacePressed anchors.fill: parent - imagePath: "widgets/button" - prefix: "pressed" - enabledBorders: surfaceNormal.enabledBorders - opacity: 0 - } + radius: surfaceNormal.radius + color: "transparent" + border { + width: surfaceNormal.border.width + color: theme.highlightColor + } - property Item shadows - Component { - id: shadowsComponent - Item { + Rectangle { anchors.fill: parent - - PlasmaCore.SvgItem { - svg: bordersSvg - width: naturalSize.width - elementId: (buttonSurface.state == "pressed" ? surfacePressed.prefix : surfaceNormal.prefix) + "-left" - visible: button.x > 0 - anchors { - left: parent.left - top: parent.top - bottom: parent.bottom - margins: 1 - leftMargin: -1 - } - } - PlasmaCore.SvgItem { - svg: bordersSvg - width: naturalSize.width - elementId: (buttonSurface.state == "pressed" ? surfacePressed.prefix : surfaceNormal.prefix) + "-right" - visible: button.x + button.width < button.parent.width - anchors { - right: parent.right - top: parent.top - bottom: parent.bottom - margins: 1 - rightMargin: -1 - } - } - PlasmaCore.SvgItem { - svg: bordersSvg - height: naturalSize.height - elementId: (buttonSurface.state == "pressed" ? surfacePressed.prefix : surfaceNormal.prefix) + "-top" - visible: button.y > 0 - anchors { - left: parent.left - top: parent.top - right: parent.right - margins: 1 - topMargin: -1 - } - } - PlasmaCore.SvgItem { - svg: bordersSvg - height: naturalSize.height - elementId: (buttonSurface.state == "pressed" ? surfacePressed.prefix : surfaceNormal.prefix) + "-bottom" - visible: button.y + button.height < button.parent.height - anchors { - left: parent.left - right: parent.right - bottom: parent.bottom - margins: 1 - bottomMargin: -1 - } - } + radius: parent.radius + color: theme.highlightColor + opacity: 0.5 } } @@ -360,7 +242,7 @@ State { name: "normal" PropertyChanges { target: surfaceNormal - opacity: style.flat ? 0 : 1 + opacity: style.isRound ? 1 : 0 } PropertyChanges { target: surfacePressed @@ -398,13 +280,6 @@ } } ] - - Component.onCompleted: { - padding.top = surfaceNormal.margins.top - padding.left = surfaceNormal.margins.left - padding.right = surfaceNormal.margins.right - padding.bottom = surfaceNormal.margins.bottom - } } } }