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
79 onTwinFormLayoutsChanged: {
81 if (!(root in twinFormLayout.children[0].reverseTwins)) {
82 twinFormLayout.children[0].reverseTwins.push(root)
83 Qt.callLater(() => twinFormLayout.children[0].reverseTwinsChanged());
88 property Kirigami.ScrollablePage scrollablePage: findAncestor(root, (item) => item instanceof Kirigami.ScrollablePage)
90 function findAncestor(item:
Item, predicate: var):
Item {
91 let target = item.parent
92 while (target && !predicate(target)) {
98 function ensureVisible(item:
Item): void {
99 if (item && root.scrollablePage) {
100 const itemPosition = scrollablePage.flickable.contentItem.mapFromItem(item, 0, 0)
101 root.scrollablePage.ensureVisible(item, itemPosition.x - item.x, itemPosition.y - item.y)
107 enabled: root.scrollablePage
108 function onActiveFocusItemChanged(): void {
109 if (root.
Window.activeFocusItem && findAncestor(root.
Window.activeFocusItem, (item) => item === root)) {
110 root.ensureVisible(root.Window.activeFocusItem)
115 Component.onCompleted: {
116 relayoutTimer.triggered();
119 Component.onDestruction: {
120 for (
const twinFormLayout of twinFormLayouts) {
121 const child = twinFormLayout.children[0];
122 child.reverseTwins = child.reverseTwins.filter(value => value !== root);
126 implicitWidth: lay.wideImplicitWidth
127 implicitHeight: lay.implicitHeight
128 Layout.preferredHeight: lay.implicitHeight
129 Layout.fillWidth:
true
130 Accessible.role: Accessible.Form
134 property int wideImplicitWidth
135 columns: root.wideMode ? 2 : 1
136 rowSpacing: Kirigami.Units.smallSpacing
137 columnSpacing: Kirigami.Units.largeSpacing
145 value: Math.min(lay.implicitWidth, Kirigami.Units.gridUnit * 32, root.width)
146 restoreMode: Binding.RestoreBinding
152 value: root.implicitWidth
153 restoreMode: Binding.RestoreBinding
155 anchors.horizontalCenter: root.horizontalCenter
157 property var reverseTwins: []
158 property var knownItems: []
159 property var buddies: []
160 property int knownItemsImplicitWidth: {
162 for (
const item of knownItems) {
163 if (typeof item.Layout ===
"undefined") {
173 const actualWidth = item.Layout.preferredWidth > 0
174 ? item.Layout.preferredWidth
175 : item.implicitWidth;
177 hint = Math.max(hint, item.Layout.minimumWidth, Math.min(actualWidth, item.Layout.maximumWidth));
181 property int buddiesImplicitWidth: {
184 for (
const buddy of buddies) {
185 if (buddy.visible && buddy.item !== null && !buddy.item.Kirigami.FormData.isSection) {
186 hint = Math.max(hint, buddy.implicitWidth);
191 readonly
property var actualTwinFormLayouts: {
193 const list = lay.reverseTwins.slice();
194 for (
const parentLay of root.twinFormLayouts) {
195 if (!parentLay || !parentLay.hasOwnProperty(
"children")) {
198 list.push(parentLay);
199 for (
const childLay of parentLay.children[0].reverseTwins) {
200 if (childLay && !(childLay in list)) {
213 lay.wideImplicitWidth = lay.implicitWidth;
217 onImplicitWidthChanged: hintCompression.restart();
221 Layout.preferredWidth: {
222 let
hint = lay.buddiesImplicitWidth;
223 for (
const item of lay.actualTwinFormLayouts) {
224 if (item && item.hasOwnProperty(
"children")) {
225 hint = Math.max(hint, item.children[0].buddiesImplicitWidth);
230 Layout.preferredHeight: 2
233 Layout.preferredWidth: {
234 let
hint = Math.min(root.width, lay.knownItemsImplicitWidth);
235 for (
const item of lay.actualTwinFormLayouts) {
236 if (item.hasOwnProperty(
"children")) {
237 hint = Math.max(hint, item.children[0].knownItemsImplicitWidth);
242 Layout.preferredHeight: 2
265 function effectiveLayout(item:
Item): int {
269 const verticalAlignment =
270 item.Kirigami.FormData.labelAlignment !== 0
271 ? item.Kirigami.FormData.labelAlignment
274 if (item.Kirigami.FormData.isSection) {
275 return Qt.AlignHCenter;
278 return Qt.AlignRight | verticalAlignment;
280 return Qt.AlignLeft |
Qt.AlignBottom;
287 function effectiveTextLayout(item:
Item): int {
291 if (root.wideMode && !item.Kirigami.FormData.isSection) {
292 return item.Kirigami.FormData.labelAlignment !== 0 ? item.Kirigami.FormData.labelAlignment : Text.AlignVCenter;
294 return Text.AlignBottom;
302 const __items = root.children;
304 for (let i = 2; i < __items.length; ++i) {
305 const item = __items[i];
308 if (lay.knownItems.indexOf(item) !== -1 || item instanceof Repeater) {
311 lay.knownItems.push(item);
313 const itemContainer = itemComponent.createObject(temp, { item });
316 if (item.Kirigami.FormData.label.length > 0 && item.Kirigami.FormData.isSection) {
317 placeHolderComponent.createObject(lay, { item });
320 const buddy = buddyComponent.createObject(lay, { item, index: i - 2 });
322 itemContainer.parent = lay;
323 lay.buddies.push(buddy);
325 lay.knownItemsChanged();
326 lay.buddiesChanged();
327 hintCompression.triggered();
331 onChildrenChanged: relayoutTimer.restart();
340 enabled: item?.
enabled ??
false
341 visible: item?.visible ??
false
344 implicitWidth: item !== null ? Math.max(item.implicitWidth, 1) : 0
345 implicitHeight: item !== null ? Math.max(item.implicitHeight, 1) : 0
346 Layout.preferredWidth: item !== null ? Math.max(1, item.Layout.preferredWidth > 0 ? item.Layout.preferredWidth : Math.ceil(item.implicitWidth)) : 0
347 Layout.preferredHeight: item !== null ? Math.max(1, item.Layout.preferredHeight > 0 ? item.Layout.preferredHeight : Math.ceil(item.implicitHeight)) : 0
349 Layout.minimumWidth: item?.Layout.minimumWidth ?? 0
350 Layout.minimumHeight: item?.Layout.minimumHeight ?? 0
352 Layout.maximumWidth: item?.Layout.maximumWidth ?? 0
353 Layout.maximumHeight: item?.Layout.maximumHeight ?? 0
355 Layout.alignment:
Qt.AlignLeft |
Qt.AlignVCenter
356 Layout.fillWidth: item !== null && (item instanceof TextInput || item.Layout.fillWidth || item.Kirigami.FormData.isSection)
357 Layout.columnSpan: item?.Kirigami.FormData.isSection ? lay.columns : 1
363 onXChanged:
if (item !== null) { item.x = x + lay.x; }
365 onYChanged:
if (item !== null) { item.y = y + lay.y; }
366 onWidthChanged:
if (item !== null) { item.width = width; }
367 Component.onCompleted: item.
x = x + lay.x;
370 function onXChanged(): void {
371 if (container.item !== null) {
372 container.item.x = container.x + lay.x;
379 id: placeHolderComponent
383 enabled: item?.
enabled ??
false
384 visible: item?.visible ??
false
386 width: Kirigami.Units.smallSpacing
387 height: Kirigami.Units.smallSpacing
388 Layout.topMargin: item?.height > 0 ? Kirigami.Units.smallSpacing : 0
405 const buddy = item?.Kirigami.FormData.buddyFor;
407 return buddy.enabled;
409 return item?.enabled ??
false;
412 visible: (item?.visible && (root.wideMode || text.length > 0)) ??
false
413 Kirigami.MnemonicData.
enabled: {
414 const buddy = item?.Kirigami.FormData.buddyFor;
415 if (buddy && buddy.enabled && buddy.visible && buddy.activeFocusOnTab) {
417 const buddyMnemonic = buddy.Kirigami.MnemonicData;
418 return !buddyMnemonic.label || !buddyMnemonic.enabled;
423 Kirigami.MnemonicData.controlType: Kirigami.MnemonicData.FormLabel
424 Kirigami.MnemonicData.label: item?.Kirigami.FormData.label ??
""
425 text: Kirigami.MnemonicData.richTextLabel
426 Accessible.name: Kirigami.MnemonicData.plainTextLabel
427 type: item?.Kirigami.FormData.isSection ? Kirigami.Heading.Type.Primary : Kirigami.Heading.Type.Normal
429 level: item?.Kirigami.FormData.isSection ? 3 : 5
431 Layout.columnSpan: item?.Kirigami.FormData.isSection ? lay.columns : 1
432 Layout.preferredHeight: {
436 if (item.Kirigami.FormData.label.length > 0) {
439 if (item.Kirigami.FormData.isSection && labelItem.index !== 0) {
440 return implicitHeight + Kirigami.Units.largeSpacing * 2;
442 else if (root.wideMode && !(item.Kirigami.FormData.buddyFor instanceof TextEdit)) {
443 return Math.max(implicitHeight, item.Kirigami.FormData.buddyFor.height)
445 return implicitHeight;
447 return Kirigami.Units.smallSpacing;
450 Layout.alignment: temp.effectiveLayout(item)
451 verticalAlignment: temp.effectiveTextLayout(item)
453 Layout.fillWidth: !root.wideMode
460 if (root.wideMode && item.Kirigami.FormData.buddyFor.parent !== root) {
461 return item.Kirigami.FormData.buddyFor.y;
463 if (index === 0 || root.wideMode) {
466 return Kirigami.Units.largeSpacing * 2;
474 sequence: labelItem.Kirigami.MnemonicData.sequence
476 const buddy = labelItem.item.Kirigami.FormData.buddyFor;
478 const buttonBuddy = buddy as T.AbstractButton;
481 if (buttonBuddy && buttonBuddy.animateClick) {
482 buttonBuddy.animateClick();
484 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)