Browse Source

Implementing rending area

master
thepra 4 years ago
parent
commit
93af42b93d
  1. 4
      .gitignore
  2. 24
      mainwindow.cpp
  3. 9
      mainwindow.h
  4. 170
      mainwindow.ui
  5. 25
      renderarea.cpp
  6. 16
      renderarea.h

4
.gitignore

@ -0,0 +1,4 @@
QtCurvesCpp.pro.user
QtCurvesCpp.pro.user.9311c87
QtCurvesCpp.pro.user

24
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();
}

9
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;

170
mainwindow.ui

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
<width>690</width>
<height>602</height>
</rect>
</property>
<property name="palette">
@ -16,9 +16,9 @@
<colorrole role="Button">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>26</red>
<green>25</green>
<blue>25</blue>
<red>11</red>
<green>10</green>
<blue>10</blue>
</color>
</brush>
</colorrole>
@ -34,18 +34,18 @@
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>26</red>
<green>25</green>
<blue>25</blue>
<red>11</red>
<green>10</green>
<blue>10</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>26</red>
<green>25</green>
<blue>25</blue>
<red>11</red>
<green>10</green>
<blue>10</blue>
</color>
</brush>
</colorrole>
@ -54,9 +54,9 @@
<colorrole role="Button">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>26</red>
<green>25</green>
<blue>25</blue>
<red>11</red>
<green>10</green>
<blue>10</blue>
</color>
</brush>
</colorrole>
@ -72,18 +72,18 @@
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>26</red>
<green>25</green>
<blue>25</blue>
<red>11</red>
<green>10</green>
<blue>10</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>26</red>
<green>25</green>
<blue>25</blue>
<red>11</red>
<green>10</green>
<blue>10</blue>
</color>
</brush>
</colorrole>
@ -92,9 +92,9 @@
<colorrole role="Button">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>26</red>
<green>25</green>
<blue>25</blue>
<red>11</red>
<green>10</green>
<blue>10</blue>
</color>
</brush>
</colorrole>
@ -110,18 +110,18 @@
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>26</red>
<green>25</green>
<blue>25</blue>
<red>11</red>
<green>10</green>
<blue>10</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>26</red>
<green>25</green>
<blue>25</blue>
<red>11</red>
<green>10</green>
<blue>10</blue>
</color>
</brush>
</colorrole>
@ -135,21 +135,123 @@
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(26, 25, 25);</string>
<string notr="true">background-color: rgb(11,10,10);</string>
</property>
<widget class="QWidget" name="centralWidget">
<property name="styleSheet">
<string notr="true">background-color: rgb(26, 25, 25);</string>
<string notr="true">background-color: rgb(16, 15, 15);</string>
</property>
<widget class="RenderArea" name="renderArea" native="true">
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>571</width>
<height>531</height>
<width>671</width>
<height>540</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="RenderArea" name="renderArea" native="true">
<property name="enabled">
<bool>true</bool>
</property>
<zorder>splitter</zorder>
</widget>
</item>
<item>
<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>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>77</width>
<height>428</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<widget class="QStatusBar" name="statusBar"/>

25
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());

16
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

Loading…
Cancel
Save