main.qml 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. ApplicationWindow {
  29. id: root
  30. visible: true
  31. width: 1024
  32. height: 768
  33. MouseArea {
  34. id: drawingArea
  35. width: 28*20
  36. height: 28*20
  37. onPositionChanged: {
  38. root.contentItem.child
  39. mouse.x
  40. mouse.y
  41. }
  42. }
  43. Repeater {
  44. model: 784
  45. Rectangle {
  46. id: tile
  47. width: 20
  48. height: 20
  49. color: "black"
  50. x: 20*Math.floor(model.index/28)
  51. y: 20*(model.index%28)
  52. border.width: 1
  53. border.color: "white"
  54. Connections {
  55. target: drawingArea
  56. onPositionChanged: {
  57. var centerX = tile.x + tile.width/2
  58. var centerY = tile.y + tile.height/2
  59. var diffX = mouse.x - centerX
  60. var diffY = mouse.y - centerY
  61. var dense = Math.sqrt(diffX * diffX + diffY * diffY)
  62. if(dense < 20) {
  63. tile.color = Qt.rgba(color.r + (20-dense)/20, color.g + (20-dense)/20, color.b + (20-dense)/20, 1.0)
  64. }
  65. }
  66. }
  67. Connections {
  68. target: clearButton
  69. onClicked: {
  70. tile.color = "black"
  71. }
  72. }
  73. }
  74. }
  75. Column {
  76. anchors.right: parent.right
  77. Button {
  78. id: clearButton
  79. text: "Clear"
  80. }
  81. }
  82. }