Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef LEDPANEL_HPP
- #define LEDPANEL_HPP
- #include <QWidget>
- #include <cassert>
- #include <QPainter>
- class LedPanel : public QWidget
- {
- Q_OBJECT
- public:
- LedPanel(QWidget *parent = 0)
- : QWidget(parent)
- {
- for (int x = 0; x < 32; ++x)
- {
- for (int y = 0; y < 8; ++y)
- {
- states[y][x] = false;
- }
- }
- }
- void on(unsigned int x, unsigned int y)
- {
- assert(x < 32);
- assert(y < 8);
- states[y][x] = true;
- }
- protected:
- void paintEvent(QPaintEvent*) override
- {
- QPainter painter(this);
- // Background
- QBrush background(QColor(23, 23, 34));
- painter.setBrush(background);
- painter.drawRect(0, 0, width(), height());
- // LED
- int w = width() / 32;
- int h = height() / 8;
- for (int x = 0; x < 32; ++x)
- {
- for (int y = 0; y < 8; ++y)
- {
- if (states[y][x])
- {
- QBrush led(QColor(0, 125, 110));
- painter.setBrush(led);
- QRect rect(x*w, y*h, w, h);
- painter.drawRect(rect);
- }
- }
- }
- }
- private:
- bool states[8][32]; // 8 lines of 32 LEDs each
- };
- #endif // LEDPANEL_HPP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement