Advertisement
Guest User

full code

a guest
Jan 8th, 2024
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.98 KB | None | 0 0
  1. import QtQuick
  2. import QtQuick.Controls
  3. import QtQuick.Controls.Universal
  4. import QtQuick.Layouts
  5. import QtQuick.Dialogs
  6. import QtQuick.Pdf
  7.  
  8. ApplicationWindow {
  9. id:root
  10. width: 640
  11. height: 480
  12. visible: true
  13. title: qsTr("Disciplinae")
  14.  
  15. color: "#1A1A1A"
  16. Universal.theme: Universal.Dark
  17.  
  18. menuBar: MenuBar {
  19. Menu {
  20. title: qsTr("&Project")
  21. Action {
  22. text: qsTr("&New Project...")
  23. shortcut: StandardKey.New
  24. }
  25. Action {
  26. text: qsTr("&Open Project...")
  27. shortcut: StandardKey.Open
  28. }
  29. Action {
  30. text: qsTr("&Save")
  31. shortcut: StandardKey.Save
  32. }
  33. Action {
  34. text: qsTr("Save &As...")
  35. shortcut: StandardKey.SaveAs
  36. }
  37. MenuSeparator { }
  38. Action {
  39. text: qsTr("&Quit")
  40. shortcut: StandardKey.Quit
  41. onTriggered: Qt.quit()
  42. }
  43. }
  44. Menu {
  45. title: qsTr("&Edit")
  46. Action {
  47. text: qsTr("&Cut")
  48. }
  49.  
  50. Action {
  51. text: qsTr("&Copy")
  52. }
  53.  
  54. Action {
  55. text: qsTr("&Paste")
  56. }
  57. }
  58. Menu {
  59. title: qsTr("&Help")
  60. Action { text: qsTr("&About") }
  61. }
  62. Menu {
  63. title: qsTr("&Test")
  64. Menu {
  65. title: qsTr("&Test")
  66. Action { text: qsTr("&Test") }
  67. }
  68. }
  69. }
  70.  
  71. PdfDocument {
  72. id: doc
  73. source: Qt.resolvedUrl(root.source)
  74. //onPasswordRequired: passwordDialog.open()
  75. }
  76.  
  77. /*
  78. * ---------
  79. * | * | |
  80. * | | |
  81. * ---------
  82. */
  83. ToolBar {
  84. id:tbar
  85. anchors.right: parent.horizontalCenter
  86. anchors.left: parent.left
  87. anchors.top: parent.top
  88. RowLayout {
  89. anchors.fill: parent
  90. anchors.rightMargin: 6
  91. ToolButton {
  92. action: Action {
  93. text: "Open"
  94. shortcut: StandardKey.Open
  95. //icon.source: "qrc:/pdfviewer/resources/document-open.svg"
  96. onTriggered: fileDialog.open()
  97. }
  98. }
  99. ToolButton {
  100. action: Action {
  101. shortcut: StandardKey.ZoomIn
  102. enabled: view.renderScale < 10
  103. icon.source: "qrc:/pdfviewer/resources/zoom-in.svg"
  104. onTriggered: view.renderScale *= Math.sqrt(2)
  105. }
  106. }
  107. ToolButton {
  108. action: Action {
  109. shortcut: StandardKey.ZoomOut
  110. enabled: view.renderScale > 0.1
  111. icon.source: "qrc:/pdfviewer/resources/zoom-out.svg"
  112. onTriggered: view.renderScale /= Math.sqrt(2)
  113. }
  114. }
  115. ToolButton {
  116. action: Action {
  117. icon.source: "qrc:/pdfviewer/resources/zoom-fit-width.svg"
  118. onTriggered: view.scaleToWidth(root.contentItem.width, root.contentItem.height)
  119. }
  120. }
  121. ToolButton {
  122. action: Action {
  123. icon.source: "qrc:/pdfviewer/resources/zoom-fit-best.svg"
  124. onTriggered: view.scaleToPage(root.contentItem.width, root.contentItem.height)
  125. }
  126. }
  127. ToolButton {
  128. action: Action {
  129. shortcut: "Ctrl+0"
  130. icon.source: "qrc:/pdfviewer/resources/zoom-original.svg"
  131. onTriggered: view.resetScale()
  132. }
  133. }
  134. ToolButton {
  135. action: Action {
  136. shortcut: "Ctrl+L"
  137. icon.source: "qrc:/pdfviewer/resources/rotate-left.svg"
  138. onTriggered: view.pageRotation -= 90
  139. }
  140. }
  141. ToolButton {
  142. action: Action {
  143. shortcut: "Ctrl+R"
  144. icon.source: "qrc:/pdfviewer/resources/rotate-right.svg"
  145. onTriggered: view.pageRotation += 90
  146. }
  147. }
  148. ToolButton {
  149. action: Action {
  150. icon.source: "qrc:/pdfviewer/resources/go-previous-view-page.svg"
  151. enabled: view.backEnabled
  152. onTriggered: view.back()
  153. }
  154. ToolTip.visible: enabled && hovered
  155. ToolTip.delay: 2000
  156. ToolTip.text: "go back"
  157. }
  158. SpinBox {
  159. id: currentPageSB
  160. from: 1
  161. to: doc.pageCount
  162. editable: true
  163. onValueModified: view.goToPage(value - 1)
  164. Shortcut {
  165. sequence: StandardKey.MoveToPreviousPage
  166. onActivated: view.goToPage(currentPageSB.value - 2)
  167. }
  168. Shortcut {
  169. sequence: StandardKey.MoveToNextPage
  170. onActivated: view.goToPage(currentPageSB.value)
  171. }
  172. }
  173. ToolButton {
  174. action: Action {
  175. icon.source: "qrc:/pdfviewer/resources/go-next-view-page.svg"
  176. enabled: view.forwardEnabled
  177. onTriggered: view.forward()
  178. }
  179. ToolTip.visible: enabled && hovered
  180. ToolTip.delay: 2000
  181. ToolTip.text: "go forward"
  182. }
  183. ToolButton {
  184. action: Action {
  185. shortcut: StandardKey.SelectAll
  186. icon.source: "qrc:/pdfviewer/resources/edit-select-all.svg"
  187. onTriggered: view.selectAll()
  188. }
  189. }
  190. ToolButton {
  191. action: Action {
  192. shortcut: StandardKey.Copy
  193. icon.source: "qrc:/pdfviewer/resources/edit-copy.svg"
  194. enabled: view.selectedText !== ""
  195. onTriggered: view.copySelectionToClipboard()
  196. }
  197. }
  198. Shortcut {
  199. sequence: StandardKey.Find
  200. onActivated: searchField.forceActiveFocus()
  201. }
  202. Shortcut {
  203. sequence: StandardKey.Quit
  204. onActivated: Qt.quit()
  205. }
  206. }
  207. }
  208.  
  209.  
  210. /*
  211. * ---------
  212. * | | |
  213. * | * | |
  214. * ---------
  215. */
  216. PdfMultiPageView {
  217. id: view
  218. document: doc
  219. anchors.right: parent.horizontalCenter
  220. anchors.left: parent.left
  221. anchors.top: tbar.bottom
  222. anchors.bottom: parent.bottom
  223. //anchors.leftMargin: sidebar.position * sidebar.width
  224. //searchString: searchField.text
  225. //onCurrentPageChanged: currentPageSB.value = view.currentPage + 1
  226. }
  227.  
  228. FileDialog {
  229. id: fileDialog
  230. title: qsTr("Open a PDF file")
  231. nameFilters: [ "PDF files (*.pdf)" ]
  232. onAccepted: doc.source = selectedFile
  233. }
  234.  
  235. DropArea { //from PdfMultiPageView example
  236. anchors.fill: view
  237. keys: ["text/uri-list"]
  238. onEntered: (drag) => {
  239. drag.accepted = (drag.proposedAction === Qt.MoveAction || drag.proposedAction === Qt.CopyAction) &&
  240. drag.hasUrls && drag.urls[0].endsWith("pdf")
  241. }
  242. onDropped: (drop) => {
  243. doc.source = drop.urls[0]
  244. drop.acceptProposedAction()
  245. }
  246. }
  247. }
  248.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement