Progress :D

This commit is contained in:
thepra 2017-09-09 21:43:16 +02:00
parent 1a9d8e5e7b
commit c152ff4dec
6 changed files with 440 additions and 318 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.4.0, 2017-09-05T20:42:14. -->
<!-- Written by QtCreator 4.4.0, 2017-09-06T18:37:05. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

View File

@ -1,12 +1,14 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPainter>
#include <QColorDialog>
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);
}

View File

@ -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;
};

View File

@ -6,13 +6,22 @@
<rect>
<x>0</x>
<y>0</y>
<width>670</width>
<height>612</height>
<width>669</width>
<height>611</height>
</rect>
</property>
<property name="palette">
<palette>
<active>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>251</red>
<green>250</green>
<blue>250</blue>
</color>
</brush>
</colorrole>
<colorrole role="Button">
<brush brushstyle="SolidPattern">
<color alpha="255">
@ -31,6 +40,24 @@
</color>
</brush>
</colorrole>
<colorrole role="Text">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>251</red>
<green>250</green>
<blue>250</blue>
</color>
</brush>
</colorrole>
<colorrole role="ButtonText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>251</red>
<green>250</green>
<blue>250</blue>
</color>
</brush>
</colorrole>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
@ -51,6 +78,15 @@
</colorrole>
</active>
<inactive>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>251</red>
<green>250</green>
<blue>250</blue>
</color>
</brush>
</colorrole>
<colorrole role="Button">
<brush brushstyle="SolidPattern">
<color alpha="255">
@ -69,6 +105,24 @@
</color>
</brush>
</colorrole>
<colorrole role="Text">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>251</red>
<green>250</green>
<blue>250</blue>
</color>
</brush>
</colorrole>
<colorrole role="ButtonText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>251</red>
<green>250</green>
<blue>250</blue>
</color>
</brush>
</colorrole>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
@ -89,6 +143,15 @@
</colorrole>
</inactive>
<disabled>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>251</red>
<green>250</green>
<blue>250</blue>
</color>
</brush>
</colorrole>
<colorrole role="Button">
<brush brushstyle="SolidPattern">
<color alpha="255">
@ -107,6 +170,24 @@
</color>
</brush>
</colorrole>
<colorrole role="Text">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>251</red>
<green>250</green>
<blue>250</blue>
</color>
</brush>
</colorrole>
<colorrole role="ButtonText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>251</red>
<green>250</green>
<blue>250</blue>
</color>
</brush>
</colorrole>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
@ -135,265 +216,282 @@
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(11,10,10);</string>
<string notr="true">background-color: rgb(11,10,10);
color: rgb(251, 250, 250);</string>
</property>
<widget class="QWidget" name="centralWidget">
<property name="styleSheet">
<string notr="true">background-color: rgb(16, 15, 15);</string>
</property>
<widget class="RenderArea" name="renderArea" native="true">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>11</x>
<y>11</y>
<width>491</width>
<height>481</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="btnLine_2">
<property name="geometry">
<rect>
<x>10</x>
<y>560</y>
<width>101</width>
<height>21</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="RenderArea" name="renderArea" native="true">
<property name="enabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QPushButton" name="btnBackgroundColor">
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
background-color: rgb(36, 35, 35);
border-color: rgb(255, 255, 255);</string>
</property>
<property name="text">
<string>Background colour</string>
</property>
</widget>
<widget class="QPushButton" name="btnLine_3">
<property name="geometry">
<rect>
<x>120</x>
<y>560</y>
<width>61</width>
<height>21</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
</property>
<property name="text">
<string>Background colour</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnLineColor">
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
background-color: rgb(36, 35, 35);
border-color: rgb(255, 255, 255);</string>
</property>
<property name="text">
<string> Line colour</string>
</property>
</widget>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>510</x>
<y>150</y>
<width>151</width>
<height>86</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label">
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);</string>
</property>
<property name="text">
<string>Scale</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="scaledContents">
<bool>false</bool>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="scaleInput">
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
</property>
<property name="text">
<string> Line colour</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>318</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="btnAstroid">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
background-color: rgb(36, 35, 35);
border-color: rgb(255, 255, 255);</string>
</property>
<property name="text">
<string>Astroid</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnCicloid">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
background-color: rgb(36, 35, 35);
border-color: rgb(255, 255, 255);</string>
</property>
<property name="text">
<string>Cicloid</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnHuygens">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
background-color: rgb(36, 35, 35);
border-color: rgb(255, 255, 255);</string>
</property>
<property name="text">
<string>Huygens</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnHypo">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
background-color: rgb(36, 35, 35);
border-color: rgb(255, 255, 255);</string>
</property>
<property name="text">
<string>Hypo Cycloid</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnLine">
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
background-color: rgb(36, 35, 35);
border-color: rgb(255, 255, 255);</string>
</property>
<property name="text">
<string>Line</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label">
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);</string>
</property>
<property name="text">
<string>Scale:</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="scaledContents">
<bool>false</bool>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="scaleInput">
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
background-color: rgb(36, 35, 35);</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);</string>
</property>
<property name="text">
<string>Interval lenght</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="scaledContents">
<bool>false</bool>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="intervalInput">
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
</property>
<property name="decimals">
<number>1</number>
</property>
<property name="maximum">
<double>100.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);</string>
</property>
<property name="text">
<string>Interval lenght:</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="scaledContents">
<bool>false</bool>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="intervalInput">
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
background-color: rgb(36, 35, 35);</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_3">
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);</string>
</property>
<property name="text">
<string>Step count</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="scaledContents">
<bool>false</bool>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="stepInput">
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
</property>
<property name="maximum">
<double>100.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_3">
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);</string>
</property>
<property name="text">
<string>Step count:</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="scaledContents">
<bool>false</bool>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="stepInput">
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
background-color: rgb(36, 35, 35);</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>509</x>
<y>12</y>
<width>151</width>
<height>131</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPushButton" name="btnAstroid">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
background-color: rgb(36, 35, 35);
border-color: rgb(255, 255, 255);</string>
</property>
<property name="text">
<string>Astroid</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnCicloid">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
background-color: rgb(36, 35, 35);
border-color: rgb(255, 255, 255);</string>
</property>
<property name="text">
<string>Cicloid</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnHuygens">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
background-color: rgb(36, 35, 35);
border-color: rgb(255, 255, 255);</string>
</property>
<property name="text">
<string>Huygens</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnHypo">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
background-color: rgb(36, 35, 35);
border-color: rgb(255, 255, 255);</string>
</property>
<property name="text">
<string>Hypo Cycloid</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnLine">
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
background-color: rgb(36, 35, 35);
border-color: rgb(255, 255, 255);</string>
</property>
<property name="text">
<string>Line</string>
</property>
</widget>
</item>
</layout>
</widget>
</property>
<property name="maximum">
<number>1024</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>

View File

@ -1,6 +1,47 @@
#include "renderarea.h"
#include <QPainter>
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) {

View File

@ -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: