From 667dce502acf1dcafb174bd019f918f752ee0a0b Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Fri, 14 Feb 2020 13:09:17 +0100 Subject: [PATCH] make sure the size hints are integer and even Summary: for retrocompatibility with pc2 units.gridUnit * 1.6 is used a lot as size hint (we have to guarantee buttons and textfields have the same height by default for perfect horizontal alignment. tough we have make sure that size is integer and even otherwise we'll have a lot of internal misalignments Reviewers: broulik Reviewed By: broulik Subscribers: kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D27399 --- .../plasmacomponents3/Button.qml | 6 +++--- .../plasmacomponents3/TabButton.qml | 3 +-- .../plasmacomponents3/TextField.qml | 2 +- .../plasmacomponents3/ToolButton.qml | 21 ++++++++++--------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/declarativeimports/plasmacomponents3/Button.qml b/src/declarativeimports/plasmacomponents3/Button.qml index b642c029d..beedb9d75 100644 --- a/src/declarativeimports/plasmacomponents3/Button.qml +++ b/src/declarativeimports/plasmacomponents3/Button.qml @@ -46,8 +46,7 @@ T.Button { PlasmaCore.IconItem { id: icon - Layout.fillWidth: control.icon.width <= 0 - Layout.fillHeight: control.icon.height <= 0 + 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 @@ -72,7 +71,8 @@ T.Button { background: Item { //retrocompatibility with old controls - implicitHeight: units.gridUnit * 1.6 + implicitWidth: Math.floor(units.gridUnit * 1.6) + Math.floor(units.gridUnit * 1.6) % 2 + implicitHeight: implicitWidth 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 index b500e808e..46dbdd28a 100644 --- a/src/declarativeimports/plasmacomponents3/TabButton.qml +++ b/src/declarativeimports/plasmacomponents3/TabButton.qml @@ -45,8 +45,7 @@ T.TabButton { PlasmaCore.IconItem { id: icon - Layout.fillWidth: control.icon.width <= 0 - Layout.fillHeight: control.icon.height <= 0 + 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 diff --git a/src/declarativeimports/plasmacomponents3/TextField.qml b/src/declarativeimports/plasmacomponents3/TextField.qml index 523a25740..93dabd843 100644 --- a/src/declarativeimports/plasmacomponents3/TextField.qml +++ b/src/declarativeimports/plasmacomponents3/TextField.qml @@ -32,7 +32,7 @@ T.TextField { implicitWidth: Math.max(units.gridUnit * 8, placeholderText ? placeholder.implicitWidth + leftPadding + rightPadding : 0) || contentWidth + leftPadding + rightPadding - implicitHeight: units.gridUnit * 1.6 + implicitHeight: Math.floor(units.gridUnit * 1.6) + Math.floor(units.gridUnit * 1.6) % 2 padding: 6 diff --git a/src/declarativeimports/plasmacomponents3/ToolButton.qml b/src/declarativeimports/plasmacomponents3/ToolButton.qml index 113a9c675..eef596381 100644 --- a/src/declarativeimports/plasmacomponents3/ToolButton.qml +++ b/src/declarativeimports/plasmacomponents3/ToolButton.qml @@ -50,8 +50,7 @@ T.ToolButton { PlasmaCore.IconItem { id: icon - Layout.fillWidth: control.icon.width <= 0 - Layout.fillHeight: control.icon.height <= 0 + 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 @@ -60,12 +59,7 @@ T.ToolButton { source: control.icon ? (control.icon.name || control.icon.source) : "" status: control.activeFocus && !control.pressed && !control.checked ? PlasmaCore.Svg.Selected : PlasmaCore.Svg.Normal } - PlasmaCore.FrameSvgItem { - id: buttonsurfaceChecker - visible: false - imagePath: "widgets/button" - prefix: control.flat ? ["toolbutton-hover", "normal"] : "normal" - } + Label { Layout.fillWidth: true visible: text.length > 0 @@ -76,13 +70,20 @@ T.ToolButton { horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter elide: Text.ElideRight + + PlasmaCore.FrameSvgItem { + id: buttonsurfaceChecker + visible: false + imagePath: "widgets/button" + prefix: control.flat ? ["toolbutton-hover", "normal"] : "normal" + } } } background: Item { //retrocompatibility with old controls - implicitWidth: units.gridUnit * 1.6 - implicitHeight: units.gridUnit * 1.6 + implicitWidth: Math.floor(units.gridUnit * 1.6) + Math.floor(units.gridUnit * 1.6) % 2 + implicitHeight: implicitWidth Private.ButtonShadow { anchors.fill: parent visible: (!control.flat || control.hovered) && (!control.pressed || !control.checked)