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.

139 lines
5.1KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Rack List Widget, a custom Qt4 widget
  4. # Copyright (C) 2011-2014 Filipe Coelho <falktx@falktx.com>
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License as
  8. # published by the Free Software Foundation; either version 2 of
  9. # the License, or any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # For a full copy of the GNU General Public License see the doc/GPL.txt file.
  17. # ------------------------------------------------------------------------------------------------------------
  18. # Imports (Config)
  19. from carla_config import *
  20. # ------------------------------------------------------------------------------------------------------------
  21. # Imports (Global)
  22. if config_UseQt5:
  23. from PyQt5.QtCore import Qt, QSize
  24. from PyQt5.QtGui import QPainter, QPixmap
  25. from PyQt5.QtWidgets import QAbstractItemView, QFrame, QListWidget, QListWidgetItem
  26. else:
  27. from PyQt4.QtCore import Qt, QSize
  28. from PyQt4.QtGui import QAbstractItemView, QFrame, QListWidget, QListWidgetItem, QPainter, QPixmap
  29. # ------------------------------------------------------------------------------------------------------------
  30. # Imports (Custom Stuff)
  31. from carla_skin import createPluginSlot
  32. # ------------------------------------------------------------------------------------------------------------
  33. # Rack Widget item
  34. class CarlaRackItem(QListWidgetItem):
  35. kRackItemType = QListWidgetItem.UserType + 1
  36. def __init__(self, parent, pluginId, useSkins):
  37. QListWidgetItem.__init__(self, parent, self.kRackItemType)
  38. self.host = parent.host
  39. if False:
  40. # kdevelop likes this :)
  41. from carla_backend import CarlaHostMeta
  42. host = CarlaHostMeta()
  43. self.host = host
  44. # ----------------------------------------------------------------------------------------------------
  45. # Internal stuff
  46. self.fParent = parent
  47. self.fPluginId = pluginId
  48. self.fUseSkins = useSkins
  49. self.fWidget = None
  50. self.setFlags(Qt.ItemIsSelectable|Qt.ItemIsEnabled)
  51. #self.setFlags(Qt.ItemIsSelectable|Qt.ItemIsEnabled|Qt.ItemIsDragEnabled|Qt.ItemIsDropEnabled)
  52. # ----------------------------------------------------------------------------------------------------
  53. # Set-up GUI
  54. self.recreateWidget()
  55. # --------------------------------------------------------------------------------------------------------
  56. def closeEditDialog(self):
  57. self.fWidget.fEditDialog.close()
  58. def getEditDialog(self):
  59. return self.fWidget.fEditDialog
  60. def getWidget(self):
  61. return self.fWidget
  62. # --------------------------------------------------------------------------------------------------------
  63. def setPluginId(self, pluginId):
  64. self.fPluginId = pluginId
  65. self.fWidget.setPluginId(pluginId)
  66. # --------------------------------------------------------------------------------------------------------
  67. def recreateWidget(self):
  68. if self.fWidget is not None:
  69. #self.fWidget.fEditDialog.close()
  70. del self.fWidget
  71. self.fWidget = createPluginSlot(self.fParent, self.fParent.host, self.fPluginId, self.fUseSkins)
  72. self.fWidget.setFixedHeight(self.fWidget.getFixedHeight())
  73. self.setSizeHint(QSize(640, self.fWidget.getFixedHeight()))
  74. self.fParent.setItemWidget(self, self.fWidget)
  75. # ------------------------------------------------------------------------------------------------------------
  76. # Rack Widget
  77. class RackListWidget(QListWidget):
  78. def __init__(self, parent):
  79. QListWidget.__init__(self, parent)
  80. self.fSupportedExtensions = []
  81. self.fWasLastDragValid = False
  82. self.setMinimumWidth(700)
  83. self.setSelectionMode(QAbstractItemView.SingleSelection)
  84. self.setSortingEnabled(False)
  85. self.setDragEnabled(True)
  86. self.setDragDropMode(QAbstractItemView.DropOnly)
  87. self.setDropIndicatorShown(True)
  88. self.viewport().setAcceptDrops(True)
  89. self.setFrameShape(QFrame.NoFrame)
  90. self.setFrameShadow(QFrame.Plain)
  91. self.fPixmapL = QPixmap(":/bitmaps/rack_interior_left.png")
  92. self.fPixmapR = QPixmap(":/bitmaps/rack_interior_right.png")
  93. self.fPixmapWidth = self.fPixmapL.width()
  94. # --------------------------------------------------------------------------------------------------------
  95. def paintEvent(self, event):
  96. painter = QPainter(self.viewport())
  97. painter.drawTiledPixmap(0, 0, self.fPixmapWidth, self.height(), self.fPixmapL)
  98. painter.drawTiledPixmap(self.width()-self.fPixmapWidth-2, 0, self.fPixmapWidth, self.height(), self.fPixmapR)
  99. QListWidget.paintEvent(self, event)
  100. # ------------------------------------------------------------------------------------------------------------