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.

90 lines
2.2KB

  1. /*
  2. * LED 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. #include <QtGui/QPaintEvent>
  20. LEDButton::LEDButton(QWidget* parent):
  21. QPushButton(parent),
  22. fColor(OFF),
  23. fLastColor(OFF),
  24. fPixmapRect(0, 0, 0, 0)
  25. {
  26. setCheckable(true);
  27. setText("");
  28. setColor(BLUE);
  29. // matching fLastColor
  30. fPixmap.load(":/bitmaps/led_off.png");
  31. }
  32. void LEDButton::setColor(Color color)
  33. {
  34. fColor = color;
  35. int size = 14;
  36. fPixmapRect = QRectF(0, 0, size, size);
  37. setMinimumSize(size, size);
  38. setMaximumSize(size, size);
  39. }
  40. void LEDButton::paintEvent(QPaintEvent* event)
  41. {
  42. QPainter painter(this);
  43. event->accept();
  44. if (isChecked())
  45. {
  46. if (fLastColor != fColor)
  47. {
  48. switch (fColor)
  49. {
  50. case OFF:
  51. fPixmap.load(":/bitmaps/led_off.png");
  52. break;
  53. case BLUE:
  54. fPixmap.load(":/bitmaps/led_blue.png");
  55. break;
  56. case GREEN:
  57. fPixmap.load(":/bitmaps/led_green.png");
  58. break;
  59. case RED:
  60. fPixmap.load(":/bitmaps/led_red.png");
  61. break;
  62. case YELLOW:
  63. fPixmap.load(":/bitmaps/led_yellow.png");
  64. break;
  65. default:
  66. return;
  67. }
  68. fLastColor = fColor;
  69. }
  70. }
  71. else if (fLastColor != OFF)
  72. {
  73. fPixmap.load(":/bitmaps/led_off.png");
  74. fLastColor = OFF;
  75. }
  76. painter.drawPixmap(fPixmapRect, fPixmap, fPixmapRect);
  77. }