#include #include #include #include #include "Sheet.h" #include "VisualizationWiew.h" VisualizationWiew::VisualizationWiew(QWidget *parent) : QWidget(parent) { this->refreshTimer = new QTimer(this); this->refreshTimer->setInterval(1000); this->connect( this->refreshTimer, SIGNAL(timeout()), this, SLOT(update()) ); this->connect( this->refreshTimer, &QTimer::timeout, this, &VisualizationWiew::refreshed ); } void VisualizationWiew::paintEvent(QPaintEvent* event) { // Adapted from https://www.youtube.com/watch?v=yz7cMHKbZSc QWidget::paintEvent(event); printf("paint rect(%d,%d %d,%d)\n" , event->rect().x(), event->rect().y() , event->rect().width(), event->rect().height() ); fflush(stdout); // Fill an image sampling from the data source QImage image( size(), QImage::Format_ARGB32_Premultiplied ); // If there is a data source if ( this->sheet ) { // Get an image representing the temperatures of the sheet this->sheet->fillImage(image); } // Paint the image into this widget QPainter painter(this); painter.drawImage(0, 0, image); } void VisualizationWiew::setRefreshRateText(const QString& millisecondsText) { // Convert the given text to an int bool ok = true; int milliseconds = millisecondsText.toInt(&ok); // If the text is a number, set is as the refresh rate if ( ok ) this->setRefreshRate(milliseconds); } void VisualizationWiew::setRefreshRate(int milliseconds) { if ( milliseconds >= 0 ) this->refreshTimer->setInterval(milliseconds); } void VisualizationWiew::setSheet(Sheet* sheet) { this->sheet = sheet; this->repaint(); } void VisualizationWiew::start(double epsilon) { Q_ASSERT(this->sheet); this->refreshTimer->start(); this->sheet->startSimulation(epsilon); } void VisualizationWiew::stop() { this->refreshTimer->stop(); this->sheet->stopSimulation(); }