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.

pixmapbutton.py 3.5KB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Pixmap Button, a custom Qt4 widget
  4. # Copyright (C) 2013-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 QPointF, QRectF
  24. from PyQt5.QtGui import QColor, QFont, QPainter, QPixmap
  25. from PyQt5.QtWidgets import QPushButton
  26. else:
  27. from PyQt4.QtCore import QPointF, QRectF
  28. from PyQt4.QtGui import QColor, QFont, QPainter, QPixmap, QPushButton
  29. # ------------------------------------------------------------------------------------------------------------
  30. # Widget Class
  31. class PixmapButton(QPushButton):
  32. def __init__(self, parent):
  33. QPushButton.__init__(self, parent)
  34. self.fPixmapNormal = QPixmap()
  35. self.fPixmapDown = QPixmap()
  36. self.fPixmapHover = QPixmap()
  37. self.fPixmapRect = QRectF(0, 0, 0, 0)
  38. self.fIsHovered = False
  39. self.fTopText = ""
  40. self.fTopTextColor = QColor()
  41. self.fTopTextFont = QFont()
  42. self.setText("")
  43. def setPixmaps(self, normal, down, hover):
  44. self.fPixmapNormal.load(normal)
  45. self.fPixmapDown.load(down)
  46. self.fPixmapHover.load(hover)
  47. width = self.fPixmapNormal.width()
  48. height = self.fPixmapNormal.height()
  49. self.fPixmapRect = QRectF(0, 0, width, height)
  50. self.setMinimumSize(width, height)
  51. self.setMaximumSize(width, height)
  52. def setTopText(self, text, color, font):
  53. self.fTopText = text
  54. self.fTopTextColor = color
  55. self.fTopTextFont = font
  56. def enterEvent(self, event):
  57. self.fIsHovered = True
  58. QPushButton.enterEvent(self, event)
  59. def leaveEvent(self, event):
  60. self.fIsHovered = False
  61. QPushButton.leaveEvent(self, event)
  62. def paintEvent(self, event):
  63. painter = QPainter(self)
  64. event.accept()
  65. if not self.isEnabled():
  66. painter.save()
  67. painter.setOpacity(0.2)
  68. painter.drawPixmap(self.fPixmapRect, self.fPixmapNormal, self.fPixmapRect)
  69. painter.restore()
  70. elif self.isChecked() or self.isDown():
  71. painter.drawPixmap(self.fPixmapRect, self.fPixmapDown, self.fPixmapRect)
  72. elif self.fIsHovered:
  73. painter.drawPixmap(self.fPixmapRect, self.fPixmapHover, self.fPixmapRect)
  74. else:
  75. painter.drawPixmap(self.fPixmapRect, self.fPixmapNormal, self.fPixmapRect)
  76. if not self.fTopText:
  77. return
  78. painter.save()
  79. painter.setPen(self.fTopTextColor)
  80. painter.setBrush(self.fTopTextColor)
  81. painter.setFont(self.fTopTextFont)
  82. painter.drawText(QPointF(10, 16), self.fTopText)
  83. painter.restore()