From b286809ea590d51223402d9424c532fc44caac34 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 13 Sep 2016 13:15:54 +0200 Subject: [PATCH] fix(ExclusiveButtons): supports unlimited buttons --- tests/ui/components/form/ExclusiveButtons.qml | 52 +++++++------------ tests/ui/views/mainWindow/contacts.qml | 6 ++- 2 files changed, 23 insertions(+), 35 deletions(-) diff --git a/tests/ui/components/form/ExclusiveButtons.qml b/tests/ui/components/form/ExclusiveButtons.qml index e039d71d3..b8e06660f 100644 --- a/tests/ui/components/form/ExclusiveButtons.qml +++ b/tests/ui/components/form/ExclusiveButtons.qml @@ -3,45 +3,31 @@ import QtQuick 2.7 // =================================================================== Row { - property alias text1: button1.text - property alias text2: button2.text - - property bool button1IsSelected: true + property int selectedButton: 0 + property variant texts signal buttonChanged (int button) spacing: 8 - SmallButton { - anchors.verticalCenter: parent.verticalCenter - backgroundColor: button1IsSelected - ? '#8E8E8E' - : (button1.down - ? '#FE5E00' - : '#D1D1D1' - ) - id: button1 - onClicked: { - if (!button1IsSelected) { - button1IsSelected = true - buttonChanged(1) - } - } - } + Repeater { + model: texts + SmallButton { + anchors.verticalCenter: parent.verticalCenter + backgroundColor: selectedButton === index + ? '#8E8E8E' + : (button.down + ? '#FE5E00' + : '#D1D1D1' + ) + id: button + text: modelData - SmallButton { - anchors.verticalCenter: parent.verticalCenter - backgroundColor: !button1IsSelected - ? '#8E8E8E' - : (button2.down - ? '#FE5E00' - : '#D1D1D1' - ) - id: button2 - onClicked: { - if (button1IsSelected) { - button1IsSelected = false - buttonChanged(2) + onClicked: { + if (selectedButton !== index) { + selectedButton = index + buttonChanged(index) + } } } } diff --git a/tests/ui/views/mainWindow/contacts.qml b/tests/ui/views/mainWindow/contacts.qml index db9e119a2..0cbd2b7c6 100644 --- a/tests/ui/views/mainWindow/contacts.qml +++ b/tests/ui/views/mainWindow/contacts.qml @@ -35,8 +35,10 @@ ColumnLayout { ExclusiveButtons { Layout.preferredHeight: parent.height - text1: qsTr('selectAllContacts') - text2: qsTr('selectConnectedContacts') + texts: [ + qsTr('selectAllContacts'), + qsTr('selectConnectedContacts') + ] } LightButton {