MainPage.qml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. import QtQuick 1.1
  2. import com.nokia.meego 1.0
  3. import "IMQuery.js" as JsIMQuery
  4. Page {
  5. id: mainPage
  6. tools: commonTools
  7. Rectangle {
  8. id: rectMain
  9. color: "#0080e6"
  10. gradient: Gradient {
  11. GradientStop {
  12. position: 0.00;
  13. color: "#048ef7";
  14. }
  15. GradientStop {
  16. position: 0.26;
  17. color: "#dbdbdb";
  18. }
  19. GradientStop {
  20. position: 0.62;
  21. color: "#ffffff";
  22. }
  23. GradientStop {
  24. position: 1.00;
  25. color: "#c0c0c0";
  26. }
  27. }
  28. anchors.left: parent.left
  29. anchors.leftMargin: 0
  30. anchors.top: parent.top
  31. width: mainPage.width
  32. height: mainPage.height
  33. SipAttributes {
  34. id:customSipAttributes
  35. actionKeyEnabled: true
  36. actionKeyHighlighted: true
  37. actionKeyLabel: qsTr("Submit")
  38. }
  39. Row {
  40. id: rowQuery
  41. anchors.horizontalCenter: parent.horizontalCenter
  42. Image {
  43. id: appLogo
  44. width: 64; height: 64
  45. source: "qrc:/appLogoWithoutBG"
  46. MouseArea {
  47. anchors.right: parent.right
  48. anchors.bottom: parent.bottom
  49. anchors.top: parent.top
  50. onClicked: Qt.openUrlExternally("http://dadablog.net/HarmattanApps")
  51. }
  52. }
  53. Label {
  54. id: lblInstruction
  55. width: 220
  56. y: 15
  57. text: qsTr("Specify a Chinese character: ")
  58. font.pointSize: 20
  59. }
  60. TextField {
  61. id: txtCharacter
  62. width: 90
  63. opacity: 0.7
  64. maximumLength: 1
  65. platformSipAttributes: customSipAttributes
  66. Keys.onReturnPressed: {
  67. txtQueryResults.queryCharacter(txtCharacter.text)
  68. txtCharacter.text = ""
  69. txtCharacter.closeSoftwareInputPanel()
  70. }
  71. platformStyle: TextFieldStyle { paddingRight: clearButton.width }
  72. Image {
  73. id: clearButton
  74. anchors.right: parent.right
  75. anchors.verticalCenter: parent.verticalCenter
  76. source: "image://theme/icon-m-input-clear"
  77. MouseArea {
  78. anchors.fill: parent
  79. onClicked: {
  80. inputContext.reset();
  81. txtCharacter.text = "";
  82. }
  83. }
  84. }
  85. }
  86. Button{
  87. id: btnQuery
  88. width: 100
  89. text: qsTr("Submit")
  90. opacity: 0.5
  91. onClicked: submitQuery()
  92. function submitQuery() {
  93. txtQueryResults.queryCharacter(txtCharacter.text)
  94. txtCharacter.text = ""
  95. }
  96. }
  97. }
  98. Flickable {
  99. id: flick
  100. anchors.left: parent.left
  101. anchors.leftMargin: 0
  102. anchors.top: rowQuery.bottom
  103. contentHeight: rectMain.height * 2.7
  104. width: rectMain.width
  105. height: rectMain.height
  106. clip: true
  107. flickableDirection: Flickable.VerticalFlick
  108. boundsBehavior: Flickable.DragOverBounds
  109. function ensureVisible(r)
  110. {
  111. if (contentY >= r.y)
  112. contentY = r.y;
  113. else if (contentY+height <= r.y+r.height)
  114. contentY = r.y+r.height-height;
  115. }
  116. QueryDialog {
  117. id: nonChineseErrorDialog
  118. titleText: qsTr("Error")
  119. acceptButtonText: qsTr("OK")
  120. message: qsTr("Please specify a Chinese character.")
  121. }
  122. TextEdit {
  123. id: txtQueryResults
  124. text: ""
  125. textFormat: TextEdit.RichText
  126. font.pointSize: 18
  127. width: rectMain.width
  128. height: rectMain.height - rowQuery.height
  129. readOnly: true
  130. focus: true
  131. wrapMode: "WrapAtWordBoundaryOrAnywhere"
  132. onCursorRectangleChanged: flick.ensureVisible(cursorRectangle)
  133. function queryCharacter( character ) {
  134. if (character != "")
  135. {
  136. var db = openDatabaseSync("IM","1.0","IMQuery",7235584);
  137. var r = "<font size=\"+5\" color=\"#000080\">" + character + "</font> "
  138. // Do nothing if character is not Chinese character.
  139. if (character.charCodeAt(0)>=31 && character.charCodeAt(0)<=127) {
  140. text = ""
  141. nonChineseErrorDialog.open()
  142. } else {
  143. var bRowsReturned
  144. db.readTransaction(
  145. function(tx) {
  146. // Look up character for Radicals.
  147. var rs = tx.executeSql('SELECT * FROM Radical WHERE Character=\'' + character + '\'');
  148. if (rs.rows.length!=0) {
  149. for(var i = 0; i < rs.rows.length; i++) {
  150. r += qsTr(" belongs to the ") + rs.rows.item(i).Radical + qsTr(" radical (") + rs.rows.item(i).RemainingStrokes + qsTr(" strokes)") + "<br />"
  151. bRowsReturned = true
  152. }
  153. }
  154. text = r
  155. }
  156. )
  157. if (bRowsReturned==true) {
  158. r += "<hr />"
  159. bRowsReturned = false
  160. }
  161. db.readTransaction(
  162. function(tx) {
  163. // Look up character for Stroke Order strokes.
  164. var rs = tx.executeSql('SELECT * FROM StrokeOrder WHERE Character=\'' + character + '\'');
  165. if (rs.rows.length!=0) {
  166. for(var i = 0; i < rs.rows.length; i++) {
  167. r += qsTr("Total strokes: ") + (rs.rows.item(i).Strokes.length).toString() + "<br />"
  168. r += qsTr("Stroke 5: ") + JsIMQuery.convertToStrokes(rs.rows.item(i).Strokes.substr(0,5)) + " (" + rs.rows.item(i).Strokes.substr(0,5) + ")<br />"
  169. r += qsTr("Stroke orders: ") + JsIMQuery.convertToStrokes(rs.rows.item(i).Strokes) + " (" + rs.rows.item(i).Strokes + ")<br />"
  170. bRowsReturned = true
  171. }
  172. }
  173. text = r
  174. }
  175. )
  176. if (bRowsReturned==true) {
  177. r += "<hr />"
  178. bRowsReturned = false
  179. }
  180. db.readTransaction(
  181. function(tx) {
  182. // Look up character for PinYin inputs.
  183. var rs = tx.executeSql('SELECT * FROM PinYin WHERE Character=\'' + character + '\'');
  184. if (rs.rows.length!=0) {
  185. for(var i = 0; i < rs.rows.length; i++) {
  186. r += qsTr("Pin Yin: ") + rs.rows.item(i).Keys + "<br />"
  187. bRowsReturned = true
  188. }
  189. }
  190. text = r
  191. }
  192. )
  193. db.readTransaction(
  194. function(tx) {
  195. // Look up character for ZhuYin inputs.
  196. var rs = tx.executeSql('SELECT * FROM ZhuYin WHERE Character=\'' + character + '\'');
  197. if (rs.rows.length!=0) {
  198. for(var i = 0; i < rs.rows.length; i++) {
  199. r += qsTr("Zhu Yin: ") + JsIMQuery.convertToZhuYin(rs.rows.item(i).Keys) + " (" + rs.rows.item(i).Keys.toUpperCase() + ")<br />"
  200. bRowsReturned = true
  201. }
  202. }
  203. text = r
  204. }
  205. )
  206. if (bRowsReturned==true) {
  207. r += "<hr />"
  208. bRowsReturned = false
  209. }
  210. db.readTransaction(
  211. function(tx) {
  212. // Look up character for ChangJie3 & Quick3 radicals.
  213. var rs = tx.executeSql('SELECT * FROM CangJie3 WHERE Character=\'' + character + '\'');
  214. if (rs.rows.length!=0) {
  215. for(var i = 0; i < rs.rows.length; i++) {
  216. r += qsTr("CangJie 3rd Edition: ") + JsIMQuery.convertToCangJie(rs.rows.item(i).Keys) + " (" + rs.rows.item(i).Keys.toUpperCase() + ")<br />"
  217. r += qsTr("Quick CangJie 3rd Edition: ") + JsIMQuery.convertToCangJie( rs.rows.item(i).Keys.substr(0,1) + rs.rows.item(i).Keys.substr( rs.rows.item(i).Keys.length - 1,1) ) + " (" + rs.rows.item(i).Keys.substr(0,1).toUpperCase() + rs.rows.item(i).Keys.substr( rs.rows.item(i).Keys.length - 1,1).toUpperCase() + ")<br />"
  218. bRowsReturned = true
  219. }
  220. }
  221. text = r
  222. }
  223. )
  224. db.readTransaction(
  225. function(tx) {
  226. // Look up character for ChangJie5 & Quick5 radicals.
  227. var rs = tx.executeSql('SELECT * FROM CangJie5 WHERE Character=\'' + character + '\'');
  228. if (rs.rows.length!=0) {
  229. for(var i = 0; i < rs.rows.length; i++) {
  230. r += qsTr("CangJie 5th Edition: ") + JsIMQuery.convertToCangJie(rs.rows.item(i).Keys) + " (" + rs.rows.item(i).Keys.toUpperCase() + ")<br />"
  231. r += qsTr("Quick CangJie 5th Edition: ") + JsIMQuery.convertToCangJie( rs.rows.item(i).Keys.substr(0,1) + rs.rows.item(i).Keys.substr( rs.rows.item(i).Keys.length - 1,1) ) + " (" + rs.rows.item(i).Keys.substr(0,1).toUpperCase() + rs.rows.item(i).Keys.substr( rs.rows.item(i).Keys.length - 1,1).toUpperCase() + ")<br />"
  232. bRowsReturned = true
  233. }
  234. }
  235. text = r
  236. }
  237. )
  238. if (bRowsReturned==true) {
  239. r += "<hr />"
  240. bRowsReturned = false
  241. }
  242. db.readTransaction(
  243. function(tx) {
  244. // Look up character for Jyut Ping inputs.
  245. var rs = tx.executeSql('SELECT * FROM JyutPing WHERE Character=\'' + character + '\'');
  246. if (rs.rows.length!=0) {
  247. for(var i = 0; i < rs.rows.length; i++) {
  248. r += qsTr("Jyut Ping: ") + rs.rows.item(i).Keys + "<br />"
  249. bRowsReturned = true
  250. }
  251. }
  252. text = r
  253. }
  254. )
  255. db.readTransaction(
  256. function(tx) {
  257. // Look up character for Cantonese inputs.
  258. var rs = tx.executeSql('SELECT * FROM Canton WHERE Character=\'' + character + '\'');
  259. if (rs.rows.length!=0) {
  260. for(var i = 0; i < rs.rows.length; i++) {
  261. r += qsTr("Cantonese: ") + rs.rows.item(i).Keys + "<br />"
  262. bRowsReturned = true
  263. }
  264. }
  265. text = r
  266. }
  267. )
  268. if (bRowsReturned==true) {
  269. r += "<hr />"
  270. bRowsReturned = false
  271. }
  272. db.readTransaction(
  273. function(tx) {
  274. // Look up character for DaiYi 3rd Edition radicals.
  275. var rs = tx.executeSql('SELECT * FROM DaYi3 WHERE Character=\'' + character + '\'');
  276. if (rs.rows.length!=0) {
  277. for(var i = 0; i < rs.rows.length; i++) {
  278. r += qsTr("Da Yi 3rd Edition: ") + JsIMQuery.convertToDaiYi3(rs.rows.item(i).Keys) + " (" + rs.rows.item(i).Keys.toUpperCase() + ")<br />"
  279. bRowsReturned = true
  280. }
  281. }
  282. text = r
  283. }
  284. )
  285. db.readTransaction(
  286. function(tx) {
  287. // Look up character for WuBi radicals.
  288. var rs = tx.executeSql('SELECT * FROM WuBi WHERE Character=\'' + character + '\'');
  289. if (rs.rows.length!=0) {
  290. for(var i = 0; i < rs.rows.length; i++) {
  291. r += qsTr("Wu Bi: ") + JsIMQuery.convertToWuBi(rs.rows.item(i).Keys) + " (" + rs.rows.item(i).Keys.toUpperCase() + ")<br />"
  292. bRowsReturned = true
  293. }
  294. }
  295. text = r
  296. }
  297. )
  298. if (bRowsReturned==true) {
  299. r += "<hr />"
  300. bRowsReturned = false
  301. }
  302. db.readTransaction(
  303. function(tx) {
  304. // Look up character for Array30 inputs.
  305. var rs = tx.executeSql('SELECT * FROM Array30 WHERE Character=\'' + character + '\'');
  306. if (rs.rows.length!=0) {
  307. for(var i = 0; i < rs.rows.length; i++) {
  308. r += qsTr("Array 30 keys: ") + JsIMQuery.convertToArray30(rs.rows.item(i).Keys) + " (" + rs.rows.item(i).Keys + ")<br />"
  309. bRowsReturned = true
  310. }
  311. }
  312. text = r
  313. }
  314. )
  315. r += "\n\n"
  316. text = r
  317. }
  318. }
  319. }
  320. }
  321. }
  322. }
  323. }