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.

ledbutton.cpp 2.3KB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Pixmap Button, a custom Qt4 widget
  3. * Copyright (C) 2011-2013 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the GPL.txt file
  16. */
  17. #include "ledbutton.hpp"
  18. #include <QtGui/QPainter>
  19. LEDButton::LEDButton(QWidget* parent):
  20. QPushButton(parent)
  21. {
  22. m_pixmap_rect = QRectF(0, 0, 0, 0);
  23. setCheckable(true);
  24. setText("");
  25. setColor(BLUE);
  26. }
  27. LEDButton::~LEDButton()
  28. {
  29. }
  30. void LEDButton::setColor(Color color)
  31. {
  32. m_color = color;
  33. int size;
  34. if (1) //color in (self.BLUE, self.GREEN, self.RED, self.YELLOW):
  35. size = 14;
  36. else if (color == BIG_RED)
  37. size = 64;
  38. else
  39. return qCritical("LEDButton::setColor(%i) - Invalid color", color);
  40. setPixmapSize(size);
  41. }
  42. void LEDButton::setPixmapSize(int size)
  43. {
  44. m_pixmap_rect = QRectF(0, 0, size, size);
  45. setMinimumWidth(size);
  46. setMaximumWidth(size);
  47. setMinimumHeight(size);
  48. setMaximumHeight(size);
  49. }
  50. void LEDButton::paintEvent(QPaintEvent*)
  51. {
  52. QPainter painter(this);
  53. if (isChecked())
  54. {
  55. if (m_color == BLUE)
  56. m_pixmap.load(":/bitmaps/led_blue.png");
  57. else if (m_color == GREEN)
  58. m_pixmap.load(":/bitmaps/led_green.png");
  59. else if (m_color == RED)
  60. m_pixmap.load(":/bitmaps/led_red.png");
  61. else if (m_color == YELLOW)
  62. m_pixmap.load(":/bitmaps/led_yellow.png");
  63. else if (m_color == BIG_RED)
  64. m_pixmap.load(":/bitmaps/led-big_on.png");
  65. else
  66. return;
  67. }
  68. else
  69. {
  70. if (1) //self.m_color in (self.BLUE, self.GREEN, self.RED, self.YELLOW):
  71. m_pixmap.load(":/bitmaps/led_off.png");
  72. else if (m_color == BIG_RED)
  73. m_pixmap.load(":/bitmaps/led-big_off.png");
  74. else
  75. return;
  76. }
  77. painter.drawPixmap(m_pixmap_rect, m_pixmap, m_pixmap_rect);
  78. }