brmbarv3 ItemEdit: Allow keyboard text entry

This commit is contained in:
Petr Baudis 2012-10-16 22:42:37 +02:00
parent c81189889e
commit 906fc75f3c
2 changed files with 35 additions and 20 deletions

View file

@ -6,15 +6,19 @@ Item {
id: page id: page
anchors.fill: parent anchors.fill: parent
property variant name: "" property variant item_name: item_name_pad.enteredText
property variant dbid: "" property variant dbid: ""
property variant info: "" property variant info: ""
property variant buy_price: item_buyprice_pad.enteredText
property variant price: item_sellprice_pad.enteredText
property string barcode: "" property string barcode: ""
state: "normal" state: "normal"
BarcodeInput { BarcodeInput {
color: "#00ff00" /* just for debugging */ color: "#00ff00" /* just for debugging */
focus: page.state == "normal"
visible: true
onAccepted: { onAccepted: {
var acct = shop.barcodeInput(text) var acct = shop.barcodeInput(text)
barcode = text barcode = text
@ -42,13 +46,13 @@ Item {
height: 60 height: 60
Text { Text {
id: item_name id: item_name_text
x: 0 x: 0
y: 0 y: 0
width: 534 width: 534
height: 60 height: 60
color: "#ffff7c" color: "#ffff7c"
text: page.name text: page.item_name
wrapMode: Text.WordWrap wrapMode: Text.WordWrap
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
font.pixelSize: 46 font.pixelSize: 46
@ -71,8 +75,9 @@ Item {
x: 65 x: 65
y: 239 y: 239
visible: page.state == "name_edit" visible: page.state == "name_edit"
onLetterEntered: { page.name = page.name + letter; } focus: page.state == "name_edit"
onLetterBackspace: { page.name = page.name.replace(/.$/, ''); } Keys.onReturnPressed: { item_name_edit.buttonClick() }
Keys.onEscapePressed: { cancel.buttonClick() }
} }
Item { Item {
@ -102,7 +107,7 @@ Item {
height: 60 height: 60
width: 248 width: 248
color: "#ffff7c" color: "#ffff7c"
text: info.buy_price text: page.buy_price
horizontalAlignment: Text.AlignRight horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
font.pixelSize: 46 font.pixelSize: 46
@ -125,8 +130,9 @@ Item {
x: 65 x: 65
y: 239 y: 239
visible: page.state == "buyprice_edit" visible: page.state == "buyprice_edit"
onLetterEntered: { var xi = info; xi.buy_price = xi.buy_price.toString() + letter; info = xi } focus: page.state == "buyprice_edit"
onLetterBackspace: { var xi = info; xi.buy_price = xi.buy_price.toString().replace(/.$/, ''); info = xi } Keys.onReturnPressed: { item_buyprice_edit.buttonClick() }
Keys.onEscapePressed: { cancel.buttonClick() }
} }
Item { Item {
@ -156,7 +162,7 @@ Item {
height: 60 height: 60
width: 248 width: 248
color: "#ffff7c" color: "#ffff7c"
text: info.price text: page.price
horizontalAlignment: Text.AlignRight horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
font.pixelSize: 46 font.pixelSize: 46
@ -179,8 +185,9 @@ Item {
x: 65 x: 65
y: 239 y: 239
visible: page.state == "sellprice_edit" visible: page.state == "sellprice_edit"
onLetterEntered: { var xi = info; xi.price = xi.price.toString() + letter; info = xi } focus: page.state == "sellprice_edit"
onLetterBackspace: { var xi = info; xi.price = xi.price.toString().replace(/.$/, ''); info = xi } Keys.onReturnPressed: { item_sellprice_edit.buttonClick() }
Keys.onEscapePressed: { cancel.buttonClick() }
} }
Item { Item {
@ -226,11 +233,11 @@ Item {
text: page.state == "balance_edit" ? "Add qty" : "Restock" text: page.state == "balance_edit" ? "Add qty" : "Restock"
onButtonClick: { onButtonClick: {
if (page.state == "balance_edit") { if (page.state == "balance_edit") {
var xi = info; xi.balance = parseInt(xi.balance) + parseInt(balance_addqty_amount.text); info = xi; var xi = info; xi.balance = parseInt(xi.balance) + parseInt(balance_addqty_edit.enteredText); info = xi;
page.state = "normal"; page.state = "normal";
} else { } else {
page.state = "balance_edit"; page.state = "balance_edit";
balance_addqty_amount.text = "" balance_addqty_edit.enteredText = ""
} }
} }
} }
@ -246,8 +253,9 @@ Item {
id: balance_addqty_edit id: balance_addqty_edit
x: 0 x: 0
y: 0 y: 0
onLetterEntered: { balance_addqty_amount.text = balance_addqty_amount.text.toString() + letter; } focus: page.state == "balance_edit"
onLetterBackspace: { balance_addqty_amount.text = balance_addqty_amount.text.toString().replace(/.$/, ''); } Keys.onReturnPressed: { item_balance_restock.buttonClick() }
Keys.onEscapePressed: { cancel.buttonClick() }
} }
Text { Text {
@ -269,7 +277,7 @@ Item {
height: 80 height: 80
width: 248 width: 248
color: "#ffff7c" color: "#ffff7c"
text: "" text: balance_addqty_edit.enteredText
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
font.pixelSize: 60 font.pixelSize: 60
} }
@ -302,7 +310,11 @@ Item {
width: 360 width: 360
text: dbid == "" ? "Create" : "Save" text: dbid == "" ? "Create" : "Save"
onButtonClick: { onButtonClick: {
var xi = info; xi["name"] = page.name; info = xi var xi = info;
xi["name"] = page.item_name;
xi["buy_price"] = page.buy_price;
xi["price"] = page.price;
info = xi
var res; var res;
if (dbid == "") { if (dbid == "") {
@ -348,6 +360,9 @@ Item {
} else { } else {
info = { "name": "", "dbid": "", "buy_price": "", "price": "", "balance": 0 }; info = { "name": "", "dbid": "", "buy_price": "", "price": "", "balance": 0 };
} }
item_name_pad.enteredText = info.name
item_buyprice_pad.enteredText = info.buy_price
item_sellprice_pad.enteredText = info.price
} }
states: [ states: [

View file

@ -21,7 +21,7 @@ Item {
loadPageByAcct(acct) loadPageByAcct(acct)
return return
} }
loadPage("ItemEdit", { name: acct["name"], dbid: acct["id"] }) loadPage("ItemEdit", { dbid: acct["id"] })
} }
} }
@ -65,7 +65,7 @@ Item {
text: "Edit" text: "Edit"
fontSize: 46 fontSize: 46
onButtonClick: { onButtonClick: {
loadPage("ItemEdit", { name: modelData.name, dbid: modelData.id }) loadPage("ItemEdit", { dbid: modelData.id })
} }
} }
} }
@ -88,7 +88,7 @@ Item {
text: "Add Item" text: "Add Item"
fontSize: 60 fontSize: 60
onButtonClick: { onButtonClick: {
loadPage("ItemEdit", { name: "", dbid: "" }) loadPage("ItemEdit", { dbid: "" })
} }
} }