/usr/lib/x86_64-linux-gnu/qt5/qml/org/kde/kirigami.2/templates/FormLayout.qml is in qml-module-org-kde-kirigami2 5.44.0-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | /*
* Copyright 2017 Marco Martin <mart@kde.org>
*
* 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
/**
* This is the base class for Form layouts conforming to the
* Kirigami Human interface guidelines. The layout will
* be divided in two columns: on the right there will be a column
* of fields, on the left their labels specified in the FormData attached
* property.
*
* Example:
* @code
* import org.kde.kirigami 2.3 as Kirigami
* Kirigami.FormLayout {
* TextField {
* Kirigami.FormData.label: "Label:"
* }
* Kirigami.Separator {
* Kirigami.FormData.label: "Section Title"
* Kirigami.FormData.isSection: true
* }
* TextField {
* Kirigami.FormData.label: "Label:"
* }
* TextField {
* }
* }
* @endcode
* @inherits QtQuick.Controls.Control
* @since 2.3
*/
Control {
id: root
/**
* wideMode: bool
* If true the layout will be optimized for a wide screen, such as
* a desktop machine (the labels will be on a left column,
* the fields on a right column beside it), if false (such as on a phone)
* everything is laid out in a single column.
* by default this will be based on wether the application is
* wide enough for the layout of being in such mode.
* It can be overridden by reasigning the property
*/
property bool wideMode: width >= lay.wideImplicitWidth
implicitWidth: lay.implicitWidth
implicitHeight: lay.implicitHeight
Layout.preferredHeight: lay.implicitHeight
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
}
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 ||
//exclude Repeaters
//NOTE: this is an heuristic but there are't better ways
(item.hasOwnProperty("model") && item.model !== undefined && item.children.length == 0)) {
continue;
}
lay.knownItems.push(item);
var itemContainer = itemComponent.createObject(temp, {"item": item})
//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: relayoutTimer.triggered();
Component {
id: itemComponent
Item {
id: container
property var item
enabled: item.enabled
visible: item.visible
implicitWidth: item.implicitWidth
Layout.preferredWidth: item.Layout.preferredWidth > 0 ? item.Layout.preferredWidth : item.implicitWidth
Layout.preferredHeight: item.Layout.preferredHeight > 0 ? item.Layout.preferredHeight : item.implicitHeight
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: 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
Kirigami.MnemonicData.enabled: item.Kirigami.FormData.buddyFor && item.Kirigami.FormData.buddyFor.activeFocusOnTab
Kirigami.MnemonicData.controlType: Kirigami.MnemonicData.FormLabel
Kirigami.MnemonicData.label: item.Kirigami.FormData.label
text: Kirigami.MnemonicData.richTextLabel
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)
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();
}
}
Shortcut {
sequence: labelItem.Kirigami.MnemonicData.sequence
onActivated: item.Kirigami.FormData.buddyFor.forceActiveFocus()
}
}
}
}
|