Files
pokerth/src/gui/qml/components/MyComboBoxSelector.qml
T

91 lines
3.0 KiB
QML
Raw Normal View History

2015-09-20 14:01:51 +02:00
import QtQuick 2.5
import QtQuick.Controls 1.2
2015-09-20 14:01:51 +02:00
import QtGraphicalEffects 1.0
import QtQuick.Layouts 1.1
import QtQuick.Controls.Styles 1.2
import "../js/colors.js" as GlobalColors
import "styles"
Item {
id: root
anchors.fill: parent
2015-09-20 14:01:51 +02:00
property ListModel internalValuesList: ListModel {}
property string valueFromParent
property string titleString
property string returnValue
property bool valueIsIndex
signal accepted
function show(title, list, vl, valueIndex) {
titleString = title;
valueFromParent = vl;
returnValue = vl; // <-- initial the returnValue with the preselection to prevent a NULL return when pressing Cancel
valueIsIndex = valueIndex;
//fill the model
2015-09-20 14:01:51 +02:00
internalValuesList.clear();
for (var i=0; i < list.length; i++) {
internalValuesList.append({"value": list[i]});
}
mySelector.show()
}
function selected(newString, index) {
if(valueIsIndex) {
returnValue = index.toString();
}
else {
returnValue = newString
}
mySelector.hide()
root.accepted()
}
MyAbstractSelector {
id: mySelector
titleText: titleString
button1Text: qsTr("CANCEL")
onButton1Clicked: hide()
container: ScrollView {
2015-09-20 14:01:51 +02:00
id: scrollView
anchors.fill:parent
2015-09-20 14:01:51 +02:00
property int yOfCheckedRadioButton: 0
ListView {
2015-09-20 14:01:51 +02:00
id:listView
anchors.fill: parent
spacing: Math.round(appWindow.height*0.05)
2015-09-20 14:01:51 +02:00
model: internalValuesList
delegate: RadioButton {
id: radioBtn
//check of value is index type and do the corresponding checked? test
2015-09-20 14:01:51 +02:00
checked: valueIsIndex ? (parseInt(valueFromParent) == index ? true : false) : (valueFromParent == value ? true : false)
onClicked: {
2015-09-20 14:01:51 +02:00
root.selected(value, index)
}
style: MyRadioButtonStyle {
myRadioBtn: radioBtn
2015-09-20 14:01:51 +02:00
labelString: value
}
2015-09-20 14:01:51 +02:00
Component.onCompleted: {
//set the position of the checked RadioButton to scroll to it later onContentHeightChange
if(checked) {
var checkedRadioBtnPositionY = Math.round((radioBtn.height + listView.spacing) * index - radioBtn.height * 1.5)
if( checkedRadioBtnPositionY > 0)
scrollView.yOfCheckedRadioButton = checkedRadioBtnPositionY
else
scrollView.yOfCheckedRadioButton = 0
}
}
}
onContentHeightChanged: {
//scroll to the checked RadioButton
contentY = scrollView.yOfCheckedRadioButton
}
}
}
}
}