2015-09-20 14:01:51 +02:00
|
|
|
import QtQuick 2.5
|
2015-08-07 00:48:05 +02:00
|
|
|
import QtQuick.Controls 1.2
|
2015-09-20 14:01:51 +02:00
|
|
|
import QtGraphicalEffects 1.0
|
|
|
|
|
import QtQuick.Layouts 1.1
|
2015-08-13 15:39:24 +02:00
|
|
|
import QtQuick.Controls.Styles 1.2
|
|
|
|
|
import "../js/colors.js" as GlobalColors
|
2015-08-17 14:52:46 +02:00
|
|
|
import "styles"
|
2015-08-07 00:48:05 +02:00
|
|
|
|
2015-08-21 01:38:35 +02:00
|
|
|
Item {
|
|
|
|
|
id: root
|
2015-08-07 00:48:05 +02:00
|
|
|
anchors.fill: parent
|
|
|
|
|
|
2015-09-20 14:01:51 +02:00
|
|
|
property ListModel internalValuesList: ListModel {}
|
2015-08-13 15:39:24 +02:00
|
|
|
property string valueFromParent
|
2015-08-21 01:38:35 +02:00
|
|
|
property string titleString
|
2015-08-13 15:39:24 +02:00
|
|
|
property string returnValue
|
|
|
|
|
property bool valueIsIndex
|
2015-08-07 00:48:05 +02:00
|
|
|
|
2015-08-21 01:38:35 +02:00
|
|
|
signal accepted
|
|
|
|
|
|
2015-08-13 15:39:24 +02:00
|
|
|
function show(title, list, vl, valueIndex) {
|
|
|
|
|
titleString = title;
|
|
|
|
|
valueFromParent = vl;
|
2015-08-17 14:52:46 +02:00
|
|
|
returnValue = vl; // <-- initial the returnValue with the preselection to prevent a NULL return when pressing Cancel
|
2015-08-13 15:39:24 +02:00
|
|
|
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]});
|
2015-08-13 15:39:24 +02:00
|
|
|
}
|
2015-08-21 01:38:35 +02:00
|
|
|
mySelector.show()
|
2015-08-07 00:48:05 +02:00
|
|
|
}
|
|
|
|
|
|
2015-08-13 15:39:24 +02:00
|
|
|
function selected(newString, index) {
|
|
|
|
|
if(valueIsIndex) {
|
|
|
|
|
returnValue = index.toString();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
returnValue = newString
|
|
|
|
|
}
|
2015-08-21 01:38:35 +02:00
|
|
|
mySelector.hide()
|
|
|
|
|
root.accepted()
|
2015-08-07 00:48:05 +02:00
|
|
|
}
|
|
|
|
|
|
2015-08-21 01:38:35 +02:00
|
|
|
MyAbstractSelector {
|
|
|
|
|
id: mySelector
|
|
|
|
|
titleText: titleString
|
|
|
|
|
button1Text: qsTr("CANCEL")
|
|
|
|
|
onButton1Clicked: hide()
|
2015-08-07 00:48:05 +02:00
|
|
|
|
2015-08-21 01:38:35 +02:00
|
|
|
container: ScrollView {
|
2015-09-20 14:01:51 +02:00
|
|
|
id: scrollView
|
2015-08-21 01:38:35 +02:00
|
|
|
anchors.fill:parent
|
2015-09-20 14:01:51 +02:00
|
|
|
property int yOfCheckedRadioButton: 0
|
2015-08-21 01:38:35 +02:00
|
|
|
ListView {
|
2015-09-20 14:01:51 +02:00
|
|
|
id:listView
|
2015-08-21 01:38:35 +02:00
|
|
|
anchors.fill: parent
|
|
|
|
|
spacing: Math.round(appWindow.height*0.05)
|
2015-09-20 14:01:51 +02:00
|
|
|
model: internalValuesList
|
2015-08-21 01:38:35 +02:00
|
|
|
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)
|
2015-08-07 00:48:05 +02:00
|
|
|
onClicked: {
|
2015-09-20 14:01:51 +02:00
|
|
|
root.selected(value, index)
|
2015-08-21 01:38:35 +02:00
|
|
|
}
|
|
|
|
|
style: MyRadioButtonStyle {
|
|
|
|
|
myRadioBtn: radioBtn
|
2015-09-20 14:01:51 +02:00
|
|
|
labelString: value
|
2015-08-07 00:48:05 +02:00
|
|
|
}
|
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
|
2015-08-07 00:48:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|