main.qml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * MIT License
  3. *
  4. * Copyright (c) 2019 Alexey Edelev <semlanik@gmail.com>
  5. *
  6. * This file is part of NeuralNetwork project https://git.semlanik.org/semlanik/NeuralNetwork
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy of this
  9. * software and associated documentation files (the "Software"), to deal in the Software
  10. * without restriction, including without limitation the rights to use, copy, modify,
  11. * merge, publish, distribute, sublicense, and/or sell copies of the Software, and
  12. * to permit persons to whom the Software is furnished to do so, subject to the following
  13. * conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in all copies
  16. * or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  19. * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  20. * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  21. * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  22. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. */
  25. import QtQuick 2.11
  26. import QtQuick.Window 2.11
  27. import QtQuick.Controls 1.4
  28. import snakesimulator 1.0
  29. ApplicationWindow {
  30. id: root
  31. visible: true
  32. property int tileSize: 20
  33. width: field.width*tileSize + sideBar.width
  34. height: field.height*tileSize
  35. Rectangle {
  36. color: "#565656"
  37. anchors.fill: parent
  38. }
  39. Repeater {
  40. model: snake.pointsData.length
  41. Rectangle {
  42. color: "#ffffff"
  43. x: snake.pointsData[model.index].x*tileSize
  44. y: snake.pointsData[model.index].y*tileSize
  45. width: tileSize
  46. height: tileSize
  47. }
  48. }
  49. Rectangle {
  50. color: "#99ee99"
  51. x: field.food.x*tileSize
  52. y: field.food.y*tileSize
  53. width: tileSize
  54. height: tileSize
  55. }
  56. Rectangle {
  57. id: sideBar
  58. width: speedTextField.width + contentColumn.anchors.margins*2
  59. color: "#000000"
  60. anchors {
  61. right: parent.right
  62. top: parent.top
  63. bottom: parent.bottom
  64. }
  65. Column {
  66. id: contentColumn
  67. anchors.fill: parent
  68. anchors.margins: 10
  69. spacing: 10
  70. Text {
  71. font.pointSize: 14
  72. font.weight: Font.Bold
  73. color: "#ffffff"
  74. text: "Generation: " + stats.generation
  75. }
  76. Text {
  77. font.pointSize: 14
  78. font.weight: Font.Bold
  79. color: "#ffffff"
  80. text: "Individual: " + stats.individual
  81. }
  82. Text {
  83. font.pointSize: 14
  84. font.weight: Font.Bold
  85. color: "#ffffff"
  86. text: "Move: " + stats.move
  87. }
  88. Text {
  89. font.pointSize: 14
  90. font.weight: Font.Bold
  91. color: "#ffffff"
  92. text: "Speed: "
  93. }
  94. TextField {
  95. id: speedTextField
  96. font.pointSize: 14
  97. validator: RegExpValidator {
  98. regExp: /1?[0-9]{1}/
  99. }
  100. onAccepted: {
  101. client.setSpeed(parseInt(text, 10))
  102. }
  103. }
  104. }
  105. }
  106. Connections {
  107. target: field
  108. onWidthChanged: {
  109. console.log("New width: " + field.width)
  110. }
  111. }
  112. }