2023-08-13 22:12:38 +02:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "ui_mainwindow.h"
|
|
|
|
|
2023-08-15 00:09:29 +02:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QGraphicsPixmapItem>
|
|
|
|
#include <QGraphicsView>
|
|
|
|
|
2023-08-13 22:12:38 +02:00
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
|
|
: QMainWindow(parent)
|
|
|
|
, ui(new Ui::MainWindow)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2023-08-14 13:53:34 +02:00
|
|
|
this->server = new UdpLedServer ();
|
2023-08-15 00:09:29 +02:00
|
|
|
|
2023-08-15 12:57:46 +02:00
|
|
|
this->mOffscreenPanel = new QImage(DEFAULT_WIDTH + LED_DISTANCE, DEFAULT_HEIGHT + LED_DISTANCE, QImage::Format_RGB32);
|
2023-08-15 14:38:39 +02:00
|
|
|
for(int x=0; x < (PANEL_WIDTH * MAXIMUM_PANELSIZE); x++) {
|
|
|
|
for(int y=0; y < PANEL_HEIGHT; y++) {
|
|
|
|
setLED(x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updatePanel();
|
2023-08-13 22:12:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2023-08-15 00:09:29 +02:00
|
|
|
void MainWindow::drawImage(QImage *target) {
|
|
|
|
QGraphicsView *graphicsView = new QGraphicsView();
|
|
|
|
graphicsView->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
|
|
|
|
QGraphicsScene* scene=new QGraphicsScene() ;
|
|
|
|
graphicsView->setScene(scene);
|
|
|
|
QGraphicsPixmapItem* item = new QGraphicsPixmapItem(QPixmap::fromImage(*(target)));
|
|
|
|
scene->addItem(item);
|
|
|
|
graphicsView->show();
|
|
|
|
this->ui->ledPanel->addWidget(graphicsView);
|
|
|
|
}
|
|
|
|
|
2023-08-15 12:57:46 +02:00
|
|
|
|
2023-08-15 14:38:39 +02:00
|
|
|
void MainWindow::setLED(uint8_t x, uint8_t y) {
|
2023-08-15 12:57:46 +02:00
|
|
|
/* draw inital screen */
|
|
|
|
QPainter painter(this->mOffscreenPanel);
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
|
|
|
painter.setPen(QPen(COLOR_FOREGROUND, 1));
|
|
|
|
painter.setBrush(COLOR_FOREGROUND);
|
2023-08-15 14:38:39 +02:00
|
|
|
painter.drawEllipse(LED_DIAMETER/2 + (x* LED_DISTANCE), LED_DIAMETER/2 + (y * LED_DISTANCE), LED_DIAMETER, LED_DIAMETER);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::updatePanel(void) {
|
|
|
|
this->drawImage(this->mOffscreenPanel);
|
|
|
|
this->renderPanel();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::renderPanel(void) {
|
|
|
|
this->mOffscreenPanel->fill(COLOR_BACKGROUND);
|
2023-08-15 12:57:46 +02:00
|
|
|
}
|