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.

80 lines
2.6KB

  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.setMinimumSize(size, size)
  44. self.setMaximumSize(size, size)
  45. def enterEvent(self, event):
  46. self.fIsHovered = True
  47. QPushButton.enterEvent(self, event)
  48. def leaveEvent(self, event):
  49. self.fIsHovered = False
  50. QPushButton.leaveEvent(self, event)
  51. def paintEvent(self, event):
  52. painter = QPainter(self)
  53. event.accept()
  54. if not self.isEnabled():
  55. painter.setOpacity(0.2)
  56. painter.drawPixmap(self.fPixmapRect, self.fPixmapNormal, self.fPixmapRect)
  57. elif self.isChecked() or self.isDown():
  58. painter.drawPixmap(self.fPixmapRect, self.fPixmapDown, self.fPixmapRect)
  59. elif self.fIsHovered:
  60. painter.drawPixmap(self.fPixmapRect, self.fPixmapHover, self.fPixmapRect)
  61. else:
  62. painter.drawPixmap(self.fPixmapRect, self.fPixmapNormal, self.fPixmapRect)