From 980ef0812f5992527638d7d3fb92fa1df413b5c0 Mon Sep 17 00:00:00 2001 From: Ollo Date: Tue, 15 Aug 2023 00:09:29 +0200 Subject: [PATCH] LED framebuffer connected to GUI --- simulation/VirtualLedBoard/mainwindow.cpp | 20 +++++++++++++++ simulation/VirtualLedBoard/mainwindow.h | 18 ++++++++++++++ simulation/VirtualLedBoard/mainwindow.ui | 30 +++++++++++++++++++++-- 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/simulation/VirtualLedBoard/mainwindow.cpp b/simulation/VirtualLedBoard/mainwindow.cpp index 7f7f6fa..e31bdca 100644 --- a/simulation/VirtualLedBoard/mainwindow.cpp +++ b/simulation/VirtualLedBoard/mainwindow.cpp @@ -1,12 +1,21 @@ #include "mainwindow.h" #include "ui_mainwindow.h" +#include +#include +#include +#include + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); this->server = new UdpLedServer (); + + this->mOffscreenDiagram = new QImage(DEFAULT_WIDTH, DEFAULT_HEIGHT, QImage::Format_RGB32); + this->mOffscreenDiagram->fill(COLOR_BACKGROUND); + } MainWindow::~MainWindow() @@ -14,3 +23,14 @@ MainWindow::~MainWindow() delete ui; } +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); +} + diff --git a/simulation/VirtualLedBoard/mainwindow.h b/simulation/VirtualLedBoard/mainwindow.h index fe5b0ba..b0ad118 100644 --- a/simulation/VirtualLedBoard/mainwindow.h +++ b/simulation/VirtualLedBoard/mainwindow.h @@ -2,8 +2,24 @@ #define MAINWINDOW_H #include +#include #include "udpserver.h" + +#define MAXIMUM_PANELSIZE 5 +#define PANEL_WIDTH 32 +#define PANEL_HEIGHT 40 + +#define LED_DIAMETER 5 +#define LED_DISTANCE (LED_DIAMETER + 2) + +#define DEFAULT_WIDTH (LED_DISTANCE * MAXIMUM_PANELSIZE * PANEL_WIDTH) +#define DEFAULT_HEIGHT (LED_DISTANCE * PANEL_HEIGHT) + + +#define COLOR_BACKGROUND Qt::black +#define COLOR_FOREGROUND Qt::orange + QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE @@ -19,5 +35,7 @@ public: private: Ui::MainWindow *ui; UdpLedServer *server; + QImage *mOffscreenDiagram; + void drawImage(QImage *image); }; #endif // MAINWINDOW_H diff --git a/simulation/VirtualLedBoard/mainwindow.ui b/simulation/VirtualLedBoard/mainwindow.ui index b232854..a181b2b 100644 --- a/simulation/VirtualLedBoard/mainwindow.ui +++ b/simulation/VirtualLedBoard/mainwindow.ui @@ -13,8 +13,34 @@ MainWindow - - + + + + 0 + 0 + + + + + + 10 + 0 + 781 + 441 + + + + + + + + 0 + 0 + 800 + 22 + + +