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.2KB

12 years ago
11 years ago
12 years ago
12 years ago
12 years ago
11 years ago
12 years ago
12 years ago
11 years ago
12 years ago
11 years ago
12 years ago
12 years ago
12 years ago
11 years ago
12 years ago
12 years ago
12 years ago
11 years ago
11 years ago
12 years ago
11 years ago
12 years ago
11 years ago
12 years ago
12 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 doc/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. }