MainPage.qml 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /**
  2. * Copyright (c) 2012 Nokia Corporation.
  3. */
  4. import QtQuick 1.1
  5. import com.nokia.symbian 1.1
  6. import "../Constants.js" as Constants
  7. Page {
  8. id: mainPage
  9. tools: sharedToolBar
  10. state: "NORMAL"
  11. ToolBar {
  12. id: sharedToolBar
  13. tools: mainToolBarLayout
  14. platformInverted: window.platformInverted
  15. }
  16. ToolBarLayout {
  17. id: mainToolBarLayout
  18. ToolButton {
  19. flat: true
  20. iconSource: "toolbar-back"
  21. platformInverted: window.platformInverted
  22. onClicked: window.pageStack.depth <= 1 ? Qt.quit() : window.pageStack.pop()
  23. }
  24. ToolButton {
  25. iconSource: platformInverted ? "../Images/Icons/edit_w.svg" : "../Images/Icons/edit.svg"
  26. platformInverted: window.platformInverted
  27. onClicked: mainPage.state = "EDIT";
  28. }
  29. ToolButton {
  30. flat: true
  31. iconSource: platformInverted ? "../Images/Icons/information_userguide_w.svg" : "../Images/Icons/information_userguide.svg"
  32. platformInverted: window.platformInverted
  33. onClicked: window.pageStack.push(Qt.resolvedUrl("../InfoPage.qml"), {text: Constants.SAFETEXT_INFOTEXT});
  34. }
  35. }
  36. ToolBarLayout {
  37. id: editToolBarLayout
  38. ToolButton {
  39. platformInverted: window.platformInverted
  40. text: "Save"
  41. onClicked: {
  42. mainPage.state = "NORMAL";
  43. textContentLabel1.text = textField1.text
  44. textContentLabel2.text = textField2.text
  45. textContentLabel3.text = textField3.text
  46. }
  47. }
  48. ToolButton {
  49. platformInverted: window.platformInverted
  50. text: "Cancel"
  51. onClicked: {
  52. mainPage.state = "NORMAL";
  53. textField1.text = textContentLabel1.text
  54. textField2.text = textContentLabel2.text
  55. textField3.text = textContentLabel3.text
  56. }
  57. }
  58. }
  59. ScrollDecorator{
  60. flickableItem: flickable
  61. }
  62. Flickable{
  63. id: flickable
  64. anchors.fill: parent
  65. width: parent.width
  66. clip: true
  67. contentHeight: item.height + (inputContext.visible ? (inputContext.height - sharedToolBar.height) : 0 )
  68. Item{
  69. id: item
  70. anchors.top: parent.top
  71. anchors.left: parent.left
  72. anchors.right: parent.right
  73. anchors.leftMargin: platformStyle.paddingLarge
  74. anchors.rightMargin: platformStyle.paddingLarge
  75. anchors.topMargin: platformStyle.paddingLarge
  76. height: childrenRect.height + anchors.topMargin
  77. Label {
  78. id: titleLabel1
  79. anchors.top: parent.top
  80. anchors.left: parent.left
  81. platformInverted: window.platformInverted
  82. text: "Text field title 1"
  83. }
  84. Label {
  85. id: textContentLabel1
  86. anchors.verticalCenter: textField1.verticalCenter
  87. anchors.left: parent.left
  88. platformInverted: window.platformInverted
  89. visible: mainPage.state == "NORMAL" ? true : false
  90. text: "Text field content 1"
  91. }
  92. TextArea {
  93. id: textField1
  94. anchors.top: titleLabel1.bottom
  95. anchors.left: parent.left
  96. platformInverted: window.platformInverted
  97. width: parent.width
  98. text: textContentLabel1.text
  99. horizontalAlignment: Text.AlignLeft
  100. visible: !textContentLabel1.visible
  101. }
  102. Label {
  103. id: titleLabel2
  104. anchors.top: textField1.bottom
  105. anchors.topMargin: platformStyle.paddingLarge
  106. anchors.left: parent.left
  107. platformInverted: window.platformInverted
  108. text: "Text field title 2"
  109. }
  110. Label {
  111. id: textContentLabel2
  112. anchors.verticalCenter: textField2.verticalCenter
  113. anchors.left: parent.left
  114. platformInverted: window.platformInverted
  115. visible: mainPage.state == "NORMAL" ? true : false
  116. text: "Text field content 2"
  117. }
  118. TextArea {
  119. id: textField2
  120. anchors.top: titleLabel2.bottom
  121. anchors.left: parent.left
  122. platformInverted: window.platformInverted
  123. width: parent.width
  124. text: textContentLabel2.text
  125. horizontalAlignment: Text.AlignLeft
  126. visible: !textContentLabel2.visible
  127. }
  128. Label {
  129. id: titleLabel3
  130. anchors.top: textField2.bottom
  131. anchors.topMargin: platformStyle.paddingLarge
  132. anchors.left: parent.left
  133. platformInverted: window.platformInverted
  134. text: "Text field title 3"
  135. }
  136. Label {
  137. id: textContentLabel3
  138. anchors.top: titleLabel3.bottom
  139. anchors.topMargin: platformStyle.paddingLarge
  140. anchors.left: parent.left
  141. anchors.right: parent.right
  142. platformInverted: window.platformInverted
  143. horizontalAlignment: Text.AlignLeft
  144. visible: mainPage.state == "NORMAL" ? true : false
  145. wrapMode: Text.WordWrap
  146. text: "Text area content. \n"
  147. + Constants.LOREM_IPSUM_TEXT + Constants.LOREM_IPSUM_TEXT
  148. }
  149. TextArea {
  150. id: textField3
  151. function cursorYPosition() {
  152. return positionToRectangle(cursorPosition).y
  153. }
  154. anchors.top: titleLabel3.bottom
  155. anchors.left: parent.left
  156. platformInverted: window.platformInverted
  157. width: parent.width
  158. text: textContentLabel3.text
  159. horizontalAlignment: Text.AlignLeft
  160. visible: !textContentLabel3.visible
  161. onCursorPositionChanged: {
  162. if (inputContext.visible) {
  163. //cursor above top screen boundary
  164. if (textField3.y + cursorYPosition() < flickable.contentY) {
  165. flickable.contentY -= flickable.contentY - ( textField3.y + cursorYPosition() )
  166. }
  167. //cursor below virtual keyboard top
  168. if (textField3.y + cursorYPosition() > flickable.contentY + flickable.height - inputContext.height) {
  169. flickable.contentY += textField3.y + cursorYPosition()
  170. - (flickable.contentY + flickable.height - inputContext.height)
  171. }
  172. }
  173. else
  174. flickable.contentY = flickable.contentHeight - textField3.height + cursorYPosition()
  175. }
  176. }
  177. }
  178. }
  179. states: [
  180. State {
  181. name: "NORMAL"
  182. },
  183. State {
  184. name: "EDIT"
  185. }
  186. ]
  187. onStateChanged: {
  188. console.log("State changed to: " + state);
  189. if (state == "NORMAL")
  190. sharedToolBar.setTools(mainToolBarLayout)
  191. else
  192. sharedToolBar.setTools(editToolBarLayout)
  193. mainPage.focus = true;
  194. }
  195. }