DictWebView.qml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*******************************************************************************
  2. * DictWebView.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 DictWebLib 1.0
  20. import com.nokia.meego 1.0
  21. Page {
  22. id: downloadPage
  23. property string loadUrl
  24. onStatusChanged: {
  25. if(status == PageStatus.Active) {
  26. return_img.visible = true
  27. moveButtons.visible = true
  28. }
  29. }
  30. function movePage(direction) {
  31. downloadView.movePage(direction)
  32. dictDownload.returnToBounds()
  33. }
  34. Flickable {
  35. id: dictDownload
  36. anchors.top: parent.top
  37. anchors.left: parent.left
  38. anchors.right: parent.right
  39. height: parent.height - commonTools.height
  40. flickableDirection: Flickable.HorizontalAndVerticalFlick
  41. contentHeight: downloadView.height
  42. contentWidth: downloadView.width
  43. PinchArea {
  44. anchors.fill: parent
  45. onPinchUpdated: downloadView.zoomFactor = pinch.scale * downloadView.currentScale
  46. onPinchFinished: {
  47. downloadView.zoomFactor = pinch.scale * downloadView.currentScale
  48. downloadView.currentScale = downloadView.zoomFactor
  49. if(pinch.scale < 1.0) {
  50. downloadView.height *= pinch.scale
  51. downloadView.width *= pinch.scale
  52. dictDownload.returnToBounds()
  53. }
  54. }
  55. }
  56. DictWebView {
  57. id: downloadView
  58. property real preferredHeight
  59. property real preferredWidth
  60. property real currentScale: 1.0
  61. signal completedImport(string dicts)
  62. signal failedImport()
  63. url: downloadPage.loadUrl
  64. onContentSizeChanged: {
  65. height = contentHeight
  66. width = contentWidth
  67. }
  68. onImportCompleted: {
  69. if(dicts == "")
  70. failedImport()
  71. else
  72. completedImport(dicts)
  73. }
  74. width: parent.width
  75. height: parent.height
  76. preferredHeight: parent.height
  77. preferredWidth: parent.width
  78. onCompletedImport: {
  79. downloadProgress.visible = false
  80. dictCore.enableDictionaries(dicts)
  81. successReport.text = successReport.success
  82. successReport.opacity = 1
  83. }
  84. onFailedImport: {
  85. downloadProgress.visible = false
  86. successReport.text = successReport.failure
  87. successReport.opacity = 1
  88. }
  89. onDownloadProgress: {
  90. downloadProgress.maximumValue = total
  91. downloadProgress.value = current
  92. downloadProgress.visible = true
  93. }
  94. onLinkClicked: {
  95. busy.visible = true
  96. back_img.enabled = true
  97. forward_img.enabled = false
  98. }
  99. onLoadFinished: busy.visible = false
  100. onHideButton: {
  101. if(back)
  102. back_img.enabled = false
  103. else
  104. forward_img.enabled = false
  105. }
  106. }
  107. }
  108. ScrollDecorator {
  109. flickableItem: dictDownload
  110. }
  111. ProgressBar {
  112. id: downloadProgress
  113. width: parent.width / 2
  114. anchors.horizontalCenter: parent.horizontalCenter
  115. anchors.verticalCenter: parent.verticalCenter
  116. minimumValue: 0
  117. visible: false
  118. }
  119. Text {
  120. id: successReport
  121. property string failure: "<b><font color=\"red\">"+qsTr("Dictionary import failed.")+"</font></b>"
  122. property string success: "<b><font color=\"green\">"+qsTr("Dictionary successfully imported.")+"</font></b>"
  123. anchors.horizontalCenter: parent.horizontalCenter
  124. anchors.verticalCenter: parent.verticalCenter
  125. font.pixelSize: 25
  126. opacity: 0
  127. onOpacityChanged: PropertyAnimation { target: successReport; property: "opacity"; to: 0; duration: 2000 }
  128. }
  129. BusyIndicator {
  130. id: busy
  131. running: true
  132. visible: true
  133. anchors.horizontalCenter: parent.horizontalCenter
  134. anchors.verticalCenter: parent.verticalCenter
  135. platformStyle: BusyIndicatorStyle {
  136. period: 800
  137. numberOfFrames: 5
  138. }
  139. }
  140. }