MainView.qml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import QtQuick 1.0
  2. import ColoringItems 1.0
  3. Rectangle {
  4. id: main
  5. color: "black"
  6. anchors.fill: parent
  7. property int canvasWidth
  8. property int canvasHeight
  9. function resetZoom() {
  10. flick.contentWidth = main.canvasWidth
  11. flick.contentHeight = main.canvasHeight
  12. flick.contentX = 0
  13. flick.contentY = 0
  14. }
  15. Flickable {
  16. id: flick
  17. anchors.fill: parent
  18. contentWidth: canvasWidth
  19. contentHeight: canvasHeight
  20. flickableDirection: Flickable.HorizontalAndVerticalFlick
  21. PinchArea {
  22. id: pincharea
  23. width: Math.max(flick.contentWidth, flick.width)
  24. height: Math.max(flick.contentHeight, flick.height)
  25. property real scale: 1.0
  26. onPinchChanged: {
  27. flick.contentX += pinch.lastCenter.x - pinch.center.x
  28. flick.contentY += pinch.lastCenter.y - pinch.center.y
  29. pincharea.scale = 1.0 + pinch.scale - pinch.lastScale
  30. var oldWidth = flick.contentWidth
  31. var oldHeight = flick.contentHeight
  32. flick.contentWidth = flick.contentWidth * scale
  33. flick.contentHeight = flick.contentHeight * scale
  34. if (pinch.center.x != 0) {
  35. var pos = pinch.center.x * flick.contentWidth / oldWidth
  36. flick.contentX = flick.contentX + pos - pinch.center.x
  37. }
  38. if (pinch.center.y != 0) {
  39. var pos = pinch.center.y * flick.contentHeight / oldHeight
  40. flick.contentY = flick.contentY + pos - pinch.center.y
  41. }
  42. }
  43. onPinchFinished: {
  44. }
  45. ColoringCanvas {
  46. id: coloringcanvas
  47. width: flick.contentWidth
  48. height: flick.contentHeight
  49. smooth: false
  50. color: colorChooser.fillColor
  51. source: fileChooser.currentImage
  52. //onSourceChanged: resetZoom()
  53. property real imageScale: flick.contentWidth / canvasWidth
  54. MouseArea {
  55. anchors.fill: parent
  56. onClicked: {
  57. var x = mouse.x / coloringcanvas.imageScale
  58. var y = mouse.y / coloringcanvas.imageScale
  59. coloringcanvas.click(x, y)
  60. }
  61. }
  62. }
  63. }
  64. }
  65. BorderImage {
  66. anchors.fill: parent
  67. source: "gfx/mainview.png"
  68. border {
  69. top: 10
  70. bottom: 10
  71. left: 10
  72. right: 70
  73. }
  74. }
  75. Column {
  76. y: 5
  77. width: 60
  78. height: parent.height - 10
  79. anchors.right: parent.right
  80. spacing: parent.height / 4 - 55
  81. Button {
  82. source: "gfx/exit.png"
  83. onClicked: Qt.quit()
  84. }
  85. Button {
  86. source: "gfx/select.png"
  87. onClicked: {
  88. fileChooser.show()
  89. }
  90. }
  91. Button {
  92. source: "gfx/restore.png"
  93. onClicked: {
  94. resetZoom()
  95. }
  96. }
  97. Item {
  98. width: 60
  99. height: 60
  100. Rectangle {
  101. anchors.centerIn: parent
  102. width: 40
  103. height: 40
  104. radius: 20
  105. color: colorChooser.fillColor
  106. }
  107. Button {
  108. source: "gfx/colorpicker.png"
  109. onClicked: colorChooser.show()
  110. }
  111. }
  112. }
  113. ColorChooser {
  114. id: colorChooser
  115. width: parent.height
  116. height: parent.height
  117. x: parent.width
  118. }
  119. FileChooser {
  120. id: fileChooser
  121. width: parent.width
  122. height: parent.height
  123. x: parent.width
  124. }
  125. }