Settings.qml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /*******************************************************************************
  2. * Settings.qml - DictionaryStar, stardict dictionary for MeeGo Harmattan *
  3. * Copyright (C) 2012 Jari P.T. Alhonen *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 3 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License along *
  16. * with this program; if not, see <http://www.gnu.org/licenses/>. *
  17. *******************************************************************************/
  18. import QtQuick 1.1
  19. import com.nokia.meego 1.0
  20. Page {
  21. id: settingPage
  22. property bool delayedMoveToFooter: false
  23. function openDownloadView(url) {
  24. pageStack.push(Qt.resolvedUrl("DictWebView.qml"), {
  25. loadUrl: url
  26. });
  27. }
  28. function moveToFooter() {
  29. if(status != PageStatus.Active)
  30. delayedMoveToFooter = true
  31. else {
  32. dictList.positionViewAtIndex(dictList.count - 1, ListView.Beginning)
  33. // unfortunately there is no function to position at the beginning of the footer
  34. dictList.contentY += 45 // 45 is the height of an item -- item id doesn't work here
  35. }
  36. }
  37. onStatusChanged: {
  38. if(status == PageStatus.Active) {
  39. return_img.visible = !dictCore.noEnabledDictionaries()
  40. dictCore.updateModel()
  41. commonTools.visible = true
  42. moveButtons.visible = false
  43. if(delayedMoveToFooter) {
  44. moveToFooter()
  45. delayedMoveToFooter = false
  46. }
  47. }
  48. }
  49. Rectangle {
  50. anchors.top: parent.top
  51. anchors.left: parent.left
  52. anchors.right: parent.right
  53. height: parent.height - commonTools.height
  54. PinchArea {
  55. anchors.fill: parent
  56. onPinchUpdated: {
  57. var desiredSize = pinch.scale * dictList.currentFontSize
  58. if(desiredSize >= dictList.minimumFontSize && desiredSize <= dictList.maximumFontSize)
  59. dictList.fontSize = desiredSize
  60. }
  61. onPinchFinished: {
  62. var desiredSize = pinch.scale * dictList.currentFontSize
  63. if(desiredSize >= dictList.minimumFontSize && desiredSize <= dictList.maximumFontSize)
  64. dictList.fontSize = desiredSize
  65. dictList.currentFontSize = dictList.fontSize
  66. dictCore.setDefaultFontSize(dictList.currentFontSize)
  67. }
  68. }
  69. Component {
  70. id: header
  71. Rectangle {
  72. width: settingPage.width
  73. height: headline.height
  74. Text {
  75. id: headline
  76. anchors.horizontalCenter: parent.horizontalCenter
  77. font.pixelSize: dictList.fontSize
  78. text: "<h2>"+qsTr("Available Dictionaries")+"</h2>"
  79. visible: dictList.count > 0
  80. }
  81. }
  82. }
  83. ListView {
  84. id: dictList
  85. anchors.fill: parent
  86. clip: true
  87. property int currentFontSize: dictCore.defaultFontSize()
  88. property int fontSize: dictCore.defaultFontSize()
  89. property int minimumFontSize: 10
  90. property int maximumFontSize: 60
  91. height: parent.height
  92. header: header
  93. model: dictsModel
  94. footer: footer
  95. delegate: Rectangle {
  96. id: dictItem
  97. height: 45
  98. anchors.right: parent.right
  99. anchors.left: parent.left
  100. CheckBox {
  101. id: dictEnable
  102. checked: useDict
  103. onClicked: {
  104. dictCore.enableDictionary(name, plugin, checked)
  105. return_img.visible = !dictCore.noEnabledDictionaries()
  106. }
  107. }
  108. Text {
  109. id: dictName;
  110. text: name
  111. anchors.left: dictEnable.right
  112. font.pixelSize: dictList.fontSize
  113. anchors.verticalCenter: dictEnable.verticalCenter
  114. }
  115. Text {
  116. id: pluginName
  117. anchors.left: dictName.right
  118. anchors.leftMargin: 10
  119. font.pixelSize: dictList.fontSize / 2
  120. font.italic: true
  121. text: plugin
  122. anchors.verticalCenter: dictEnable.verticalCenter
  123. }
  124. MouseArea {
  125. id: dragArea
  126. anchors.left: dictName.left
  127. anchors.right: parent.right
  128. anchors.top: parent.top
  129. anchors.bottom: parent.bottom
  130. property int positionStarted: 0
  131. property int positionEnded: 0
  132. property int positionsMoved: ((positionEnded - positionStarted)/parent.height)
  133. property int newPosition: index + positionsMoved
  134. property bool held: false
  135. drag.axis: Drag.YAxis
  136. onPressAndHold: {
  137. if(dictEnable.checked) {
  138. dictItem.z = 2
  139. dictItem.opacity = 0.5
  140. dictList.interactive = false
  141. positionStarted = dictItem.y
  142. dragArea.drag.target = dictItem
  143. held = true
  144. drag.maximumY = (dictList.height - parent.height - 1 + dictList.contentY)
  145. drag.minimumY = 0
  146. } else {
  147. deleteDialog.dictName = dictName.text
  148. deleteDialog.pluginName = pluginName.text
  149. deleteDialog.open()
  150. }
  151. }
  152. onReleased: {
  153. positionEnded = dictItem.y;
  154. if (Math.abs(positionsMoved) < 1 && held == true) {
  155. dictItem.y = positionStarted
  156. dictItem.opacity = 1
  157. dictList.interactive = true
  158. dragArea.drag.target = null
  159. held = false
  160. } else {
  161. if (held == true) {
  162. if (newPosition < 1) {
  163. dictItem.z = 1
  164. dictCore.moveItem(index, 0)
  165. dictList.interactive = true
  166. dragArea.drag.target = null
  167. held = false
  168. } else if (newPosition > dictList.count - 1) {
  169. dictItem.z = 1
  170. dictCore.moveItem(index, dictList.count -1)
  171. dictItem.opacity = 1
  172. dictList.interactive = true
  173. dragArea.drag.target = null
  174. held = false
  175. } else {
  176. dictItem.z = 1
  177. dictCore.moveItem(index, newPosition)
  178. dictItem.opacity = 1
  179. dictList.interactive = true
  180. dragArea.drag.target = null
  181. held = false
  182. }
  183. }
  184. }
  185. } // onReleased
  186. } // dragArea
  187. } // delegate
  188. } // listview
  189. ScrollDecorator {
  190. flickableItem: dictList
  191. }
  192. Component {
  193. id: footer
  194. Rectangle {
  195. width: settingPage.width
  196. height: info_header.height + info.height + download.height + import_dict.height + 30
  197. Text {
  198. id: info_header
  199. anchors.horizontalCenter: parent.horizontalCenter
  200. font.pixelSize: dictList.fontSize
  201. text: "<h2>"+qsTr("Adding Dictionaries")+"</h2>"
  202. }
  203. Text {
  204. id: info
  205. anchors.top: info_header.bottom
  206. anchors.left: parent.left
  207. anchors.right: parent.right
  208. anchors.rightMargin: 65
  209. anchors.leftMargin: 20
  210. anchors.topMargin: 10
  211. width: parent.width
  212. font.pixelSize: dictList.fontSize
  213. wrapMode: Text.Wrap
  214. text: "<p>"+qsTr("Dictionary files in StarDict format for various languages are available for free online.")+"</p>"
  215. }
  216. Text {
  217. id: download
  218. anchors.top: info.bottom
  219. anchors.left: parent.left
  220. anchors.right: parent.right
  221. anchors.rightMargin: 130
  222. anchors.leftMargin: 20
  223. anchors.topMargin: 10
  224. width: parent.width
  225. font.pixelSize: dictList.fontSize
  226. wrapMode: Text.Wrap
  227. text: "<p>"+qsTr("Dictionaries downloaded with the built-in browser will be automatically installed. Just click links: ")
  228. +" <a href=\"http://abloz.com/huzheng/stardict-dic/\">abloz.com</a> " + qsTr("or")
  229. +" <a href=\"http://sourceforge.net/projects/xdxf/files/dicts-stardict-form-xdxf/\">sourceforge.net</a>.</p>"
  230. onLinkActivated: settingPage.openDownloadView(link)
  231. }
  232. Image {
  233. id: download_img
  234. width: 64
  235. height: 64
  236. source: "qrc:/images/download.png"
  237. anchors.right: parent.right
  238. anchors.rightMargin: 65
  239. anchors.verticalCenter: download.verticalCenter
  240. MouseArea {
  241. anchors.fill: parent
  242. onClicked: settingPage.openDownloadView("http://abloz.com/huzheng/stardict-dic/")
  243. }
  244. }
  245. Text {
  246. id: import_dict
  247. anchors.top: download.bottom
  248. anchors.left: parent.left
  249. anchors.right: parent.right
  250. anchors.rightMargin: 65
  251. anchors.leftMargin: 20
  252. anchors.topMargin: 10
  253. width: parent.width
  254. font.pixelSize: dictList.fontSize
  255. wrapMode: Text.Wrap
  256. text: "<p>"+qsTr("Alternatively, you can download dictionaries manually from the regular browser or copy them from a PC. To install in this method, copy the extracted dictionaries to")
  257. +" <code>/home/user/.stardict/dic/</code></p><p><small>"
  258. +qsTr("This program is free software under ")+"<a href=\"http://www.gnu.org/copyleft/gpl.html\">"+qsTr("GPL license")+"</a>"
  259. +qsTr(". The source code can be downloaded from")+" <a href=\"https://gitorious.org/dictionarystar/pages/Home\">gitorious.org/dictionarystar</a>.</small></p>"
  260. onLinkActivated: Qt.openUrlExternally(link)
  261. }
  262. } // rectangle
  263. } // component
  264. } // whole page rectangle
  265. QueryDialog {
  266. id: deleteDialog
  267. property string dictName
  268. property string pluginName
  269. property string promptPreamble: qsTr("Delete ")
  270. property string promptMidamble: qsTr(" dictionary ")
  271. property string promptPostamble: qsTr("?")
  272. property string promptNote: qsTr("This operation cannot be undone.")
  273. icon: "qrc:/images/trash.png"
  274. acceptButtonText: qsTr("Yes")
  275. rejectButtonText: qsTr("No")
  276. titleText: qsTr("Delete Dictionary")
  277. message: promptPreamble + pluginName + promptMidamble + dictName + promptPostamble + promptNote
  278. onAccepted: {
  279. dictCore.deleteDictionary(pluginName, dictName)
  280. // headline.visible = dictList.count > 0
  281. commonTools.visible = true
  282. }
  283. onRejected: commonTools.visible = true
  284. onStatusChanged: {
  285. if(status == DialogStatus.Opening) {
  286. commonTools.visible = false
  287. message = "<p>" + promptPreamble + pluginName + promptMidamble + "\"" + dictName + "\"" + promptPostamble + "</p><p>" + promptNote + "</p>"
  288. }
  289. }
  290. }
  291. } // page