diff --git a/src/declarativeimports/plasmacomponents3/Button.qml b/src/declarativeimports/plasmacomponents3/Button.qml --- a/src/declarativeimports/plasmacomponents3/Button.qml +++ b/src/declarativeimports/plasmacomponents3/Button.qml @@ -31,6 +31,8 @@ contentItem.implicitWidth + leftPadding + rightPadding) implicitHeight: Math.max(background.implicitHeight, contentItem.implicitHeight + topPadding + bottomPadding) + Layout.minimumWidth: contentItem.implicitWidth + leftPadding + rightPadding + leftPadding: surfaceNormal.margins.left topPadding: surfaceNormal.margins.top rightPadding: surfaceNormal.margins.right @@ -42,37 +44,50 @@ Kirigami.MnemonicData.controlType: Kirigami.MnemonicData.SecondaryControl Kirigami.MnemonicData.label: control.text - contentItem: RowLayout { + PlasmaCore.ColorScope.inherit: flat + PlasmaCore.ColorScope.colorGroup: flat ? parent.PlasmaCore.ColorScope.colorGroup : PlasmaCore.Theme.ButtonColorGroup + + contentItem: GridLayout { + columns: control.display == T.AbstractButton.TextBesideIcon ? 2 : 1 PlasmaCore.IconItem { id: icon Layout.alignment: Qt.AlignCenter - Layout.preferredWidth: control.icon.width > 0 ? control.icon.width : units.iconSizes.small - Layout.preferredHeight: control.icon.height > 0 ? control.icon.height : units.iconSizes.small + + Layout.fillWidth: control.display === T.Button.TextUnderIcon + Layout.fillHeight: control.display !== T.Button.TextUnderIcon + + Layout.minimumWidth: units.iconSizes.tiny + Layout.minimumHeight: units.iconSizes.tiny + Layout.maximumWidth: control.icon.width > 0 ? control.icon.width : units.iconSizes.small + Layout.maximumHeight: control.icon.height > 0 ? control.icon.height : units.iconSizes.small + + implicitWidth: Layout.maximumWidth + implicitHeight: Layout.maximumHeight colorGroup: PlasmaCore.Theme.ButtonColorGroup - visible: source.length > 0 + visible: source.length > 0 && control.display !== T.Button.TextOnly source: control.icon ? (control.icon.name || control.icon.source) : "" - status: buttonSvg.hasElement("hint-focus-highlighted-background") && control.activeFocus && !control.pressed && !control.checked ? PlasmaCore.Svg.Selected : PlasmaCore.Svg.Normal + status: !control.flat && buttonSvg.hasElement("hint-focus-highlighted-background") && control.activeFocus && !control.pressed && !control.checked ? PlasmaCore.Svg.Selected : PlasmaCore.Svg.Normal } Label { + id: label Layout.fillWidth: true - Layout.fillHeight: true - visible: text.length > 0 + visible: text.length > 0 && control.display !== T.Button.IconOnly text: control.Kirigami.MnemonicData.richTextLabel font: control.font opacity: enabled || control.highlighted || control.checked ? 1 : 0.4 color: buttonSvg.hasElement("hint-focus-highlighted-background") && control.activeFocus && !control.down ? theme.highlightedTextColor : theme.buttonTextColor - horizontalAlignment: Text.AlignHCenter + horizontalAlignment: control.display !== T.Button.TextUnderIcon && icon.visible ? Text.AlignLeft : Text.AlignHCenter verticalAlignment: Text.AlignVCenter elide: Text.ElideRight } } background: Item { //retrocompatibility with old controls - implicitWidth: Math.floor(units.gridUnit * 1.6) + Math.floor(units.gridUnit * 1.6) % 2 - implicitHeight: implicitWidth + implicitWidth: label.visible ? units.gridUnit * 6 : implicitHeight + implicitHeight: Math.floor(units.gridUnit * 1.6) + Math.floor(units.gridUnit * 1.6) % 2 Private.ButtonShadow { anchors.fill: parent visible: (!control.flat || control.hovered) && (!control.pressed || !control.checked) diff --git a/src/declarativeimports/plasmacomponents3/TabButton.qml b/src/declarativeimports/plasmacomponents3/TabButton.qml --- a/src/declarativeimports/plasmacomponents3/TabButton.qml +++ b/src/declarativeimports/plasmacomponents3/TabButton.qml @@ -46,18 +46,26 @@ id: icon Layout.alignment: Qt.AlignCenter - Layout.preferredWidth: control.icon.width > 0 ? control.icon.width : units.iconSizes.smallMedium - Layout.preferredHeight: control.icon.height > 0 ? control.icon.height : units.iconSizes.smallMedium - colorGroup: PlasmaCore.Theme.ButtonColorGroup - visible: source.length > 0 + Layout.fillWidth: control.display === T.AbstractButton.TextUnderIcon + Layout.fillHeight: control.display !== T.AbstractButton.TextUnderIcon + + Layout.minimumWidth: units.iconSizes.tiny + Layout.minimumHeight: units.iconSizes.tiny + Layout.maximumWidth: control.icon.width > 0 ? control.icon.width : units.iconSizes.smallMedium + Layout.maximumHeight: control.icon.height > 0 ? control.icon.height : units.iconSizes.smallMedium + + implicitWidth: Layout.maximumWidth + implicitHeight: Layout.maximumHeight + + colorGroup: control.PlasmaCore.ColorScope.colorGroup + visible: source.length > 0 && control.display !== T.AbstractButton.TextOnly source: control.icon ? (control.icon.name || control.icon.source) : "" - status: control.activeFocus && !control.pressed && !control.checked ? PlasmaCore.Svg.Selected : PlasmaCore.Svg.Normal } Label { + id: label Layout.fillWidth: true - Layout.fillHeight: true - visible: text.length > 0 + visible: text.length > 0 && control.display !== T.AbstractButton.IconOnly text: control.Kirigami.MnemonicData.richTextLabel font: control.font opacity: enabled || control.highlighted || control.checked ? 1 : 0.4 diff --git a/src/declarativeimports/plasmacomponents3/TextField.qml b/src/declarativeimports/plasmacomponents3/TextField.qml --- a/src/declarativeimports/plasmacomponents3/TextField.qml +++ b/src/declarativeimports/plasmacomponents3/TextField.qml @@ -32,7 +32,7 @@ implicitWidth: Math.max(units.gridUnit * 8, placeholderText ? placeholder.implicitWidth + leftPadding + rightPadding : 0) || contentWidth + leftPadding + rightPadding - implicitHeight: Math.floor(units.gridUnit * 1.6) + Math.floor(units.gridUnit * 1.6) % 2 + implicitHeight: background.implicitHeight padding: 6 @@ -100,6 +100,13 @@ } background: Item { + implicitHeight: Math.max(Math.floor(metrics.height * 1.6) + Math.floor(metrics.height * 1.6) % 2, + metrics.height + base.margins.top + base.margins.bottom) + TextMetrics { + id: metrics + text: "M" + font: control.font + } Private.TextFieldFocus { state: control.activeFocus ? "focus" : (control.hovered ? "hover" : "hidden") anchors.fill: parent diff --git a/src/declarativeimports/plasmacomponents3/ToolButton.qml b/src/declarativeimports/plasmacomponents3/ToolButton.qml --- a/src/declarativeimports/plasmacomponents3/ToolButton.qml +++ b/src/declarativeimports/plasmacomponents3/ToolButton.qml @@ -45,27 +45,41 @@ flat: true + PlasmaCore.ColorScope.inherit: flat + PlasmaCore.ColorScope.colorGroup: flat ? parent.PlasmaCore.ColorScope.colorGroup : PlasmaCore.Theme.ButtonColorGroup + contentItem: GridLayout { columns: control.display == T.AbstractButton.TextBesideIcon ? 2 : 1 + PlasmaCore.IconItem { id: icon Layout.alignment: Qt.AlignCenter - Layout.preferredWidth: control.icon.width > 0 ? control.icon.width : units.iconSizes.smallMedium - Layout.preferredHeight: control.icon.height > 0 ? control.icon.height : units.iconSizes.smallMedium - colorGroup: PlasmaCore.Theme.ButtonColorGroup - visible: source.length > 0 + Layout.fillWidth: control.display === T.AbstractButton.TextUnderIcon + Layout.fillHeight: control.display !== T.AbstractButton.TextUnderIcon + + Layout.minimumWidth: units.iconSizes.tiny + Layout.minimumHeight: units.iconSizes.tiny + Layout.maximumWidth: control.icon.width > 0 ? control.icon.width : units.iconSizes.smallMedium + Layout.maximumHeight: control.icon.height > 0 ? control.icon.height : units.iconSizes.smallMedium + + implicitWidth: Layout.maximumWidth + implicitHeight: Layout.maximumHeight + + colorGroup: control.PlasmaCore.ColorScope.colorGroup + visible: source.length > 0 && control.display !== T.AbstractButton.TextOnly source: control.icon ? (control.icon.name || control.icon.source) : "" - status: control.activeFocus && !control.pressed && !control.checked ? PlasmaCore.Svg.Selected : PlasmaCore.Svg.Normal + status: !control.flat && control.activeFocus && !control.pressed && !control.checked ? PlasmaCore.Svg.Selected : PlasmaCore.Svg.Normal } Label { + id: label Layout.fillWidth: true - visible: text.length > 0 + visible: text.length > 0 && control.display !== T.AbstractButton.IconOnly text: control.Kirigami.MnemonicData.richTextLabel font: control.font - opacity: enabled || control.highlighted || control.checked ? 1 : 0.4 + opacity: width > 0 ? (enabled || control.highlighted || control.checked ? 1 : 0.4) : 0 color: (control.hovered || !control.flat) && buttonsurfaceChecker.usedPrefix != "toolbutton-hover" ? theme.buttonTextColor : PlasmaCore.ColorScope.textColor horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter diff --git a/tests/components/button3.qml b/tests/components/button3.qml --- a/tests/components/button3.qml +++ b/tests/components/button3.qml @@ -87,7 +87,42 @@ RowLayout { PlasmaComponents.Button { text: "AA" -// implicitWidth: minimumWidth FIXME, there is no equivalent? + implicitWidth: Layout.minimumWidth + } + PlasmaComponents.Button { + icon.name: "application-menu" + text: "AA" + implicitWidth: Layout.minimumWidth + } + PlasmaComponents.Button { + icon.name: "application-menu" + implicitWidth: Layout.minimumWidth + } + } + + PlasmaComponents.Label { + text: "Display property" + } + RowLayout { + PlasmaComponents.Button { + icon.name: "application-menu" + text: "Icon Only" + display: PlasmaComponents.Button.IconOnly + } + PlasmaComponents.Button { + icon.name: "application-menu" + text: "Text Beside Icon" + display: PlasmaComponents.Button.TextBesideIcon + } + PlasmaComponents.Button { + icon.name: "application-menu" + text: "Text Under Icon" + display: PlasmaComponents.Button.TextUnderIcon + } + PlasmaComponents.Button { + icon.name: "application-menu" + text: "Text Only" + display: PlasmaComponents.Button.TextOnly } } diff --git a/tests/components/tabbar3.qml b/tests/components/tabbar3.qml new file mode 100644 --- /dev/null +++ b/tests/components/tabbar3.qml @@ -0,0 +1,35 @@ +import QtQuick 2.0 + +import org.kde.plasma.core 2.0 as PlasmaCore + +import org.kde.plasma.components 3.0 as PlasmaComponents + +ComponentBase { + PlasmaComponents.TabBar { + anchors.fill: parent + anchors.margins: 20 + spacing: 20 + + PlasmaComponents.TabButton { + icon.name: "application-menu" + text: "Icon Only" + display: PlasmaComponents.TabButton.IconOnly + } + PlasmaComponents.TabButton { + icon.name: "application-menu" + text: "Text Beside Icon" + display: PlasmaComponents.TabButton.TextBesideIcon + } + PlasmaComponents.TabButton { + icon.name: "application-menu" + text: "Text Under Icon" + display: PlasmaComponents.TabButton.TextUnderIcon + } + PlasmaComponents.TabButton { + icon.name: "application-menu" + text: "Text Only" + display: PlasmaComponents.TabButton.TextOnly + } + } +} + diff --git a/tests/components/toolbutton3.qml b/tests/components/toolbutton3.qml --- a/tests/components/toolbutton3.qml +++ b/tests/components/toolbutton3.qml @@ -1,40 +1,84 @@ import QtQuick 2.0 +import QtQuick.Layouts 1.4 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 3.0 as PlasmaComponents ComponentBase { - Flow { + ColumnLayout { anchors.fill: parent anchors.margins: 20 - spacing: 20 + Flow { + Layout.fillWidth: true + Layout.fillHeight: true + spacing: 20 - PlasmaComponents.ToolButton { - icon.name: "list-remove" - text: "test" - flat: true + PlasmaComponents.ToolButton { + icon.name: "list-remove" + text: "test" + flat: true + } + PlasmaComponents.ToolButton { + icon.name: "list-remove" + flat: true + } + PlasmaComponents.ToolButton { + text: "test" + flat: true + } + PlasmaComponents.ToolButton { + icon.name: "list-remove" + text: "test" + flat: false + } + PlasmaComponents.ToolButton { + icon.name: "list-remove" + flat: false + } + PlasmaComponents.ToolButton { + text: "test" + flat: false + } + PlasmaComponents.ToolButton { + icon.name: "application-menu" + text: "Icon Only" + display: PlasmaComponents.ToolButton.IconOnly + } + PlasmaComponents.ToolButton { + icon.name: "application-menu" + text: "Text Beside Icon" + display: PlasmaComponents.ToolButton.TextBesideIcon + } + PlasmaComponents.ToolButton { + icon.name: "application-menu" + text: "Text Under Icon" + display: PlasmaComponents.ToolButton.TextUnderIcon + } + PlasmaComponents.ToolButton { + icon.name: "application-menu" + text: "Text Only" + display: PlasmaComponents.ToolButton.TextOnly + } } - PlasmaComponents.ToolButton { - icon.name: "list-remove" - flat: true - } - PlasmaComponents.ToolButton { - text: "test" - flat: true - } - PlasmaComponents.ToolButton { - icon.name: "list-remove" - text: "test" - flat: false - } - PlasmaComponents.ToolButton { - icon.name: "list-remove" - flat: false - } - PlasmaComponents.ToolButton { - text: "test" - flat: false + RowLayout { + Layout.fillWidth: true + PlasmaComponents.Label { + Layout.fillWidth: true + text: "They should always be square:" + } + PlasmaComponents.ToolButton { + icon.name: "list-remove" + } + PlasmaComponents.ToolButton { + icon.name: "list-remove" + } + PlasmaComponents.ToolButton { + icon.name: "list-remove" + } + PlasmaComponents.ToolButton { + icon.name: "list-remove" + } } } }