From c152ff4dec97200878c3b8e04c284cba19a52830 Mon Sep 17 00:00:00 2001 From: thepra Date: Sat, 9 Sep 2017 21:43:16 +0200 Subject: [PATCH] Progress :D --- QtCurvesCpp.pro.user | 2 +- mainwindow.cpp | 42 ++- mainwindow.h | 7 +- mainwindow.ui | 596 +++++++++++++++++++++++++------------------ renderarea.cpp | 96 +++---- renderarea.h | 15 +- 6 files changed, 440 insertions(+), 318 deletions(-) diff --git a/QtCurvesCpp.pro.user b/QtCurvesCpp.pro.user index f70bc67..a5e36ca 100644 --- a/QtCurvesCpp.pro.user +++ b/QtCurvesCpp.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/mainwindow.cpp b/mainwindow.cpp index dd517a0..32c0bc1 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,12 +1,14 @@ #include "mainwindow.h" #include "ui_mainwindow.h" #include +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); + UpdateUi(); } MainWindow::~MainWindow() @@ -14,6 +16,13 @@ MainWindow::~MainWindow() delete ui; } +void MainWindow::UpdateUi() +{ + this->ui->scaleInput->setValue(this->ui->renderArea->scale()); + this->ui->intervalInput->setValue(this->ui->renderArea->intervalLenght()); + this->ui->stepInput->setValue(this->ui->renderArea->stepCount()); +} + void MainWindow::paintEvent(QPaintEvent* event) { QPainter painter{this}; @@ -24,46 +33,61 @@ void MainWindow::on_btnAstroid_clicked() { this->ui->renderArea->setShape(RenderArea::Astroid); this->ui->renderArea->repaint(); + UpdateUi(); } void MainWindow::on_btnCicloid_clicked() { this->ui->renderArea->setShape(RenderArea::Cycloid); this->ui->renderArea->repaint(); + UpdateUi(); } void MainWindow::on_btnHuygens_clicked() { this->ui->renderArea->setShape(RenderArea::HuygensCycloid); this->ui->renderArea->repaint(); + UpdateUi(); } void MainWindow::on_btnHypo_clicked() { this->ui->renderArea->setShape(RenderArea::HypoCycloid); this->ui->renderArea->repaint(); + UpdateUi(); } void MainWindow::on_btnLine_clicked() { this->ui->renderArea->setShape(RenderArea::Line); this->ui->renderArea->repaint(); + UpdateUi(); } -void MainWindow::on_intervalInput_valueChanged(double arg1) +void MainWindow::on_intervalInput_valueChanged(double interval) { - this->ui->renderArea->setInternalLenght(arg1); - this->ui->renderArea->repaint(); + this->ui->renderArea->setInternalLenght(interval); } -void MainWindow::on_scaleInput_valueChanged(double arg1) +void MainWindow::on_scaleInput_valueChanged(double scale) { - this->ui->renderArea->setScale(arg1); - this->ui->renderArea->repaint(); + this->ui->renderArea->setScale(scale); } -void MainWindow::on_stepInput_valueChanged(double arg1) +void MainWindow::on_stepInput_valueChanged(int count) { - this->ui->renderArea->setStepCount(arg1); - this->ui->renderArea->repaint(); + this->ui->renderArea->setStepCount(count); +} + + +void MainWindow::on_btnBackgroundColor_clicked() +{ + auto color{QColorDialog::getColor(this->ui->renderArea->backgroundColor(),this,"Select Color")}; + ui->renderArea->setBackgroundColor(color); +} + +void MainWindow::on_btnLineColor_clicked() +{ + auto color{QColorDialog::getColor(this->ui->renderArea->shapeColor(),this,"Select Color")}; + ui->renderArea->setShapeColor(color); } diff --git a/mainwindow.h b/mainwindow.h index c245bb4..4336790 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -33,9 +33,14 @@ class MainWindow : public QMainWindow void on_scaleInput_valueChanged(double arg1); - void on_stepInput_valueChanged(double arg1); + void on_stepInput_valueChanged(int arg1); + + void on_btnBackgroundColor_clicked(); + + void on_btnLineColor_clicked(); private: + void UpdateUi(); constexpr static QWidget* root = 0; Ui::MainWindow *ui; }; diff --git a/mainwindow.ui b/mainwindow.ui index 72c444f..0b342c6 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -6,13 +6,22 @@ 0 0 - 670 - 612 + 669 + 611 + + + + 251 + 250 + 250 + + + @@ -31,6 +40,24 @@ + + + + 251 + 250 + 250 + + + + + + + 251 + 250 + 250 + + + @@ -51,6 +78,15 @@ + + + + 251 + 250 + 250 + + + @@ -69,6 +105,24 @@ + + + + 251 + 250 + 250 + + + + + + + 251 + 250 + 250 + + + @@ -89,6 +143,15 @@ + + + + 251 + 250 + 250 + + + @@ -107,6 +170,24 @@ + + + + 251 + 250 + 250 + + + + + + + 251 + 250 + 250 + + + @@ -135,265 +216,282 @@ false - background-color: rgb(11,10,10); + background-color: rgb(11,10,10); +color: rgb(251, 250, 250); background-color: rgb(16, 15, 15); - - - true - - - - 11 - 11 - 491 - 481 - - - - - - - 10 - 560 - 101 - 21 - - - - color: rgb(255, 255, 255); + + + + + + + true + + + + + + + + + color: rgb(255, 255, 255); background-color: rgb(36, 35, 35); border-color: rgb(255, 255, 255); - - - Background colour - - - - - - 120 - 560 - 61 - 21 - - - - color: rgb(255, 255, 255); + + + Background colour + + + + + + + color: rgb(255, 255, 255); background-color: rgb(36, 35, 35); border-color: rgb(255, 255, 255); - - - Line colour - - - - - - 510 - 150 - 151 - 86 - - - - - - - - - color: rgb(255, 255, 255); - - - Scale - - - Qt::PlainText - - - false - - - Qt::AlignCenter - - - - - - - color: rgb(255, 255, 255); + + + Line colour + + + + + + + Qt::Horizontal + + + + 318 + 20 + + + + + + + + + + + + + + + 0 + 0 + + + + color: rgb(255, 255, 255); +background-color: rgb(36, 35, 35); +border-color: rgb(255, 255, 255); + + + Astroid + + + false + + + + + + + + 0 + 0 + + + + color: rgb(255, 255, 255); +background-color: rgb(36, 35, 35); +border-color: rgb(255, 255, 255); + + + Cicloid + + + + + + + + 0 + 0 + + + + color: rgb(255, 255, 255); +background-color: rgb(36, 35, 35); +border-color: rgb(255, 255, 255); + + + Huygens + + + + + + + + 0 + 0 + + + + color: rgb(255, 255, 255); +background-color: rgb(36, 35, 35); +border-color: rgb(255, 255, 255); + + + Hypo Cycloid + + + + + + + color: rgb(255, 255, 255); +background-color: rgb(36, 35, 35); +border-color: rgb(255, 255, 255); + + + Line + + + + + + + + + color: rgb(255, 255, 255); + + + Scale: + + + Qt::PlainText + + + false + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + color: rgb(255, 255, 255); background-color: rgb(36, 35, 35); - - - - - - - - - - - color: rgb(255, 255, 255); - - - Interval lenght - - - Qt::PlainText - - - false - - - Qt::AlignCenter - - - - - - - color: rgb(255, 255, 255); + + + 1 + + + 100.000000000000000 + + + 0.100000000000000 + + + + + + + + + + + color: rgb(255, 255, 255); + + + Interval lenght: + + + Qt::PlainText + + + false + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + color: rgb(255, 255, 255); background-color: rgb(36, 35, 35); - - - - - - - - - - - color: rgb(255, 255, 255); - - - Step count - - - Qt::PlainText - - - false - - - Qt::AlignCenter - - - - - - - color: rgb(255, 255, 255); + + + 100.000000000000000 + + + 0.100000000000000 + + + + + + + + + + + color: rgb(255, 255, 255); + + + Step count: + + + Qt::PlainText + + + false + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + color: rgb(255, 255, 255); background-color: rgb(36, 35, 35); - - - - - - - - - - - 509 - 12 - 151 - 131 - - - - - - - - 0 - 0 - - - - color: rgb(255, 255, 255); -background-color: rgb(36, 35, 35); -border-color: rgb(255, 255, 255); - - - Astroid - - - false - - - - - - - - 0 - 0 - - - - color: rgb(255, 255, 255); -background-color: rgb(36, 35, 35); -border-color: rgb(255, 255, 255); - - - Cicloid - - - - - - - - 0 - 0 - - - - color: rgb(255, 255, 255); -background-color: rgb(36, 35, 35); -border-color: rgb(255, 255, 255); - - - Huygens - - - - - - - - 0 - 0 - - - - color: rgb(255, 255, 255); -background-color: rgb(36, 35, 35); -border-color: rgb(255, 255, 255); - - - Hypo Cycloid - - - - - - - color: rgb(255, 255, 255); -background-color: rgb(36, 35, 35); -border-color: rgb(255, 255, 255); - - - Line - - - - - + + + 1024 + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + diff --git a/renderarea.cpp b/renderarea.cpp index 37c7db9..45b636f 100644 --- a/renderarea.cpp +++ b/renderarea.cpp @@ -1,6 +1,47 @@ #include "renderarea.h" #include +QSize RenderArea::minimumSizeHint() const +{ + return QSize{491,481}; +} + +QSize RenderArea::sizeHint() const +{ + return QSize{491,481}; +} + +void RenderArea::paintEvent(QPaintEvent* event) +{ + Q_UNUSED(event); + QPainter painter{this}; + painter.setRenderHint(QPainter::Antialiasing,true); + + painter.setBrush(mBackgroundColour); + painter.setPen(mShapeColour); + + painter.drawRect(this->rect()); + + QPointF prevPoint{Compute(0)}; + QPoint center{this->rect().center()},prevPixel; + prevPixel.setX(prevPoint.x() * mScale + center.x()); + prevPixel.setY(prevPoint.y() * mScale + center.y()); + + double step{ mIntervalLenght / mStepCount }; + + for(double t{0}; t < mIntervalLenght; t += step){ + QPointF point = Compute(t); + + QPoint pixel{}; + pixel.setX(point.x() * mScale + center.x()); + pixel.setY(point.y() * mScale + center.y()); + + painter.drawLine(pixel, prevPixel); + + prevPixel=pixel; + } +} + RenderArea::RenderArea(QWidget *parent) : QWidget{parent}, mBackgroundColour{36,35,35}, @@ -46,61 +87,6 @@ QPointF RenderArea::ComputeLine(double t) return QPointF{1-t,1-t}; } -QSize RenderArea::minimumSizeHint() const -{ - return QSize(100,100); -} - -QSize RenderArea::sizeHint() const -{ - return QSize(400,200); -} - -void RenderArea::setInternalLenght(double l) -{ - mIntervalLenght = l; -} - -void RenderArea::setScale(double s) -{ - mScale = s; -} - -void RenderArea::setStepCount(double s) -{ - mStepCount = s; -} - -void RenderArea::paintEvent(QPaintEvent* event) -{ - QPainter painter{this}; - painter.setRenderHint(QPainter::Antialiasing,true); - - painter.setBrush(mBackgroundColour); - painter.setPen(mShapeColour); - - painter.drawRect(this->rect()); - - QPointF prevPoint{Compute(0)}; - QPoint center{this->rect().center()},prevPixel; - prevPixel.setX(prevPoint.x() * mScale + center.x()); - prevPixel.setY(prevPoint.y() * mScale + center.y()); - - double step{ mIntervalLenght / mStepCount }; - - for(float t = 0; t < mIntervalLenght; t += step){ - QPointF point = Compute(t); - - QPoint pixel; - pixel.setX(point.x() * mScale + center.x()); - pixel.setY(point.y() * mScale + center.y()); - - painter.drawLine(pixel, prevPixel); - - prevPixel=pixel; - } -} - void RenderArea::OnShapeChanged() { switch (mShape) { diff --git a/renderarea.h b/renderarea.h index 6718a2d..b5a9a45 100644 --- a/renderarea.h +++ b/renderarea.h @@ -22,12 +22,21 @@ class RenderArea : public QWidget void setBackgroundColor(QColor color) { mBackgroundColour = color; } QColor backgroundColor() const { return mBackgroundColour; } + + void setShapeColor(QColor color) { mShapeColour = color; } + QColor shapeColor() const { return mShapeColour; } + void setShape(ShapesType shape) { mShape = shape; OnShapeChanged(); } ShapesType shape() const { return mShape; } - void setInternalLenght(double l); - void setScale(double s); - void setStepCount(double s); + void setInternalLenght(double l){mIntervalLenght=l;repaint();} + double intervalLenght() const {return mIntervalLenght;} + + void setScale(double s){mScale=s;repaint();} + double scale() const {return mScale;} + + void setStepCount(int s){mStepCount=s;repaint();} + int stepCount() const {return mStepCount;} signals: