Warning, /frameworks/kirigami/autotests/tst_headerfooterlayout.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2023 Marco Martin <mart@kde.org> 0003 * SPDX-FileCopyrightText: 2023 ivan tkachenko <me@ratijas.tk> 0004 * 0005 * SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 import QtQuick 0009 import QtQuick.Controls as QQC2 0010 import QtQuick.Layouts 0011 import QtTest 0012 import org.kde.kirigami as Kirigami 0013 0014 TestCase { 0015 id: testCase 0016 0017 name: "HeaderFooterLayoutTests" 0018 when: windowShown 0019 0020 width: 300 0021 height: 300 0022 visible: true 0023 0024 Component { 0025 id: implicitSizeComponent 0026 Kirigami.HeaderFooterLayout { 0027 header: Rectangle { 0028 color: "red" 0029 implicitHeight: 30 0030 implicitWidth: 100 0031 } 0032 contentItem: Rectangle { 0033 color: "green" 0034 implicitHeight: 40 0035 implicitWidth: 110 0036 } 0037 footer: Rectangle { 0038 color: "blue" 0039 implicitHeight: 25 0040 implicitWidth: 120 0041 } 0042 } 0043 } 0044 0045 Component { 0046 id: nestedLayoutComponent 0047 ColumnLayout { 0048 Rectangle { 0049 color: "red" 0050 Layout.fillWidth: true 0051 Layout.minimumHeight: 50 0052 } 0053 Kirigami.HeaderFooterLayout { 0054 Layout.fillWidth: true 0055 Layout.fillHeight: true 0056 header: Rectangle { 0057 color: "red" 0058 implicitHeight: 30 0059 implicitWidth: 100 0060 } 0061 contentItem: Rectangle { 0062 color: "green" 0063 implicitHeight: 40 0064 implicitWidth: 110 0065 } 0066 footer: Rectangle { 0067 color: "blue" 0068 implicitHeight: 25 0069 implicitWidth: 120 0070 } 0071 } 0072 } 0073 } 0074 0075 function test_implicit_sizes_standalone_layout() { 0076 const layout = createTemporaryObject(implicitSizeComponent, this); 0077 verify(layout); 0078 0079 compare(layout.implicitHeight, 95); 0080 compare(layout.implicitWidth, 120); 0081 compare(layout.height, 95); 0082 compare(layout.width, 120); 0083 0084 compare(layout.header.width, 120); 0085 compare(layout.header.height, 30); 0086 0087 compare(layout.footer.width, 120); 0088 compare(layout.footer.height, 25); 0089 0090 compare(layout.contentItem.width, 120); 0091 compare(layout.contentItem.height, 40); 0092 0093 layout.height = 130; 0094 verify(waitForItemPolished(layout)); 0095 0096 // Header and footer don't change 0097 compare(layout.header.width, 120); 0098 compare(layout.header.height, 30); 0099 0100 compare(layout.footer.width, 120); 0101 compare(layout.footer.height, 25); 0102 0103 // ContentItem stretchesvertically 0104 compare(layout.contentItem.width, 120); 0105 compare(layout.contentItem.height, 75); 0106 0107 layout.width = 200; 0108 verify(waitForItemPolished(layout)); 0109 // Everything stretched only horizontally 0110 compare(layout.header.width, 200); 0111 compare(layout.header.height, 30); 0112 0113 compare(layout.footer.width, 200); 0114 compare(layout.footer.height, 25); 0115 0116 compare(layout.contentItem.width, 200); 0117 compare(layout.contentItem.height, 75); 0118 0119 // change header implicit size 0120 layout.header.implicitHeight = 40; 0121 verify(waitForItemPolished(layout)); 0122 compare(layout.implicitHeight, 105); 0123 compare(layout.implicitWidth, 120); 0124 compare(layout.height, 130); 0125 compare(layout.width, 200); 0126 0127 compare(layout.header.width, 200); 0128 compare(layout.header.height, 40); 0129 0130 compare(layout.footer.width, 200); 0131 compare(layout.footer.height, 25); 0132 0133 compare(layout.contentItem.width, 200); 0134 compare(layout.contentItem.height, 65); 0135 0136 // hide header 0137 layout.header.visible = false; 0138 verify(waitForItemPolished(layout)); 0139 compare(layout.implicitHeight, 65); 0140 compare(layout.implicitWidth, 120); 0141 compare(layout.height, 130); 0142 compare(layout.width, 200); 0143 0144 compare(layout.header.width, 200); 0145 compare(layout.header.height, 40); 0146 0147 compare(layout.footer.width, 200); 0148 compare(layout.footer.height, 25); 0149 0150 compare(layout.contentItem.width, 200); 0151 compare(layout.contentItem.height, 105); 0152 0153 // force polish right now 0154 verify(!isPolishScheduled(layout)); 0155 layout.header.visible = true; 0156 verify(isPolishScheduled(layout)); 0157 compare(layout.implicitHeight, 65); 0158 layout.forceLayout(); 0159 compare(layout.implicitHeight, 105); 0160 verify(waitForItemPolished(layout)); 0161 compare(layout.implicitHeight, 105); 0162 } 0163 0164 function test_implicit_sizes_nested_layout() { 0165 const columnLayout = createTemporaryObject(nestedLayoutComponent, this); 0166 verify(columnLayout); 0167 const headerFooterLayout = columnLayout.children[1]; 0168 verify(waitForRendering(columnLayout)); 0169 verify(headerFooterLayout instanceof Kirigami.HeaderFooterLayout); 0170 0171 compare(columnLayout.implicitHeight, 95 + 50 + columnLayout.spacing); 0172 compare(columnLayout.implicitHeight, columnLayout.height); 0173 0174 compare(headerFooterLayout.implicitHeight, 95); 0175 compare(headerFooterLayout.implicitWidth, 120); 0176 compare(headerFooterLayout.height, 95); 0177 compare(headerFooterLayout.width, 120); 0178 0179 compare(headerFooterLayout.header.width, 120); 0180 compare(headerFooterLayout.header.height, 30); 0181 0182 compare(headerFooterLayout.footer.width, 120); 0183 compare(headerFooterLayout.footer.height, 25); 0184 0185 compare(headerFooterLayout.contentItem.width, 120); 0186 compare(headerFooterLayout.contentItem.height, 40); 0187 0188 columnLayout.height = 200; 0189 verify(waitForItemPolished(columnLayout)); 0190 verify(waitForItemPolished(headerFooterLayout)); 0191 0192 // headerFooterLayout should have stretched 0193 compare(headerFooterLayout.implicitHeight, 95); 0194 compare(headerFooterLayout.implicitWidth, 120); 0195 compare(headerFooterLayout.height, 145); 0196 compare(headerFooterLayout.width, 120); 0197 0198 compare(headerFooterLayout.header.width, 120); 0199 compare(headerFooterLayout.header.height, 30); 0200 0201 compare(headerFooterLayout.footer.width, 120); 0202 compare(headerFooterLayout.footer.height, 25); 0203 0204 compare(headerFooterLayout.contentItem.width, 120); 0205 compare(headerFooterLayout.contentItem.height, 90); 0206 0207 // change header implicit size 0208 headerFooterLayout.header.implicitHeight = 40; 0209 verify(waitForItemPolished(columnLayout)); 0210 verify(waitForItemPolished(headerFooterLayout)); 0211 0212 compare(headerFooterLayout.implicitHeight, 105); 0213 compare(headerFooterLayout.implicitWidth, 120); 0214 compare(headerFooterLayout.height, 145); 0215 compare(headerFooterLayout.width, 120); 0216 0217 compare(headerFooterLayout.header.width, 120); 0218 compare(headerFooterLayout.header.height, 40); 0219 0220 compare(headerFooterLayout.footer.width, 120); 0221 compare(headerFooterLayout.footer.height, 25); 0222 0223 compare(headerFooterLayout.contentItem.width, 120); 0224 compare(headerFooterLayout.contentItem.height, 80); 0225 0226 // hide header 0227 headerFooterLayout.header.visible = false; 0228 verify(waitForItemPolished(columnLayout)); 0229 verify(waitForItemPolished(headerFooterLayout)); 0230 0231 compare(headerFooterLayout.implicitHeight, 65); 0232 compare(headerFooterLayout.implicitWidth, 120); 0233 compare(headerFooterLayout.height, 145); 0234 compare(headerFooterLayout.width, 120); 0235 0236 compare(headerFooterLayout.header.width, 120); 0237 compare(headerFooterLayout.header.height, 40); 0238 0239 compare(headerFooterLayout.footer.width, 120); 0240 compare(headerFooterLayout.footer.height, 25); 0241 0242 compare(headerFooterLayout.contentItem.width, 120); 0243 compare(headerFooterLayout.contentItem.height, 120); 0244 } 0245 0246 function test_disconnect_old_items() { 0247 const layout = createTemporaryObject(implicitSizeComponent, this); 0248 verify(layout); 0249 0250 verify(isPolishScheduled(layout)); 0251 verify(waitForItemPolished(layout)); 0252 0253 for (const partName of ["header", "contentItem", "footer"]) { 0254 const part = layout[partName]; 0255 0256 part.implicitHeight = 10; 0257 0258 verify(isPolishScheduled(layout)); 0259 verify(waitForItemPolished(layout)); 0260 0261 layout[partName] = null; 0262 0263 verify(isPolishScheduled(layout)); 0264 verify(waitForItemPolished(layout)); 0265 0266 part.implicitHeight = 20; 0267 0268 verify(!isPolishScheduled(layout)); 0269 } 0270 0271 } 0272 }