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.

79 lines
1.8KB

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