FluColorPicker.qml 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import QtQuick
  2. import QtQuick.Controls
  3. import QtQuick.Controls.Basic
  4. import QtQuick.Layouts
  5. import QtQuick.Window
  6. import FluentUI
  7. Button{
  8. id:control
  9. width: 36
  10. height: 36
  11. implicitWidth: width
  12. implicitHeight: height
  13. background:
  14. Rectangle{
  15. id:layout_color
  16. radius: 5
  17. color: container.colorValue
  18. border.color: {
  19. if(hovered)
  20. return FluTheme.primaryColor.light
  21. return FluTheme.dark ? Qt.rgba(45/255,45/255,45/255,1) : Qt.rgba(226/255,229/255,234/255,1)
  22. }
  23. border.width: 1
  24. }
  25. contentItem: Item{}
  26. onClicked: {
  27. popup.showPopup()
  28. }
  29. Menu{
  30. id:popup
  31. modal: true
  32. dim:false
  33. height: container.height
  34. width: container.width
  35. contentItem: Item{
  36. clip: true
  37. FluColorView{
  38. id:container
  39. }
  40. }
  41. background:Item{
  42. FluShadow{
  43. radius: 5
  44. }
  45. }
  46. enter: Transition {
  47. reversible: true
  48. NumberAnimation {
  49. property: "opacity"
  50. from:0
  51. to:1
  52. duration: 83
  53. }
  54. }
  55. exit:Transition {
  56. NumberAnimation {
  57. property: "opacity"
  58. from:1
  59. to:0
  60. duration: 83
  61. }
  62. }
  63. function showPopup() {
  64. var pos = control.mapToItem(null, 0, 0)
  65. if(window.height>pos.y+control.height+container.height){
  66. popup.y = control.height
  67. } else if(pos.y>container.height){
  68. popup.y = -container.height
  69. } else {
  70. popup.y = window.height-(pos.y+container.height)
  71. }
  72. popup.x = -(popup.width-control.width)/2
  73. popup.open()
  74. }
  75. }
  76. }