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 restoreMode: Binding.RestoreBinding
151 value: root.implicitWidth
152 restoreMode: Binding.RestoreBinding
155 horizontalCenter: root.wideMode ? root.horizontalCenter : undefined
156 left: root.wideMode ? undefined : root.left
159 property var reverseTwins: []
160 property var knownItems: []
161 property var buddies: []
162 property int knownItemsImplicitWidth: {
164 for (
const item of knownItems) {
165 if (typeof item.Layout ===
"undefined") {
175 const actualWidth = item.Layout.preferredWidth > 0
176 ? item.Layout.preferredWidth
177 : item.implicitWidth;
179 hint = Math.max(hint, item.Layout.minimumWidth, Math.min(actualWidth, item.Layout.maximumWidth));
183 property int buddiesImplicitWidth: {
186 for (
const buddy of buddies) {
187 if (buddy.visible && buddy.item !== null && !buddy.item.Kirigami.FormData.isSection) {
188 hint = Math.max(hint, buddy.implicitWidth);
193 readonly
property var actualTwinFormLayouts: {
195 const list = lay.reverseTwins.slice();
196 for (
const parentLay of root.twinFormLayouts) {
197 if (!parentLay || !parentLay.hasOwnProperty(
"children")) {
200 list.push(parentLay);
201 for (
const childLay of parentLay.children[0].reverseTwins) {
202 if (childLay && !(childLay in list)) {
215 lay.wideImplicitWidth = lay.implicitWidth;
219 onImplicitWidthChanged: hintCompression.restart();
223 Layout.preferredWidth: {
224 let
hint = lay.buddiesImplicitWidth;
225 for (
const item of lay.actualTwinFormLayouts) {
226 if (item && item.hasOwnProperty(
"children")) {
227 hint = Math.max(hint, item.children[0].buddiesImplicitWidth);
232 Layout.preferredHeight: 2
235 Layout.preferredWidth: {
236 let
hint = Math.min(root.width, lay.knownItemsImplicitWidth);
237 for (
const item of lay.actualTwinFormLayouts) {
238 if (item.hasOwnProperty(
"children")) {
239 hint = Math.max(hint, item.children[0].knownItemsImplicitWidth);
244 Layout.preferredHeight: 2
267 function effectiveLayout(item:
Item): int {
271 const verticalAlignment =
272 item.Kirigami.FormData.labelAlignment !== 0
273 ? item.Kirigami.FormData.labelAlignment
276 if (item.Kirigami.FormData.isSection) {
277 return Qt.AlignHCenter;
280 return Qt.AlignRight | verticalAlignment;
282 return Qt.AlignLeft |
Qt.AlignBottom;
289 function effectiveTextLayout(item:
Item): int {
293 if (root.wideMode && !item.Kirigami.FormData.isSection) {
294 return item.Kirigami.FormData.labelAlignment !== 0 ? item.Kirigami.FormData.labelAlignment : Text.AlignVCenter;
296 return Text.AlignBottom;
304 const __items = root.children;
306 for (let i = 2; i < __items.length; ++i) {
307 const item = __items[i];
310 if (lay.knownItems.indexOf(item) !== -1 || item instanceof Repeater) {
313 lay.knownItems.push(item);
315 const itemContainer = itemComponent.createObject(temp, { item });
318 if (item.Kirigami.FormData.label.length > 0 && item.Kirigami.FormData.isSection) {
319 placeHolderComponent.createObject(lay, { item });
322 const buddy = buddyComponent.createObject(lay, { item, index: i - 2 });
324 itemContainer.parent = lay;
325 lay.buddies.push(buddy);
327 lay.knownItemsChanged();
328 lay.buddiesChanged();
329 hintCompression.triggered();
333 onChildrenChanged: relayoutTimer.restart();
342 enabled: item?.
enabled ??
false
343 visible: item?.visible ??
false
346 implicitWidth: item !== null ? Math.max(item.implicitWidth, 1) : 0
347 implicitHeight: item !== null ? Math.max(item.implicitHeight, 1) : 0
348 Layout.preferredWidth: item !== null ? Math.max(1, item.Layout.preferredWidth > 0 ? item.Layout.preferredWidth : Math.ceil(item.implicitWidth)) : 0
349 Layout.preferredHeight: item !== null ? Math.max(1, item.Layout.preferredHeight > 0 ? item.Layout.preferredHeight : Math.ceil(item.implicitHeight)) : 0
351 Layout.minimumWidth: item?.Layout.minimumWidth ?? 0
352 Layout.minimumHeight: item?.Layout.minimumHeight ?? 0
354 Layout.maximumWidth: item?.Layout.maximumWidth ?? 0
355 Layout.maximumHeight: item?.Layout.maximumHeight ?? 0
357 Layout.alignment:
Qt.AlignLeft |
Qt.AlignVCenter
358 Layout.fillWidth: item !== null && (item instanceof TextInput || item.Layout.fillWidth || item.Kirigami.FormData.isSection)
359 Layout.columnSpan: item?.Kirigami.FormData.isSection ? lay.columns : 1
365 onXChanged:
if (item !== null) { item.x = x + lay.x; }
367 onYChanged:
if (item !== null) { item.y = y + lay.y; }
368 onWidthChanged:
if (item !== null) { item.width = width; }
369 Component.onCompleted: item.
x = x + lay.x;
372 function onXChanged(): void {
373 if (container.item !== null) {
374 container.item.x = container.x + lay.x;
381 id: placeHolderComponent
385 enabled: item?.
enabled ??
false
386 visible: item?.visible ??
false
388 width: Kirigami.Units.smallSpacing
389 height: Kirigami.Units.smallSpacing
390 Layout.topMargin: item?.height > 0 ? Kirigami.Units.smallSpacing : 0
407 const buddy = item?.Kirigami.FormData.buddyFor;
409 return buddy.enabled;
411 return item?.enabled ??
false;
414 visible: (item?.visible && (root.wideMode || text.length > 0)) ??
false
415 Kirigami.MnemonicData.
enabled: {
416 const buddy = item?.Kirigami.FormData.buddyFor;
417 if (buddy && buddy.enabled && buddy.visible && buddy.activeFocusOnTab) {
419 const buddyMnemonic = buddy.Kirigami.MnemonicData;
420 return !buddyMnemonic.label || !buddyMnemonic.enabled;
425 Kirigami.MnemonicData.controlType: Kirigami.MnemonicData.FormLabel
426 Kirigami.MnemonicData.label: item?.Kirigami.FormData.label ??
""
427 text: Kirigami.MnemonicData.richTextLabel
428 Accessible.name: Kirigami.MnemonicData.plainTextLabel
429 type: item?.Kirigami.FormData.isSection ? Kirigami.Heading.Type.Primary : Kirigami.Heading.Type.Normal
431 level: item?.Kirigami.FormData.isSection ? 3 : 5
433 Layout.columnSpan: item?.Kirigami.FormData.isSection ? lay.columns : 1
434 Layout.preferredHeight: {
438 if (item.Kirigami.FormData.label.length > 0) {
441 if (item.Kirigami.FormData.isSection && labelItem.index !== 0) {
442 return implicitHeight + Kirigami.Units.largeSpacing * 2;
444 else if (root.wideMode && !(item.Kirigami.FormData.buddyFor instanceof TextEdit)) {
445 return Math.max(implicitHeight, item.Kirigami.FormData.buddyFor.height)
447 return implicitHeight;
449 return Kirigami.Units.smallSpacing;
452 Layout.alignment: temp.effectiveLayout(item)
453 verticalAlignment: temp.effectiveTextLayout(item)
455 Layout.fillWidth: !root.wideMode
462 if (root.wideMode && item.Kirigami.FormData.buddyFor.parent !== root) {
463 return item.Kirigami.FormData.buddyFor.y;
465 if (index === 0 || root.wideMode) {
468 return Kirigami.Units.largeSpacing * 2;
476 sequence: labelItem.Kirigami.MnemonicData.sequence
478 const buddy = labelItem.item.Kirigami.FormData.buddyFor;
480 const buttonBuddy = buddy as T.AbstractButton;
483 if (buttonBuddy && buttonBuddy.animateClick) {
484 buttonBuddy.animateClick();
486 buddy.forceActiveFocus(
Qt.ShortcutFocusReason);
QAction * hint(const QObject *recvr, const char *slot, QObject *parent)
QStringView level(QStringView ifopt)
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
QTextStream & left(QTextStream &stream)