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.

172 lines
3.9 KiB

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