diff --git a/src/controls/private/PrivateActionToolButton.qml b/src/controls/private/PrivateActionToolButton.qml index 4488931f..d7b37148 100644 --- a/src/controls/private/PrivateActionToolButton.qml +++ b/src/controls/private/PrivateActionToolButton.qml @@ -1,76 +1,76 @@ /* * Copyright 2016 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.6 import QtQuick.Layouts 1.2 import QtQuick.Controls 2.0 as Controls import org.kde.kirigami 2.2 Controls.ToolButton { id: control implicitWidth: showText ? Math.max(background.implicitWidth, layout.implicitWidth + 16) : height implicitHeight: background.implicitHeight hoverEnabled: true property Action action property bool showText: true //we need our own text delegate text: "" checkable: action && action.checkable checked: action && action.checked enabled: action && action.enabled opacity: enabled ? 1 : 0.4 visible: action && action.visible onClicked: { if (action) { action.trigger(); } } flat: true contentItem: MouseArea { hoverEnabled: true onPressed: mouse.accepted = false Theme.colorSet: checked ? Theme.Selection : Theme.Window Theme.inherit: false RowLayout { id: layout anchors.centerIn: parent Icon { Layout.minimumWidth: 22 Layout.minimumHeight: 22 source: control.action ? control.action.iconName : "" visible: control.action && control.action.iconName != "" } - Label { + Controls.Label { text: action ? action.text : "" visible: control.showText } } } Controls.ToolTip { visible: control.hovered text: action ? (action.tooltip.length ? action.tooltip : action.text) : "" delay: 1000 timeout: 5000 y: control.height } } diff --git a/src/controls/templates/FormLayout.qml b/src/controls/templates/FormLayout.qml index 35b6e06f..c56b4073 100644 --- a/src/controls/templates/FormLayout.qml +++ b/src/controls/templates/FormLayout.qml @@ -1,156 +1,169 @@ /* * Copyright 2017 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.6 import QtQuick.Layouts 1.2 import QtQuick.Controls 2.2 import org.kde.kirigami 2.3 as Kirigami Control { id: root implicitWidth: lay.implicitWidth implicitHeight: lay.implicitHeight Layout.preferredHeight: lay.implicitHeight - property bool wideMode: width > Kirigami.Units.gridUnit * 15 + property bool wideMode: width >= lay.wideImplicitWidth GridLayout { id: lay + property int wideImplicitWidth columns: root.wideMode ? 2 : 1 rowSpacing: Kirigami.Units.smallSpacing columnSpacing: Kirigami.Units.smallSpacing property var knownItems: [] anchors { left: parent.left top: parent.top right: parent.right } + + Timer { + id: hintCompression + onTriggered: { + if (root.wideMode) { + lay.wideImplicitWidth = lay.implicitWidth; + } + } + } + onImplicitWidthChanged: hintCompression.restart(); + Component.onCompleted: wideImplicitWidth = lay.implicitWidth; } Item { id: temp + Text {text: root.width+" "+lay.wideImplicitWidth+ " "+lay.implicitWidth} } Timer { id: relayoutTimer interval: 0 onTriggered: { var __items = children; //exclude the layout and temp for (var i = 2; i < __items.length; ++i) { var item = __items[i]; //skip items that are already there if (lay.knownItems.indexOf(item) != -1 || //item.parent && item.parent.parent == lay || //exclude Repeaters //NOTE: this is an heuristic but there are't better ways (item.model !== undefined && item.children.length == 0)) { continue; } lay.knownItems.push(item); var itemContainer = itemComponent.createObject(temp, {"item": item}) - //item.parent = itemContainer; - item.anchors.fill = itemContainer; + //if section, label goes after the separator if (item.Kirigami.FormData.isSection) { //put an extra spacer var placeHolder = placeHolderComponent.createObject(lay, {"item": item}); placeHolder.Layout.colSpan = 2; itemContainer.parent = lay; } var buddy = buddyComponent.createObject(lay, {"item": item}) itemContainer.parent = lay; //if section, wee need another placeholder if (item.Kirigami.FormData.isSection) { var placeHolder = placeHolderComponent.createObject(lay, {"item": item}); placeHolder.parent = lay; } } } } onChildrenChanged: relayoutTimer.restart(); Component.onCompleted: childrenChanged() Component { id: itemComponent Item { id: container property var item enabled: item.enabled visible: item.visible implicitWidth: item.implicitWidth + Layout.preferredWidth: item.Layout.preferredWidth Layout.preferredHeight: Math.max(item.Layout.preferredHeight, item.implicitHeight) - Layout.alignment: (root.wideMode ? Qt.AlignLeft : Qt.AlignHCenter) | Qt.AlignVCenter + Layout.alignment: (root.wideMode ? Qt.AlignLeft | Qt.AlignVCenter : Qt.AlignHCenter | Qt.AlignTop) Layout.fillWidth: item.Kirigami.FormData.isSection Layout.columnSpan: item.Kirigami.FormData.isSection ? lay.columns : 1 onItemChanged: { if (!item) { container.destroy(); } } onXChanged: item.x = x; onYChanged: item.y = y; - onWidthChanged: { - if (item.Kirigami.FormData.isSection) { - item.width = width; - } - } + onWidthChanged: item.width = width; } } Component { id: placeHolderComponent Item { property var item enabled: item.enabled visible: item.visible width: Kirigami.Units.smallSpacing height: Kirigami.Units.smallSpacing onItemChanged: { if (!item) { labelItem.destroy(); } } } } Component { id: buddyComponent Kirigami.Heading { id: labelItem + property var item enabled: item.enabled visible: item.visible text: item.Kirigami.FormData.label level: item.Kirigami.FormData.isSection ? 3 : 5 Layout.preferredHeight: item.Kirigami.FormData.label.length > 0 ? implicitHeight : Kirigami.Units.smallSpacing + Layout.alignment: root.wideMode ? (Qt.AlignRight | (item.Kirigami.FormData.buddyFor.height > height * 2 ? Qt.AlignTop : Qt.AlignVCenter)) : (Qt.AlignLeft | Qt.AlignBottom) - Layout.topMargin: item.Kirigami.FormData.buddyFor.height > height * 2 ? Kirigami.Units.smallSpacing : 0 + verticalAlignment: root.wideMode ? Text.AlignVCenter : Text.AlignBottom + + Layout.topMargin: item.Kirigami.FormData.buddyFor.height > implicitHeight * 2 ? Kirigami.Units.smallSpacing/2 : 0 onItemChanged: { if (!item) { labelItem.destroy(); } } } } }