8pragma ComponentBehavior: Bound
12import QtQuick.Controls as QQC2
13import QtQuick.Templates as T
14import org.kde.kirigami as Kirigami
68 property bool wideMode: width >= lay.wideImplicitWidth
77 property list<Item> twinFormLayouts
79 onTwinFormLayoutsChanged: {
80 for (
const twinFormLayout of twinFormLayouts) {
81 if (!(root in twinFormLayout.children[0].reverseTwins)) {
82 twinFormLayout.children[0].reverseTwins.push(root)
83 Qt.callLater(() => twinFormLayout.children[0].reverseTwinsChanged());
88 Component.onCompleted: {
89 relayoutTimer.triggered();
92 Component.onDestruction: {
93 for (
const twinFormLayout of twinFormLayouts) {
94 const child = twinFormLayout.children[0];
95 child.reverseTwins = child.reverseTwins.filter(value => value !== root);
99 implicitWidth: lay.wideImplicitWidth
100 implicitHeight: lay.implicitHeight
101 Layout.preferredHeight: lay.implicitHeight
102 Layout.fillWidth:
true
103 Accessible.role: Accessible.Form
107 property int wideImplicitWidth
108 columns: root.wideMode ? 2 : 1
109 rowSpacing: Kirigami.Units.smallSpacing
110 columnSpacing: Kirigami.Units.largeSpacing
118 restoreMode: Binding.RestoreBinding
124 value: root.implicitWidth
125 restoreMode: Binding.RestoreBinding
128 horizontalCenter: root.wideMode ? root.horizontalCenter : undefined
129 left: root.wideMode ? undefined : root.left
132 property var reverseTwins: []
133 property var knownItems: []
134 property var buddies: []
135 property int knownItemsImplicitWidth: {
137 for (
const item of knownItems) {
138 if (typeof item.Layout ===
"undefined") {
148 const actualWidth = item.Layout.preferredWidth > 0
149 ? item.Layout.preferredWidth
150 : item.implicitWidth;
152 hint = Math.max(hint, item.Layout.minimumWidth, Math.min(actualWidth, item.Layout.maximumWidth));
156 property int buddiesImplicitWidth: {
159 for (
const buddy of buddies) {
160 if (buddy.visible && buddy.item !== null && !buddy.item.Kirigami.FormData.isSection) {
161 hint = Math.max(hint, buddy.implicitWidth);
166 readonly
property var actualTwinFormLayouts: {
168 const list = lay.reverseTwins.slice();
169 for (
const parentLay of root.twinFormLayouts) {
170 if (!parentLay || !parentLay.hasOwnProperty(
"children")) {
173 list.push(parentLay);
174 for (
const childLay of parentLay.children[0].reverseTwins) {
175 if (childLay && !(childLay in list)) {
188 lay.wideImplicitWidth = lay.implicitWidth;
192 onImplicitWidthChanged: hintCompression.restart();
196 Layout.preferredWidth: {
197 let
hint = lay.buddiesImplicitWidth;
198 for (
const item of lay.actualTwinFormLayouts) {
199 if (item && item.hasOwnProperty(
"children")) {
200 hint = Math.max(hint, item.children[0].buddiesImplicitWidth);
205 Layout.preferredHeight: 2
208 Layout.preferredWidth: {
209 let
hint = Math.min(root.width, lay.knownItemsImplicitWidth);
210 for (
const item of lay.actualTwinFormLayouts) {
211 if (item.hasOwnProperty(
"children")) {
212 hint = Math.max(hint, item.children[0].knownItemsImplicitWidth);
217 Layout.preferredHeight: 2
240 function effectiveLayout(item:
Item): int {
244 const verticalAlignment =
245 item.Kirigami.FormData.labelAlignment !== 0
246 ? item.Kirigami.FormData.labelAlignment
249 if (item.Kirigami.FormData.isSection) {
250 return Qt.AlignHCenter;
253 return Qt.AlignRight | verticalAlignment;
255 return Qt.AlignLeft |
Qt.AlignBottom;
262 function effectiveTextLayout(item:
Item): int {
266 if (root.wideMode && !item.Kirigami.FormData.isSection) {
267 return item.Kirigami.FormData.labelAlignment !== 0 ? item.Kirigami.FormData.labelAlignment : Text.AlignVCenter;
269 return Text.AlignBottom;
277 const __items = root.children;
279 for (let i = 2; i < __items.length; ++i) {
280 const item = __items[i];
283 if (lay.knownItems.indexOf(item) !== -1 || item instanceof Repeater) {
286 lay.knownItems.push(item);
288 const itemContainer = itemComponent.createObject(temp, { item });
291 if (item.Kirigami.FormData.label.length > 0 && item.Kirigami.FormData.isSection) {
292 placeHolderComponent.createObject(lay, { item });
295 const buddy = buddyComponent.createObject(lay, { item, index: i - 2 });
297 itemContainer.parent = lay;
298 lay.buddies.push(buddy);
300 lay.knownItemsChanged();
301 lay.buddiesChanged();
302 hintCompression.triggered();
306 onChildrenChanged: relayoutTimer.restart();
315 enabled: item?.
enabled ??
false
316 visible: item?.visible ??
false
319 implicitWidth: item !== null ? Math.max(item.implicitWidth, 1) : 0
320 implicitHeight: item !== null ? Math.max(item.implicitHeight, 1) : 0
321 Layout.preferredWidth: item !== null ? Math.max(1, item.Layout.preferredWidth > 0 ? item.Layout.preferredWidth : Math.ceil(item.implicitWidth)) : 0
322 Layout.preferredHeight: item !== null ? Math.max(1, item.Layout.preferredHeight > 0 ? item.Layout.preferredHeight : Math.ceil(item.implicitHeight)) : 0
324 Layout.minimumWidth: item?.Layout.minimumWidth ?? 0
325 Layout.minimumHeight: item?.Layout.minimumHeight ?? 0
327 Layout.maximumWidth: item?.Layout.maximumWidth ?? 0
328 Layout.maximumHeight: item?.Layout.maximumHeight ?? 0
330 Layout.alignment:
Qt.AlignLeft |
Qt.AlignVCenter
331 Layout.fillWidth: item !== null && (item instanceof TextInput || item.Layout.fillWidth || item.Kirigami.FormData.isSection)
332 Layout.columnSpan: item?.Kirigami.FormData.isSection ? lay.columns : 1
338 onXChanged:
if (item !== null) { item.x = x + lay.x; }
340 onYChanged:
if (item !== null) { item.y = y + lay.y; }
341 onWidthChanged:
if (item !== null) { item.width = width; }
342 Component.onCompleted: item.
x = x + lay.x;
345 function onXChanged(): void {
346 if (container.item !== null) {
347 container.item.x = container.x + lay.x;
354 id: placeHolderComponent
358 enabled: item?.
enabled ??
false
359 visible: item?.visible ??
false
361 width: Kirigami.Units.smallSpacing
362 height: Kirigami.Units.smallSpacing
363 Layout.topMargin: item?.height > 0 ? Kirigami.Units.smallSpacing : 0
379 enabled: item?.
enabled ??
false
380 visible: (item?.visible && (root.wideMode || text.length > 0)) ??
false
381 Kirigami.MnemonicData.enabled: {
382 const buddy = item?.Kirigami.FormData.buddyFor;
383 if (buddy && buddy.enabled && buddy.visible && buddy.activeFocusOnTab) {
385 const buddyMnemonic = buddy.Kirigami.MnemonicData;
386 return !buddyMnemonic.label || !buddyMnemonic.enabled;
391 Kirigami.MnemonicData.controlType: Kirigami.MnemonicData.FormLabel
392 Kirigami.MnemonicData.label: item?.Kirigami.FormData.label ??
""
393 text: Kirigami.MnemonicData.richTextLabel
394 type: item?.Kirigami.FormData.isSection ? Kirigami.Heading.Type.Primary : Kirigami.Heading.Type.Normal
396 level: item?.Kirigami.FormData.isSection ? 3 : 5
398 Layout.columnSpan: item?.Kirigami.FormData.isSection ? lay.columns : 1
399 Layout.preferredHeight: {
403 if (item.Kirigami.FormData.label.length > 0) {
406 if (item.Kirigami.FormData.isSection && labelItem.index !== 0) {
407 return implicitHeight + Kirigami.Units.largeSpacing * 2;
409 else if (root.wideMode && !(item.Kirigami.FormData.buddyFor instanceof TextEdit)) {
410 return Math.max(implicitHeight, item.Kirigami.FormData.buddyFor.height)
412 return implicitHeight;
414 return Kirigami.Units.smallSpacing;
417 Layout.alignment: temp.effectiveLayout(item)
418 verticalAlignment: temp.effectiveTextLayout(item)
420 Layout.fillWidth: !root.wideMode
427 if (root.wideMode && item.Kirigami.FormData.buddyFor.parent !== root) {
428 return item.Kirigami.FormData.buddyFor.y;
430 if (index === 0 || root.wideMode) {
433 return Kirigami.Units.largeSpacing * 2;
441 sequence: labelItem.Kirigami.MnemonicData.sequence
443 const buddy = labelItem.item.Kirigami.FormData.buddyFor;
445 const buttonBuddy = buddy as T.AbstractButton;
448 if (buttonBuddy && buttonBuddy.animateClick) {
449 buttonBuddy.animateClick();
451 buddy.forceActiveFocus(
Qt.ShortcutFocusReason);
Type type(const QSqlDatabase &db)
QAction * hint(const QObject *recvr, const char *slot, QObject *parent)
QStringView level(QStringView ifopt)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
QTextStream & left(QTextStream &stream)