diff --git a/src/gui/qml/components/MyBlindsRaiseIntervalSelector.qml b/src/gui/qml/components/MyBlindsRaiseIntervalSelector.qml index 08c4b802..71b56caf 100644 --- a/src/gui/qml/components/MyBlindsRaiseIntervalSelector.qml +++ b/src/gui/qml/components/MyBlindsRaiseIntervalSelector.qml @@ -3,6 +3,7 @@ import QtQuick.Layouts 1.1 import QtQuick.Controls 1.2 import QtQuick.Controls.Styles 1.2 import "../js/colors.js" as GlobalColors +import "../js/tools.js" as GlobalTools import "styles/" Rectangle { @@ -20,24 +21,34 @@ Rectangle { property int raiseOnHandsMaximum: 99 property int raiseOnMinutesMinimum: 1 property int raiseOnMinutesMaximum: 99 + property bool ready: false function show(type, hands, minutes) { raiseOnHandsType = type; raiseOnHandsInterval = hands; raiseOnMinutesInterval = minutes; visible = true; - } + + if(raiseOnHandsType == "1") { + textFieldHandsInterval.focus = true; + radioBtnRaiseOnHands.checked = true; + } + else { + textFieldMinutesInterval.focus = true; + radioBtnRaiseOnMinutes.checked = true; + } + } function reject() { visible = false; - } + } function selected(handsType, handsInterval, minutesInterval) { raiseOnHandsType = handsType; raiseOnHandsInterval = handsInterval; raiseOnMinutesInterval = minutesInterval; visible = false; - } + } MouseArea { //set empty MouseArea to prevent the background to be clicked @@ -80,37 +91,24 @@ Rectangle { RadioButton { id: radioBtnRaiseOnHands - checked: raiseOnHandsType ? true : false exclusiveGroup: raiseTypeGroup style: MyRadioButtonStyle { myRadioBtn: radioBtnRaiseOnHands; labelString: "Every" } - onCheckedChanged: checked ? textFieldHandsInterval.focus = true : textFieldHandsInterval.focus = false + onClicked: textFieldHandsInterval.focus = true; } TextField { id: textFieldHandsInterval width: appWindow.textFieldFontSize*2 - // validator: IntValidator{bottom: minValue; top: maxValue;} TODO: test validator in later QtVersions > 5.5.0 + validator: IntValidator{bottom: raiseOnHandsMinimum; top: raiseOnHandsMaximum;} text: raiseOnHandsInterval - focus: raiseOnHandsType ? true : false function correctValue() { - if(text != "") { - if(parseInt(text) > raiseOnHandsMaximum) text = raiseOnHandsMaximum - else if(parseInt(text) < raiseOnHandsMinimum) text = raiseOnHandsMinimum - else { - //remove leading "0000" - var temp = parseInt(text) - text = temp - } - } + text = GlobalTools.correctTextFieldIntegerValue(selector, text, raiseOnHandsMinimum); } - onFocusChanged: { - correctValue() - focus ? radioBtnRaiseOnHands.checked = true : radioBtnRaiseOnHands.checked = false - } - onEditingFinished: correctValue() + onFocusChanged: { if(selector.ready && !focus) correctValue(); } + onEditingFinished: { if(selector.ready) correctValue(); } style: MyTextFieldStyle { myTextField: textFieldHandsInterval @@ -126,37 +124,24 @@ Rectangle { spacing: appWindow.rowLayoutSpacing RadioButton { id: radioBtnRaiseOnMinutes - checked: raiseOnHandsType ? false : true exclusiveGroup: raiseTypeGroup style: MyRadioButtonStyle { myRadioBtn: radioBtnRaiseOnMinutes; labelString: "Every" } - onCheckedChanged: checked ? textFieldMinutesInterval.focus = true : textFieldMinutesInterval.focus = false + onClicked: textFieldMinutesInterval.focus = true; } - TextField { id: textFieldMinutesInterval - // validator: IntValidator{bottom: minValue; top: maxValue;} TODO: test validator in later QtVersions > 5.5.0 + validator: IntValidator{bottom: raiseOnMinutesMinimum; top: raiseOnMinutesMaximum;} text: raiseOnMinutesInterval width: appWindow.textFieldFontSize*2 - focus: raiseOnHandsType ? false : true function correctValue() { - if(text != "") { - if(parseInt(text) > raiseOnMinutesMaximum) text = raiseOnMinutesMaximum - else if(parseInt(text) < raiseOnMinutesMinimum) text = raiseOnMinutesMinimum - else { - //remove leading "0000" - var temp = parseInt(text) - text = temp - } - } + text = GlobalTools.correctTextFieldIntegerValue(selector, text, raiseOnMinutesMinimum); + } - onFocusChanged: { - correctValue(); - focus ? radioBtnRaiseOnMinutes.checked = true : radioBtnRaiseOnMinutes.checked = false - } - onEditingFinished: correctValue() + onFocusChanged: { if(selector.ready && !focus) correctValue(); } + onEditingFinished: { if(selector.ready) correctValue(); } style: MyTextFieldStyle { myTextField: textFieldMinutesInterval @@ -213,4 +198,5 @@ Rectangle { } } } + Component.onCompleted: ready = true; } diff --git a/src/gui/qml/components/MyListViewDelegateFactory.qml b/src/gui/qml/components/MyListViewDelegateFactory.qml index 63ecf1bd..8b243075 100644 --- a/src/gui/qml/components/MyListViewDelegateFactory.qml +++ b/src/gui/qml/components/MyListViewDelegateFactory.qml @@ -134,8 +134,8 @@ Item { id: mouse anchors.fill: parent onClicked: { - //call selector overlay and set inital values - mySpinBoxSelector.show(myTitle, myMinValue, myMaxValue, myValue, myPrefix) + //call selector overlay and set inital value + mySpinBoxSelector.show(myId, myTitle, myMinValue, myMaxValue, myValue, myPrefix) } Connections { target: mySpinBoxSelector @@ -232,6 +232,10 @@ Item { } } + // BlindsRaiseType --> Always double vs. Manual blinds List +// Component { +// //TODO +// } Component.onCompleted: { listViewFactoryLoader.setSourceComponent(componentMap[myType]) diff --git a/src/gui/qml/components/MySpinBoxSelector.qml b/src/gui/qml/components/MySpinBoxSelector.qml index b4f1f701..a8c62b20 100644 --- a/src/gui/qml/components/MySpinBoxSelector.qml +++ b/src/gui/qml/components/MySpinBoxSelector.qml @@ -3,6 +3,7 @@ import QtQuick.Layouts 1.1 import QtQuick.Controls 1.2 import QtQuick.Controls.Styles 1.2 import "../js/colors.js" as GlobalColors +import "../js/tools.js" as GlobalTools import "styles/" Rectangle { @@ -14,30 +15,36 @@ Rectangle { property string titleString: "" property string prefix: "" + property string returnValue: "" + property string myIdString: "" property int minValue: 0 property int maxValue: 0 - property string returnValue: "" property int initialTextFieldValue: 0 property int initialSliderValue: 0 + property bool ready: false - function show(title, min, max, value, pref) { - titleString = title; - initialTextFieldValue = parseInt(value); - initialSliderValue = parseInt(value); - minValue = min; - maxValue = max; - prefix = pref; - returnValue = value; // <-- initial the returnValue with the preselection to prevent a NULL return when pressing Cancel + + function show(myId, myTitle, myMinValue, myMaxValue, myValue, myPrefix) { + myIdString = myId; + titleString = myTitle; + minValue = myMinValue; + maxValue = myMaxValue; + returnValue = myValue; + textField.text = myValue; + prefix = myPrefix; visible = true; + textField.focus = true; } function reject() { visible = false; +// textField.focus = false; } function selected(newSelection) { returnValue = newSelection; visible = false; +// textField.focus = false; } MouseArea { @@ -77,27 +84,20 @@ Rectangle { anchors.rightMargin: 50 //make space for the prefix anchors.leftMargin: 50 + Math.round(appWindow.height*0.03) -// validator: IntValidator{bottom: minValue; top: maxValue;} TODO: test validator in later QtVersions > 5.5.0 - text: initialTextFieldValue - focus: true + validator: IntValidator{bottom: minValue; top: maxValue;} // TODO: test validator in later QtVersions > 5.5.0 + function correctValue() { - if(text != "") { - if(parseInt(text) > maxValue) text = maxValue - else if(parseInt(text) < minValue) text = minValue - else { - //remove leading "0000" - var temp = parseInt(text) - text = temp - } - } + text = GlobalTools.correctTextFieldIntegerValue(selector, text, minValue); } - onFocusChanged: correctValue() - onEditingFinished: correctValue() + + onFocusChanged: { if(selector.ready && !focus) correctValue(); } + onEditingFinished: { if(selector.ready) correctValue(); } style: MyTextFieldStyle { prefix: selector.prefix myTextField: textField } + } Slider { id: slider @@ -112,10 +112,12 @@ Rectangle { //because of the binding to the TextField value stepSize: minimumValue * 10 on__HandlePosChanged: { - if (slider.value > minimumValue && slider.value < maximumValue) - textField.text = slider.value - minimumValue - else - textField.text = slider.value + if(selector.ready) { //wait until the whole component is ready, otherwise setting min and max changes text field value + if (slider.value > minimumValue && slider.value < maximumValue) + textField.text = slider.value - minimumValue + else + textField.text = slider.value + } } style: SliderStyle { handle: Rectangle { @@ -188,5 +190,6 @@ Rectangle { } } } + Component.onCompleted: ready = true } diff --git a/src/gui/qml/cpp/qmlconfig.cpp b/src/gui/qml/cpp/qmlconfig.cpp index 98434be4..7e751e2a 100644 --- a/src/gui/qml/cpp/qmlconfig.cpp +++ b/src/gui/qml/cpp/qmlconfig.cpp @@ -14,6 +14,6 @@ QString QmlConfig::readConfigString(QString varName) { return QString::fromUtf8(myConfig->readConfigString(varName.toStdString()).c_str()); } -QString QmlConfig::readConfigInt(QString varName) { +QString QmlConfig::readConfigIntString(QString varName) { return QString::number(myConfig->readConfigInt(varName.toStdString())); } diff --git a/src/gui/qml/cpp/qmlconfig.h b/src/gui/qml/cpp/qmlconfig.h index f561ffa9..f56eab69 100644 --- a/src/gui/qml/cpp/qmlconfig.h +++ b/src/gui/qml/cpp/qmlconfig.h @@ -11,7 +11,7 @@ class QmlConfig: public QObject public: Q_INVOKABLE QString readConfigString(QString); - Q_INVOKABLE QString readConfigInt(QString); + Q_INVOKABLE QString readConfigIntString(QString); QmlConfig(boost::shared_ptr); ~QmlConfig(); diff --git a/src/gui/qml/js/tools.js b/src/gui/qml/js/tools.js new file mode 100644 index 00000000..b3533757 --- /dev/null +++ b/src/gui/qml/js/tools.js @@ -0,0 +1,15 @@ +//global tools definition + +function correctTextFieldIntegerValue(readyComponent, textValue, minValue) { + if(selector.ready) { + var returnValue = ""; + if(textValue == "" || parseInt(textValue) == 0 || parseInt(textValue) < minValue) { + returnValue = minValue; + } + else { + returnValue = parseInt(textValue); //remove leading "0000" + } + return returnValue; + } +} + diff --git a/src/gui/qml/qml.qrc b/src/gui/qml/qml.qrc index 84bae698..21518e47 100644 --- a/src/gui/qml/qml.qrc +++ b/src/gui/qml/qml.qrc @@ -19,5 +19,6 @@ components/MyBlindsRaiseIntervalSelector.qml components/styles/MyTextFieldStyle.qml components/styles/MyRadioButtonStyle.qml + js/tools.js diff --git a/src/gui/qml/views/createlocalgameview/CreateLocalGameView.qml b/src/gui/qml/views/createlocalgameview/CreateLocalGameView.qml index 240c1a01..429022fc 100644 --- a/src/gui/qml/views/createlocalgameview/CreateLocalGameView.qml +++ b/src/gui/qml/views/createlocalgameview/CreateLocalGameView.qml @@ -41,8 +41,8 @@ Rectangle { myId: "spinBox_StartCash" myTitle: qsTr("Start cash") myType: "SpinBox" - myMaxValue: 1000000 - myMinValue: 1000 + myMaxValue: "1000000" + myMinValue: "1000" myPrefix: "$" myValue: "" } @@ -50,8 +50,8 @@ Rectangle { myId: "spinBox_StartBlind" myTitle: qsTr("Start blind") myType: "SpinBox" - myMaxValue: 20000 - myMinValue: 5 + myMaxValue: "20000" + myMinValue: "5" myPrefix: "$" myValue: "" } @@ -86,13 +86,13 @@ Rectangle { Component.onCompleted: { //set Config Values from config file - createLocalGameViewModel.setProperty(0, "myValue", Config.readConfigInt("NumberOfPlayers")); - createLocalGameViewModel.setProperty(1, "myValue", Config.readConfigInt("StartCash")); - createLocalGameViewModel.setProperty(2, "myValue", Config.readConfigInt("FirstSmallBlind")); - createLocalGameViewModel.setProperty(3, "myRaiseOnHandsType", Config.readConfigInt("RaiseBlindsAtHands")); - createLocalGameViewModel.setProperty(3, "myRaiseOnHandsInterval", Config.readConfigInt("RaiseSmallBlindEveryHands")); - createLocalGameViewModel.setProperty(3, "myRaiseOnMinutesInterval", Config.readConfigInt("RaiseSmallBlindEveryMinutes")); - createLocalGameViewModel.setProperty(4, "myValue", Config.readConfigInt("GameSpeed")); + createLocalGameViewModel.setProperty(0, "myValue", Config.readConfigIntString("NumberOfPlayers")); + createLocalGameViewModel.setProperty(1, "myValue", Config.readConfigIntString("StartCash")); + createLocalGameViewModel.setProperty(2, "myValue", Config.readConfigIntString("FirstSmallBlind")); + createLocalGameViewModel.setProperty(3, "myRaiseOnHandsType", Config.readConfigIntString("RaiseBlindsAtHands")); + createLocalGameViewModel.setProperty(3, "myRaiseOnHandsInterval", Config.readConfigIntString("RaiseSmallBlindEveryHands")); + createLocalGameViewModel.setProperty(3, "myRaiseOnMinutesInterval", Config.readConfigIntString("RaiseSmallBlindEveryMinutes")); + createLocalGameViewModel.setProperty(4, "myValue", Config.readConfigIntString("GameSpeed")); } } delegate: MyListViewDelegateFactory {