aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/controls/data/tst_button.qml
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2017-03-01 13:06:44 +0100
committerMitch Curtis <mitch.curtis@qt.io>2017-03-28 06:17:35 +0000
commitb44048ae27bd916d0eaa1e7d6a5456488ff76f29 (patch)
treebb00c7612f6baee2dbe0697205a52fd2792e9ee8 /tests/auto/controls/data/tst_button.qml
parenta7d9818dd414565cdcc4f4c9415f67735d146c68 (diff)
AbstractButton: add display property
This property allows control over how icons and text are displayed within buttons, without having to implement custom delegates. It is also necessary for the upcoming Action type. [ChangeLog][Controls][AbstractButton] Added display property to allow control over how icons and text are displayed within buttons, without having to implement custom delegates. Task-number: QTBUG-49820 Change-Id: Ie924e2c54ed49961fd40129999875c8175606ecd Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'tests/auto/controls/data/tst_button.qml')
-rw-r--r--tests/auto/controls/data/tst_button.qml52
1 files changed, 51 insertions, 1 deletions
diff --git a/tests/auto/controls/data/tst_button.qml b/tests/auto/controls/data/tst_button.qml
index e3081354..d0f8bbf3 100644
--- a/tests/auto/controls/data/tst_button.qml
+++ b/tests/auto/controls/data/tst_button.qml
@@ -50,7 +50,7 @@
import QtQuick 2.2
import QtTest 1.0
-import QtQuick.Controls 2.2
+import QtQuick.Controls 2.3
TestCase {
id: testCase
@@ -448,4 +448,54 @@ TestCase {
// The implicitWidth of the Button itself should, therefore, also never include spacing while no icon is set.
compare(control.implicitWidth, control.contentItem.text.implicitWidth + control.leftPadding + control.rightPadding)
}
+
+ function test_display_data() {
+ return [
+ { "tag": "IconOnly", display: Button.IconOnly },
+ { "tag": "TextOnly", display: Button.TextOnly },
+ { "tag": "TextBesideIcon", display: Button.TextBesideIcon },
+ { "tag": "IconOnly, mirrored", display: Button.IconOnly, mirrored: true },
+ { "tag": "TextOnly, mirrored", display: Button.TextOnly, mirrored: true },
+ { "tag": "TextBesideIcon, mirrored", display: Button.TextBesideIcon, mirrored: true }
+ ]
+ }
+
+ function test_display(data) {
+ var control = createTemporaryObject(button, testCase, {
+ text: "Button",
+ display: data.display,
+ "icon.source": "qrc:/qt-project.org/imports/QtQuick/Controls.2/images/check.png",
+ "LayoutMirroring.enabled": !!data.mirrored
+ })
+ verify(control)
+ verify(control.icon.source.length > 0)
+
+ var iconImage = control.contentItem.icon
+ verify(iconImage)
+ verify(iconImage.hasOwnProperty("name"))
+ var text = control.contentItem.text
+ verify(text)
+ verify(text.hasOwnProperty("text"))
+
+ switch (control.display) {
+ case Button.IconOnly:
+ compare(iconImage.visible, true)
+ compare(text.visible, false)
+ compare(iconImage.x, (control.availableWidth - iconImage.width) / 2)
+ break;
+ case Button.TextOnly:
+ compare(iconImage.visible, false)
+ compare(text.visible, true)
+ compare(text.x, (control.availableWidth - text.width) / 2)
+ break;
+ case Button.TextBesideIcon:
+ compare(iconImage.visible, true)
+ compare(text.visible, true)
+ if (control.mirrored)
+ verify(text.x < iconImage.x)
+ else
+ verify(iconImage.x < text.x)
+ break;
+ }
+ }
}