SpinBox bugfixes, outsourced corretValues helper function, MyBlindsRaiseIntervalSelector focus bugfixes

This commit is contained in:
Felix Hammer
2015-08-18 01:36:55 +02:00
parent bb441b565c
commit d0cce129dd
8 changed files with 91 additions and 82 deletions
@@ -3,6 +3,7 @@ import QtQuick.Layouts 1.1
import QtQuick.Controls 1.2 import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2 import QtQuick.Controls.Styles 1.2
import "../js/colors.js" as GlobalColors import "../js/colors.js" as GlobalColors
import "../js/tools.js" as GlobalTools
import "styles/" import "styles/"
Rectangle { Rectangle {
@@ -20,12 +21,22 @@ Rectangle {
property int raiseOnHandsMaximum: 99 property int raiseOnHandsMaximum: 99
property int raiseOnMinutesMinimum: 1 property int raiseOnMinutesMinimum: 1
property int raiseOnMinutesMaximum: 99 property int raiseOnMinutesMaximum: 99
property bool ready: false
function show(type, hands, minutes) { function show(type, hands, minutes) {
raiseOnHandsType = type; raiseOnHandsType = type;
raiseOnHandsInterval = hands; raiseOnHandsInterval = hands;
raiseOnMinutesInterval = minutes; raiseOnMinutesInterval = minutes;
visible = true; visible = true;
if(raiseOnHandsType == "1") {
textFieldHandsInterval.focus = true;
radioBtnRaiseOnHands.checked = true;
}
else {
textFieldMinutesInterval.focus = true;
radioBtnRaiseOnMinutes.checked = true;
}
} }
function reject() { function reject() {
@@ -80,37 +91,24 @@ Rectangle {
RadioButton { RadioButton {
id: radioBtnRaiseOnHands id: radioBtnRaiseOnHands
checked: raiseOnHandsType ? true : false
exclusiveGroup: raiseTypeGroup exclusiveGroup: raiseTypeGroup
style: MyRadioButtonStyle { style: MyRadioButtonStyle {
myRadioBtn: radioBtnRaiseOnHands; myRadioBtn: radioBtnRaiseOnHands;
labelString: "Every" labelString: "Every"
} }
onCheckedChanged: checked ? textFieldHandsInterval.focus = true : textFieldHandsInterval.focus = false onClicked: textFieldHandsInterval.focus = true;
} }
TextField { TextField {
id: textFieldHandsInterval id: textFieldHandsInterval
width: appWindow.textFieldFontSize*2 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 text: raiseOnHandsInterval
focus: raiseOnHandsType ? true : false
function correctValue() { function correctValue() {
if(text != "") { text = GlobalTools.correctTextFieldIntegerValue(selector, text, raiseOnHandsMinimum);
if(parseInt(text) > raiseOnHandsMaximum) text = raiseOnHandsMaximum
else if(parseInt(text) < raiseOnHandsMinimum) text = raiseOnHandsMinimum
else {
//remove leading "0000"
var temp = parseInt(text)
text = temp
} }
} onFocusChanged: { if(selector.ready && !focus) correctValue(); }
} onEditingFinished: { if(selector.ready) correctValue(); }
onFocusChanged: {
correctValue()
focus ? radioBtnRaiseOnHands.checked = true : radioBtnRaiseOnHands.checked = false
}
onEditingFinished: correctValue()
style: MyTextFieldStyle { style: MyTextFieldStyle {
myTextField: textFieldHandsInterval myTextField: textFieldHandsInterval
@@ -126,37 +124,24 @@ Rectangle {
spacing: appWindow.rowLayoutSpacing spacing: appWindow.rowLayoutSpacing
RadioButton { RadioButton {
id: radioBtnRaiseOnMinutes id: radioBtnRaiseOnMinutes
checked: raiseOnHandsType ? false : true
exclusiveGroup: raiseTypeGroup exclusiveGroup: raiseTypeGroup
style: MyRadioButtonStyle { style: MyRadioButtonStyle {
myRadioBtn: radioBtnRaiseOnMinutes; myRadioBtn: radioBtnRaiseOnMinutes;
labelString: "Every" labelString: "Every"
} }
onCheckedChanged: checked ? textFieldMinutesInterval.focus = true : textFieldMinutesInterval.focus = false onClicked: textFieldMinutesInterval.focus = true;
} }
TextField { TextField {
id: textFieldMinutesInterval 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 text: raiseOnMinutesInterval
width: appWindow.textFieldFontSize*2 width: appWindow.textFieldFontSize*2
focus: raiseOnHandsType ? false : true
function correctValue() { function correctValue() {
if(text != "") { text = GlobalTools.correctTextFieldIntegerValue(selector, text, raiseOnMinutesMinimum);
if(parseInt(text) > raiseOnMinutesMaximum) text = raiseOnMinutesMaximum
else if(parseInt(text) < raiseOnMinutesMinimum) text = raiseOnMinutesMinimum
else {
//remove leading "0000"
var temp = parseInt(text)
text = temp
} }
} onFocusChanged: { if(selector.ready && !focus) correctValue(); }
} onEditingFinished: { if(selector.ready) correctValue(); }
onFocusChanged: {
correctValue();
focus ? radioBtnRaiseOnMinutes.checked = true : radioBtnRaiseOnMinutes.checked = false
}
onEditingFinished: correctValue()
style: MyTextFieldStyle { style: MyTextFieldStyle {
myTextField: textFieldMinutesInterval myTextField: textFieldMinutesInterval
@@ -213,4 +198,5 @@ Rectangle {
} }
} }
} }
Component.onCompleted: ready = true;
} }
@@ -134,8 +134,8 @@ Item {
id: mouse id: mouse
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
//call selector overlay and set inital values //call selector overlay and set inital value
mySpinBoxSelector.show(myTitle, myMinValue, myMaxValue, myValue, myPrefix) mySpinBoxSelector.show(myId, myTitle, myMinValue, myMaxValue, myValue, myPrefix)
} }
Connections { Connections {
target: mySpinBoxSelector target: mySpinBoxSelector
@@ -232,6 +232,10 @@ Item {
} }
} }
// BlindsRaiseType --> Always double vs. Manual blinds List
// Component {
// //TODO
// }
Component.onCompleted: { Component.onCompleted: {
listViewFactoryLoader.setSourceComponent(componentMap[myType]) listViewFactoryLoader.setSourceComponent(componentMap[myType])
+26 -23
View File
@@ -3,6 +3,7 @@ import QtQuick.Layouts 1.1
import QtQuick.Controls 1.2 import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2 import QtQuick.Controls.Styles 1.2
import "../js/colors.js" as GlobalColors import "../js/colors.js" as GlobalColors
import "../js/tools.js" as GlobalTools
import "styles/" import "styles/"
Rectangle { Rectangle {
@@ -14,30 +15,36 @@ Rectangle {
property string titleString: "" property string titleString: ""
property string prefix: "" property string prefix: ""
property string returnValue: ""
property string myIdString: ""
property int minValue: 0 property int minValue: 0
property int maxValue: 0 property int maxValue: 0
property string returnValue: ""
property int initialTextFieldValue: 0 property int initialTextFieldValue: 0
property int initialSliderValue: 0 property int initialSliderValue: 0
property bool ready: false
function show(title, min, max, value, pref) {
titleString = title; function show(myId, myTitle, myMinValue, myMaxValue, myValue, myPrefix) {
initialTextFieldValue = parseInt(value); myIdString = myId;
initialSliderValue = parseInt(value); titleString = myTitle;
minValue = min; minValue = myMinValue;
maxValue = max; maxValue = myMaxValue;
prefix = pref; returnValue = myValue;
returnValue = value; // <-- initial the returnValue with the preselection to prevent a NULL return when pressing Cancel textField.text = myValue;
prefix = myPrefix;
visible = true; visible = true;
textField.focus = true;
} }
function reject() { function reject() {
visible = false; visible = false;
// textField.focus = false;
} }
function selected(newSelection) { function selected(newSelection) {
returnValue = newSelection; returnValue = newSelection;
visible = false; visible = false;
// textField.focus = false;
} }
MouseArea { MouseArea {
@@ -77,27 +84,20 @@ Rectangle {
anchors.rightMargin: 50 anchors.rightMargin: 50
//make space for the prefix //make space for the prefix
anchors.leftMargin: 50 + Math.round(appWindow.height*0.03) anchors.leftMargin: 50 + Math.round(appWindow.height*0.03)
// validator: IntValidator{bottom: minValue; top: maxValue;} TODO: test validator in later QtVersions > 5.5.0 validator: IntValidator{bottom: minValue; top: maxValue;} // TODO: test validator in later QtVersions > 5.5.0
text: initialTextFieldValue
focus: true
function correctValue() { function correctValue() {
if(text != "") { text = GlobalTools.correctTextFieldIntegerValue(selector, text, minValue);
if(parseInt(text) > maxValue) text = maxValue
else if(parseInt(text) < minValue) text = minValue
else {
//remove leading "0000"
var temp = parseInt(text)
text = temp
} }
}
} onFocusChanged: { if(selector.ready && !focus) correctValue(); }
onFocusChanged: correctValue() onEditingFinished: { if(selector.ready) correctValue(); }
onEditingFinished: correctValue()
style: MyTextFieldStyle { style: MyTextFieldStyle {
prefix: selector.prefix prefix: selector.prefix
myTextField: textField myTextField: textField
} }
} }
Slider { Slider {
id: slider id: slider
@@ -112,11 +112,13 @@ Rectangle {
//because of the binding to the TextField value //because of the binding to the TextField value
stepSize: minimumValue * 10 stepSize: minimumValue * 10
on__HandlePosChanged: { on__HandlePosChanged: {
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) if (slider.value > minimumValue && slider.value < maximumValue)
textField.text = slider.value - minimumValue textField.text = slider.value - minimumValue
else else
textField.text = slider.value textField.text = slider.value
} }
}
style: SliderStyle { style: SliderStyle {
handle: Rectangle { handle: Rectangle {
width: Math.round(selectionBox.height*0.12) width: Math.round(selectionBox.height*0.12)
@@ -188,5 +190,6 @@ Rectangle {
} }
} }
} }
Component.onCompleted: ready = true
} }
+1 -1
View File
@@ -14,6 +14,6 @@ QString QmlConfig::readConfigString(QString varName) {
return QString::fromUtf8(myConfig->readConfigString(varName.toStdString()).c_str()); 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())); return QString::number(myConfig->readConfigInt(varName.toStdString()));
} }
+1 -1
View File
@@ -11,7 +11,7 @@ class QmlConfig: public QObject
public: public:
Q_INVOKABLE QString readConfigString(QString); Q_INVOKABLE QString readConfigString(QString);
Q_INVOKABLE QString readConfigInt(QString); Q_INVOKABLE QString readConfigIntString(QString);
QmlConfig(boost::shared_ptr<ConfigFile>); QmlConfig(boost::shared_ptr<ConfigFile>);
~QmlConfig(); ~QmlConfig();
+15
View File
@@ -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;
}
}
+1
View File
@@ -19,5 +19,6 @@
<file>components/MyBlindsRaiseIntervalSelector.qml</file> <file>components/MyBlindsRaiseIntervalSelector.qml</file>
<file>components/styles/MyTextFieldStyle.qml</file> <file>components/styles/MyTextFieldStyle.qml</file>
<file>components/styles/MyRadioButtonStyle.qml</file> <file>components/styles/MyRadioButtonStyle.qml</file>
<file>js/tools.js</file>
</qresource> </qresource>
</RCC> </RCC>
@@ -41,8 +41,8 @@ Rectangle {
myId: "spinBox_StartCash" myId: "spinBox_StartCash"
myTitle: qsTr("Start cash") myTitle: qsTr("Start cash")
myType: "SpinBox" myType: "SpinBox"
myMaxValue: 1000000 myMaxValue: "1000000"
myMinValue: 1000 myMinValue: "1000"
myPrefix: "$" myPrefix: "$"
myValue: "" myValue: ""
} }
@@ -50,8 +50,8 @@ Rectangle {
myId: "spinBox_StartBlind" myId: "spinBox_StartBlind"
myTitle: qsTr("Start blind") myTitle: qsTr("Start blind")
myType: "SpinBox" myType: "SpinBox"
myMaxValue: 20000 myMaxValue: "20000"
myMinValue: 5 myMinValue: "5"
myPrefix: "$" myPrefix: "$"
myValue: "" myValue: ""
} }
@@ -86,13 +86,13 @@ Rectangle {
Component.onCompleted: { Component.onCompleted: {
//set Config Values from config file //set Config Values from config file
createLocalGameViewModel.setProperty(0, "myValue", Config.readConfigInt("NumberOfPlayers")); createLocalGameViewModel.setProperty(0, "myValue", Config.readConfigIntString("NumberOfPlayers"));
createLocalGameViewModel.setProperty(1, "myValue", Config.readConfigInt("StartCash")); createLocalGameViewModel.setProperty(1, "myValue", Config.readConfigIntString("StartCash"));
createLocalGameViewModel.setProperty(2, "myValue", Config.readConfigInt("FirstSmallBlind")); createLocalGameViewModel.setProperty(2, "myValue", Config.readConfigIntString("FirstSmallBlind"));
createLocalGameViewModel.setProperty(3, "myRaiseOnHandsType", Config.readConfigInt("RaiseBlindsAtHands")); createLocalGameViewModel.setProperty(3, "myRaiseOnHandsType", Config.readConfigIntString("RaiseBlindsAtHands"));
createLocalGameViewModel.setProperty(3, "myRaiseOnHandsInterval", Config.readConfigInt("RaiseSmallBlindEveryHands")); createLocalGameViewModel.setProperty(3, "myRaiseOnHandsInterval", Config.readConfigIntString("RaiseSmallBlindEveryHands"));
createLocalGameViewModel.setProperty(3, "myRaiseOnMinutesInterval", Config.readConfigInt("RaiseSmallBlindEveryMinutes")); createLocalGameViewModel.setProperty(3, "myRaiseOnMinutesInterval", Config.readConfigIntString("RaiseSmallBlindEveryMinutes"));
createLocalGameViewModel.setProperty(4, "myValue", Config.readConfigInt("GameSpeed")); createLocalGameViewModel.setProperty(4, "myValue", Config.readConfigIntString("GameSpeed"));
} }
} }
delegate: MyListViewDelegateFactory { delegate: MyListViewDelegateFactory {