PdfLinkDelegate.qml 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright (C) 2022 The Qt Company Ltd.
  2. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
  3. import QtQuick
  4. import QtQuick.Controls
  5. /*!
  6. \qmltype PdfLinkDelegate
  7. \inqmlmodule QtQuick.Pdf
  8. \brief A component to decorate hyperlinks on a PDF page.
  9. PdfLinkDelegate provides the component that QML-based PDF viewers
  10. instantiate on top of each hyperlink that is found on each PDF page.
  11. This component does not provide any visual decoration, because often the
  12. hyperlinks will already be formatted in a distinctive way; but when the
  13. mouse cursor hovers, it changes to Qt::PointingHandCursor, and a tooltip
  14. appears after a delay. Clicking emits the goToLocation() signal if the link
  15. is internal, or calls Qt.openUrlExternally() if the link contains a URL.
  16. \sa PdfPageView, PdfScrollablePageView, PdfMultiPageView
  17. */
  18. Item {
  19. id: root
  20. required property var link
  21. required property rect rectangle
  22. required property url url
  23. required property int page
  24. required property point location
  25. required property real zoom
  26. /*!
  27. \qmlsignal PdfLinkDelegate::tapped(link)
  28. Emitted on mouse click or touch tap. The \a link argument is an
  29. instance of QPdfLink with information about the hyperlink.
  30. */
  31. signal tapped(var link)
  32. /*!
  33. \qmlsignal PdfLinkDelegate::contextMenuRequested(link)
  34. Emitted on mouse right-click or touch long-press. The \a link argument
  35. is an instance of QPdfLink with information about the hyperlink.
  36. */
  37. signal contextMenuRequested(var link)
  38. HoverHandler {
  39. id: linkHH
  40. cursorShape: Qt.PointingHandCursor
  41. }
  42. TapHandler {
  43. gesturePolicy: TapHandler.ReleaseWithinBounds
  44. onTapped: root.tapped(root.link)
  45. }
  46. TapHandler {
  47. acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad | PointerDevice.Stylus
  48. acceptedButtons: Qt.RightButton
  49. gesturePolicy: TapHandler.ReleaseWithinBounds
  50. onTapped: root.contextMenuRequested(root.link)
  51. }
  52. TapHandler {
  53. acceptedDevices: PointerDevice.TouchScreen
  54. onLongPressed: root.contextMenuRequested(root.link)
  55. }
  56. ToolTip {
  57. visible: linkHH.hovered
  58. delay: 1000
  59. property string destFormat: qsTr("Page %1 location %2, %3 zoom %4")
  60. text: root.page >= 0 ?
  61. destFormat.arg(root.page + 1).arg(root.location.x.toFixed(1))
  62. .arg(root.location.y.toFixed(1)).arg(root.zoom) :
  63. root.url
  64. }
  65. }