From 41c30cdf376730a68fcda69b57b1139f143a5543 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Wed, 26 Dec 2018 19:53:20 +0100 Subject: Fix indentation and code-style. --- src/outputwindow.cc | 317 +++++++++++++++++++++++++++------------------------- 1 file changed, 167 insertions(+), 150 deletions(-) (limited to 'src/outputwindow.cc') diff --git a/src/outputwindow.cc b/src/outputwindow.cc index 498af23..815da8c 100644 --- a/src/outputwindow.cc +++ b/src/outputwindow.cc @@ -34,216 +34,233 @@ OutputWindow::OutputWindow() { - resize(1000, 1000); - - /* - QTransform t; - t.scale(0.2, 0.2); - kaiman = kaiman.transformed(t, Qt::SmoothTransformation); - */ - connect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); - timer.setSingleShot(true); - timer.start(25); - - reset(); + resize(1000, 1000); + + //QTransform t; + //t.scale(0.2, 0.2); + //kaiman = kaiman.transformed(t, Qt::SmoothTransformation); + + connect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); + timer.setSingleShot(true); + timer.start(25); + + reset(); } double OutputWindow::coordX() { - return x; + return x; } double OutputWindow::coordY() { - return y; + return y; } void OutputWindow::stopScript() { - stop = true; + stop = true; } void OutputWindow::loadPen(QString file) { - sem.acquire(); - penfile = file; - loadpen = true; + sem.acquire(); + penfile = file; + loadpen = true; } void OutputWindow::setScale(double s) { - scale = s; - sem.acquire(); + scale = s; + sem.acquire(); } void OutputWindow::setSpeed(int s) { - if(s < 1) speed = 100; - else if(s > 100) speed = 1; - else speed = 101 - s; - sem.acquire(); + if(s < 1) + { + speed = 100; + } + else if(s > 100) + { + speed = 1; + } + else + { + speed = 101 - s; + } + sem.acquire(); } void OutputWindow::setColour(int r, int g, int b, int a) { - colour = QColor(r, g, b, a); - sem.acquire(); + colour = QColor(r, g, b, a); + sem.acquire(); } void OutputWindow::timeout() { - /* - x++; - y++; - r++; - */ - repaint(); - timer.start(25); + //x++; + //y++; + //r++; + repaint(); + timer.start(25); } void OutputWindow::paintEvent(QPaintEvent *) { - // sem.acquire(); - QPainter p(this); - // QTransform tp; tp.scale(3, 3); p.setTransform(tp); - - if(loadpen) { - QPixmap img(penfile); - kaiman = img.toImage(); - loadpen = false; - } - - QTransform t; - t.rotate(-r + 90); - t.scale((100.0 / kaiman.width() * scale), - (100.0 / kaiman.width() * scale) ); - QImage img = kaiman.transformed(t, Qt::SmoothTransformation); - p.drawImage((x * scale) - img.width()/2 + width() / 2, - (y * scale) - img.height()/2 + height() / 2, img); - - QTransform gt; - gt.translate(width() / 2, height() / 2); - gt.scale(scale, scale); - p.setTransform(gt); - - QPen pen; - pen.setWidth(4); - /* - p.setPen(pen); - p.drawLines(points); - */ - for(int i = 0; i < lines.size(); i++) { - ColLine l = lines[i]; - pen.setColor(l.colour); - p.setPen(pen); - QLineF line = l.line; - line.setP1(line.p1()); - line.setP2(line.p2()); - p.drawLine(line); - } - - pen.setWidth(2); - pen.setStyle(Qt::DotLine); - // pen.setCapStyle(Qt::RoundCap); - pen.setColor(Qt::black); - - // pen.setColor(colour); - p.setPen(pen); - for(int i = 0; i < current_points.size(); i+=2) { - QPointF p1 = current_points[i]; - QPointF p2 = current_points[i + 1]; - p.drawLine(QLineF(p1, p2)); - } - - QColor c = colour; - c.setAlpha(c.alpha() / 4); - pen.setStyle(Qt::SolidLine); - pen.setWidth(4); - pen.setColor(c); - p.setPen(pen); - for(int i = 0; i < current_points.size(); i+=2) { - QPointF p1 = current_points[i]; - QPointF p2 = current_points[i + 1]; - p.drawLine(QLineF(p1, p2)); - } - - sem.release(); + //sem.acquire(); + QPainter p(this); + //QTransform tp; tp.scale(3, 3); p.setTransform(tp); + + if(loadpen) + { + QPixmap img(penfile); + kaiman = img.toImage(); + loadpen = false; + } + + QTransform t; + t.rotate(-r + 90); + t.scale((100.0 / kaiman.width() * scale), + (100.0 / kaiman.width() * scale) ); + QImage img = kaiman.transformed(t, Qt::SmoothTransformation); + p.drawImage((x * scale) - img.width()/2 + width() / 2, + (y * scale) - img.height()/2 + height() / 2, img); + + QTransform gt; + gt.translate(width() / 2, height() / 2); + gt.scale(scale, scale); + p.setTransform(gt); + + QPen pen; + pen.setWidth(4); + //p.setPen(pen); + //p.drawLines(points); + for(int i = 0; i < lines.size(); i++) + { + ColLine l = lines[i]; + pen.setColor(l.colour); + p.setPen(pen); + QLineF line = l.line; + line.setP1(line.p1()); + line.setP2(line.p2()); + p.drawLine(line); + } + + pen.setWidth(2); + pen.setStyle(Qt::DotLine); + // pen.setCapStyle(Qt::RoundCap); + pen.setColor(Qt::black); + + // pen.setColor(colour); + p.setPen(pen); + for(int i = 0; i < current_points.size(); i+=2) + { + QPointF p1 = current_points[i]; + QPointF p2 = current_points[i + 1]; + p.drawLine(QLineF(p1, p2)); + } + + QColor c = colour; + c.setAlpha(c.alpha() / 4); + pen.setStyle(Qt::SolidLine); + pen.setWidth(4); + pen.setColor(c); + p.setPen(pen); + for(int i = 0; i < current_points.size(); i+=2) + { + QPointF p1 = current_points[i]; + QPointF p2 = current_points[i + 1]; + p.drawLine(QLineF(p1, p2)); + } + + sem.release(); } void OutputWindow::reset() { - scale = 2.0; - speed = 50; - penfile = "gfx/kaiman.png"; - loadpen = true; - - lines.clear(); - current_points.clear(); - x = 0;//(width() / 2) / scale; - y = 0;//(height() / 2) / scale; - r = 0; - colour = QColor(150, 0, 0, 150); - stop = false; - while(sem.tryAcquire()) {} + scale = 2.0; + speed = 50; + penfile = "gfx/kaiman.png"; + loadpen = true; + + lines.clear(); + current_points.clear(); + x = 0;//(width() / 2) / scale; + y = 0;//(height() / 2) / scale; + r = 0; + colour = QColor(150, 0, 0, 150); + stop = false; + while(sem.tryAcquire()) + { + } } static inline int sign(int x) { - if(x > 0) return 1; - return -1; + if(x > 0) + { + return 1; + } + return -1; } void OutputWindow::forward(double dist) { - sem.acquire(); + sem.acquire(); - float target_x = sin(r * (M_PI / 180.0)) * dist; - float target_y = cos(r * (M_PI / 180.0)) * dist; + float target_x = sin(r * (M_PI / 180.0)) * dist; + float target_y = cos(r * (M_PI / 180.0)) * dist; - float source_x = x; - float source_y = y; - - int spd = abs(dist * speed) / 60;//28; - for(int i = 0; i < spd; i++) { - if(stop) return; - float d = (float)i / (float)spd; + float source_x = x; + float source_y = y; - current_points.clear(); - current_points.append(QPointF(source_x, source_y)); + int spd = abs(dist * speed) / 60;//28; + for(int i = 0; i < spd; i++) + { + if(stop) return; + float d = (float)i / (float)spd; - x = source_x * (1 - d) + (source_x + target_x) * d; - y = source_y * (1 - d) + (source_y + target_y) * d; + current_points.clear(); + current_points.append(QPointF(source_x, source_y)); - current_points.append(QPointF(x, y)); + x = source_x * (1 - d) + (source_x + target_x) * d; + y = source_y * (1 - d) + (source_y + target_y) * d; - sem.acquire(); - } - x = source_x + target_x; - y = source_y + target_y; + current_points.append(QPointF(x, y)); - ColLine l; - l.colour = colour; - l.line = QLine(QPoint(source_x, source_y), - QPoint(x, y)); - lines.append(l); + sem.acquire(); + } + x = source_x + target_x; + y = source_y + target_y; + ColLine l; + l.colour = colour; + l.line = QLine(QPoint(source_x, source_y), + QPoint(x, y)); + lines.append(l); - current_points.clear(); - sem.acquire(); + current_points.clear(); + sem.acquire(); } // Turn x degrees void OutputWindow::turn(double x) { - double spd = (speed * abs(x) / 80.0); - double offset = this->r; - sem.acquire(); - for(int i = 0; i < spd; i++) { - if(stop) return; - double p = (double)i / spd; - this->r = offset + x * p; - sem.acquire(); - } - this->r = offset + x; - sem.acquire(); + double spd = (speed * abs(x) / 80.0); + double offset = this->r; + sem.acquire(); + for(int i = 0; i < spd; i++) + { + if(stop) + { + return; + } + double p = (double)i / spd; + this->r = offset + x * p; + sem.acquire(); + } + this->r = offset + x; + sem.acquire(); } -- cgit v1.2.3