From 93af42b93da8b90c055474ff34df1e8bb5ebde1d Mon Sep 17 00:00:00 2001 From: thepra Date: Mon, 28 Aug 2017 11:07:50 +0200 Subject: [PATCH] Implementing rending area --- .gitignore | 4 ++ mainwindow.cpp | 24 +++++++ mainwindow.h | 9 +++ mainwindow.ui | 170 +++++++++++++++++++++++++++++++++++++++---------- renderarea.cpp | 25 +++++++- renderarea.h | 16 ++++- 6 files changed, 211 insertions(+), 37 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1bc216a --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ + +QtCurvesCpp.pro.user +QtCurvesCpp.pro.user.9311c87 +QtCurvesCpp.pro.user diff --git a/mainwindow.cpp b/mainwindow.cpp index f262f97..247f569 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -19,3 +19,27 @@ void MainWindow::paintEvent(QPaintEvent* event) QPainter painter{this}; painter.setBrush(QColor{26,25,25}); } + +void MainWindow::on_btnAstroid_clicked() +{ + this->ui->renderArea->setShape(RenderArea::Astroid); + this->ui->renderArea->repaint(); +} + +void MainWindow::on_btnCicloid_clicked() +{ + this->ui->renderArea->setShape(RenderArea::Cycloid); + this->ui->renderArea->repaint(); +} + +void MainWindow::on_btnHuygens_clicked() +{ + this->ui->renderArea->setShape(RenderArea::HuygensCycloid); + this->ui->renderArea->repaint(); +} + +void MainWindow::on_btnHypo_clicked() +{ + this->ui->renderArea->setShape(RenderArea::HypoCycloid); + this->ui->renderArea->repaint(); +} diff --git a/mainwindow.h b/mainwindow.h index 78d8c87..9299792 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -18,6 +18,15 @@ class MainWindow : public QMainWindow protected: void paintEvent(QPaintEvent* event) Q_DECL_OVERRIDE; + private slots: + void on_btnAstroid_clicked(); + + void on_btnCicloid_clicked(); + + void on_btnHuygens_clicked(); + + void on_btnHypo_clicked(); + private: constexpr static QWidget* root = 0; Ui::MainWindow *ui; diff --git a/mainwindow.ui b/mainwindow.ui index cc56428..b0905c4 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 800 - 600 + 690 + 602 @@ -16,9 +16,9 @@ - 26 - 25 - 25 + 11 + 10 + 10 @@ -34,18 +34,18 @@ - 26 - 25 - 25 + 11 + 10 + 10 - 26 - 25 - 25 + 11 + 10 + 10 @@ -54,9 +54,9 @@ - 26 - 25 - 25 + 11 + 10 + 10 @@ -72,18 +72,18 @@ - 26 - 25 - 25 + 11 + 10 + 10 - 26 - 25 - 25 + 11 + 10 + 10 @@ -92,9 +92,9 @@ - 26 - 25 - 25 + 11 + 10 + 10 @@ -110,18 +110,18 @@ - 26 - 25 - 25 + 11 + 10 + 10 - 26 - 25 - 25 + 11 + 10 + 10 @@ -135,21 +135,123 @@ false - background-color: rgb(26, 25, 25); + background-color: rgb(11,10,10); - background-color: rgb(26, 25, 25); + background-color: rgb(16, 15, 15); - + 10 10 - 571 - 531 + 671 + 540 + + + + + true + + splitter + + + + + + + + + 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 + + + + + + + Qt::Vertical + + + + 77 + 428 + + + + + + + diff --git a/renderarea.cpp b/renderarea.cpp index 59301a7..82d3f1c 100644 --- a/renderarea.cpp +++ b/renderarea.cpp @@ -4,7 +4,8 @@ RenderArea::RenderArea(QWidget *parent) : QWidget{parent}, mBackgroundColour{36,35,35}, - mShapeColour{251,250,250} + mShapeColour{251,250,250}, + mShape{Astroid} { } @@ -22,8 +23,28 @@ QSize RenderArea::sizeHint() const void RenderArea::paintEvent(QPaintEvent* event) { QPainter painter{this}; - painter.setBrush(mBackgroundColour); painter.setRenderHint(QPainter::Antialiasing,true); + + switch (mShape) { + case Astroid: + mBackgroundColour = Qt::red; + break; + case Cycloid: + mBackgroundColour = Qt::green; + + break; + case HuygensCycloid: + mBackgroundColour = Qt::blue; + + break; + case HypoCycloid: + mBackgroundColour = Qt::yellow; + + break; + default: + break; + } + painter.setBrush(mBackgroundColour); painter.setPen(mShapeColour); painter.drawRect(this->rect()); diff --git a/renderarea.h b/renderarea.h index c64c5c8..f6c1e74 100644 --- a/renderarea.h +++ b/renderarea.h @@ -11,6 +11,20 @@ class RenderArea : public QWidget QSize minimumSizeHint() const Q_DECL_OVERRIDE; QSize sizeHint() const Q_DECL_OVERRIDE; + + enum ShapesType{ + Astroid, + Cycloid, + HuygensCycloid, + HypoCycloid + }; + + void setBackgroundColor(QColor color) { mBackgroundColour = color; } + QColor backgroundColor() const { return mBackgroundColour; } + void setShape(ShapesType shape) { mShape = shape; } + ShapesType shape() const { return mShape; } + + signals: protected: @@ -21,6 +35,6 @@ class RenderArea : public QWidget private: QColor mBackgroundColour; QColor mShapeColour; + ShapesType mShape; }; - #endif // RENDERAREA_H