image picker with clipboard and drag-n-drop capability for linux.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
3.2 KiB

2 years ago
  1. import QtQuick 2.15
  2. import QtQuick.Window 2.15
  3. import QtQuick.Controls 2.15
  4. import QtQuick.Layouts 1.3
  5. import Qt.labs.folderlistmodel 2.15
  6. import QtQml.Models 2.15
  7. import "qrc:/src/widgets"
  8. Window {
  9. width: 700
  10. height: 500
  11. visible: true
  12. title: qsTr("reaction image manager")
  13. flags: Qt.Dialog
  14. id: window;
  15. Component {
  16. id: delegate
  17. Item {
  18. width: imageList.cellWidth
  19. height: imageList.cellHeight
  20. clip: true
  21. Column {
  22. anchors.fill: parent
  23. Reaction {
  24. anchors.horizontalCenter: parent.horizontalCenter
  25. path: fileUrl
  26. width: Math.min(parent.width, parent.height) - label.height
  27. height: Math.min(parent.width, parent.height) - label.height
  28. }
  29. Text {
  30. id: label
  31. anchors.horizontalCenter: parent.horizontalCenter
  32. text: fileName
  33. }
  34. }
  35. }
  36. }
  37. Column {
  38. anchors.fill: parent
  39. TextField {
  40. id: text
  41. placeholderText: qsTr("Search")
  42. focus: true
  43. height: 40
  44. width: parent.width
  45. onTextChanged: () => {
  46. backingModel.nameFilters = makeFilter(text.text)
  47. imageList.currentIndex = 0
  48. imageList.moveCurrentIndexRight()
  49. }
  50. Keys.onPressed: {
  51. if (event.key == Qt.Key_Tab || event.key == Qt.Key_Right) {
  52. event.accepted = true
  53. imageList.moveCurrentIndexRight()
  54. } else if (event.key == Qt.Key_Up) {
  55. event.accepted = true
  56. imageList.moveCurrentIndexUp()
  57. } else if (event.key == Qt.Key_Down) {
  58. event.accepted = true
  59. imageList.moveCurrentIndexDown()
  60. } else if (event.key == Qt.Key_Left) {
  61. event.accepted = true
  62. imageList.moveCurrentIndexLeft()
  63. } else if (event.key == Qt.Key_Escape) {
  64. Qt.quit()
  65. }
  66. }
  67. onAccepted: {
  68. clipboard.setClipboard(backingModel.get(imageList.currentIndex, 'fileUrl') || backingModel.get(0, 'fileUrl'));
  69. }
  70. }
  71. Row {
  72. width: parent.width
  73. height: parent.height - 40
  74. Rectangle {
  75. width: 2 * (parent.width / 3)
  76. height: parent.height
  77. GridView {
  78. id: imageList
  79. anchors.fill: parent
  80. clip: true
  81. keyNavigationWraps: true
  82. flickableDirection: Flickable.AutoFlickDirection
  83. cellWidth: parent.width / 3;
  84. cellHeight: imageList.cellWidth
  85. snapMode: GridView.SnapToRow
  86. model: FolderListModel {
  87. id: backingModel
  88. nameFilters: makeFilter("")
  89. folder: "file:" + Qt.application.arguments[1]
  90. }
  91. delegate: delegate
  92. highlight: Rectangle {
  93. color: "lightsteelblue"
  94. radius: 5
  95. }
  96. }
  97. }
  98. Reaction {
  99. width: parent.width / 3
  100. height: parent.height
  101. path: backingModel.get(imageList.currentIndex, 'fileUrl') || backingModel.get(0, 'fileUrl')
  102. }
  103. }
  104. }
  105. function makeFilter(text) {
  106. if (text.indexOf("*") !== -1) {
  107. return [text]
  108. }
  109. return [
  110. "*" + text + "*.png",
  111. "*" + text + "*.gif",
  112. "*" + text + "*.jpg",
  113. "*" + text + "*.jpeg",
  114. ]
  115. }
  116. }