Audio plugin host https://kx.studio/carla
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.

71 lines
2.6KB

  1. #!/usr/bin/env python3
  2. # SPDX-FileCopyrightText: 2011-2024 Filipe Coelho <falktx@falktx.com>
  3. # SPDX-License-Identifier: GPL-2.0-or-later
  4. # ------------------------------------------------------------------------------------------------------------
  5. # Imports (Global)
  6. from qt_compat import qt_config
  7. if qt_config == 5:
  8. from PyQt5.QtCore import pyqtSlot, Qt
  9. from PyQt5.QtWidgets import QFrame, QSizePolicy, QToolButton, QVBoxLayout, QWidget
  10. elif qt_config == 6:
  11. from PyQt6.QtCore import pyqtSlot, Qt
  12. from PyQt6.QtWidgets import QFrame, QSizePolicy, QToolButton, QVBoxLayout, QWidget
  13. # ------------------------------------------------------------------------------------------------------------
  14. # Widget Class
  15. class QToolButtonWithMouseTracking(QToolButton):
  16. def __init__(self, parent):
  17. QToolButton.__init__(self, parent)
  18. self._font = self.font()
  19. def enterEvent(self, event):
  20. self._font.setBold(True)
  21. self.setFont(self._font)
  22. QToolButton.enterEvent(self, event)
  23. def leaveEvent(self, event):
  24. self._font.setBold(False)
  25. self.setFont(self._font)
  26. QToolButton.leaveEvent(self, event)
  27. class CollapsibleBox(QFrame):
  28. def __init__(self, title, parent):
  29. QFrame.__init__(self, parent)
  30. self.setFrameShape(QFrame.StyledPanel)
  31. self.setFrameShadow(QFrame.Raised)
  32. self.toggle_button = QToolButtonWithMouseTracking(self)
  33. self.toggle_button.setText(title)
  34. self.toggle_button.setCheckable(True)
  35. self.toggle_button.setChecked(True)
  36. self.toggle_button.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
  37. self.toggle_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
  38. self.toggle_button.setArrowType(Qt.DownArrow)
  39. self.toggle_button.toggled.connect(self.toolButtonPressed)
  40. self.content_area = QWidget(self)
  41. self.content_layout = QVBoxLayout(self.content_area)
  42. self.content_layout.setContentsMargins(6, 2, 6, 0)
  43. self.content_layout.setSpacing(3)
  44. lay = QVBoxLayout(self)
  45. lay.setContentsMargins(0, 0, 0, 4)
  46. lay.setSpacing(1)
  47. lay.addWidget(self.toggle_button)
  48. lay.addWidget(self.content_area)
  49. @pyqtSlot(bool)
  50. def toolButtonPressed(self, toggled):
  51. self.content_area.setVisible(toggled)
  52. self.toggle_button.setArrowType(Qt.DownArrow if toggled else Qt.RightArrow)
  53. def getContentLayout(self):
  54. return self.content_layout
  55. # ------------------------------------------------------------------------------------------------------------