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.

83 lines
2.7KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Pixmap Button, a custom Qt4 widget
  4. # Copyright (C) 2013 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 GPL.txt file
  17. # ------------------------------------------------------------------------------------------------------------
  18. # Imports (Global)
  19. from PyQt4.QtCore import QRectF
  20. from PyQt4.QtGui import QPainter, QPixmap, QPushButton
  21. # ------------------------------------------------------------------------------------------------------------
  22. # Widget Class
  23. class PixmapButton(QPushButton):
  24. STATE_NULL = 0
  25. STATE_NORMAL = 1
  26. STATE_DOWN = 2
  27. STATE_HOVER = 3
  28. def __init__(self, parent):
  29. QPushButton.__init__(self, parent)
  30. self.fPixmapNormal = QPixmap()
  31. self.fPixmapDown = QPixmap()
  32. self.fPixmapHover = QPixmap()
  33. self.fPixmapRect = QRectF(0, 0, 0, 0)
  34. self.fIsHovered = False
  35. self.setText("")
  36. def setPixmaps(self, normal, down, hover):
  37. self.fPixmapNormal.load(normal)
  38. self.fPixmapDown.load(down)
  39. self.fPixmapHover.load(hover)
  40. self.setPixmapSize(self.fPixmapNormal.width())
  41. def setPixmapSize(self, size):
  42. self.fPixmapRect = QRectF(0, 0, size, size)
  43. self.setMinimumWidth(size)
  44. self.setMaximumWidth(size)
  45. self.setMinimumHeight(size)
  46. self.setMaximumHeight(size)
  47. def enterEvent(self, event):
  48. self.fIsHovered = True
  49. QPushButton.enterEvent(self, event)
  50. def leaveEvent(self, event):
  51. self.fIsHovered = False
  52. QPushButton.leaveEvent(self, event)
  53. def paintEvent(self, event):
  54. painter = QPainter(self)
  55. if not self.isEnabled():
  56. painter.setOpacity(0.2)
  57. painter.drawPixmap(self.fPixmapRect, self.fPixmapNormal, self.fPixmapRect)
  58. elif self.isChecked() or self.isDown():
  59. painter.drawPixmap(self.fPixmapRect, self.fPixmapDown, self.fPixmapRect)
  60. elif self.fIsHovered:
  61. painter.drawPixmap(self.fPixmapRect, self.fPixmapHover, self.fPixmapRect)
  62. else:
  63. painter.drawPixmap(self.fPixmapRect, self.fPixmapNormal, self.fPixmapRect)
  64. event.accept()