commit b9f62b20e5bfc769cb8917241986bdf75312826b Author: Hello-User <20123493@student.hhs.nl> Date: Thu Feb 10 17:44:22 2022 +0100 init diff --git a/deur.cpp b/deur.cpp new file mode 100644 index 0000000..640164d --- /dev/null +++ b/deur.cpp @@ -0,0 +1,29 @@ +#include "deur.h" +#include + +Deur::Deur(int x, int y, int lengte): x_coordinaat(x), y_coordinaat(y), lengte(lengte){ + +} + +pair Deur::coordinaten() const { + pair temp; + temp.first=x_coordinaat; + temp.second=y_coordinaat; + return temp; +} + +void Deur::open(){ + status = true; +} + +void Deur::sluit(){ + status = false; +} + +bool Deur::isDeurOpen(){ + return status; +} + +unsigned int Deur::deurLengte(){ + return lengte; +} diff --git a/deur.h b/deur.h new file mode 100644 index 0000000..a8e595b --- /dev/null +++ b/deur.h @@ -0,0 +1,25 @@ +#ifndef DEUR_H +#define DEUR_H + +#include +#include + +using namespace std; + +class Deur +{ +private: + bool status; + int x_coordinaat, y_coordinaat; + unsigned lengte; +public: + void open(); + void sluit(); + virtual void teken(QPaintDevice*) = 0; + bool isDeurOpen(); + unsigned int deurLengte(); + std::pair coordinaten() const; + Deur(int, int, int); +}; + +#endif // DEUR_H diff --git a/draaideur.cpp b/draaideur.cpp new file mode 100644 index 0000000..fec764c --- /dev/null +++ b/draaideur.cpp @@ -0,0 +1,23 @@ +#include "draaideur.h" +#include +#include +#include + +Draaideur::Draaideur(int x, int y, int lengte): Deur(x,y,lengte){ + +} + +void Draaideur::teken(QPaintDevice* tp){ + QPainter p(tp); + QColor kleur; + p.setBrush(Qt::SolidPattern); + if(isDeurOpen()) + kleur=Qt::blue; + else + kleur=Qt::yellow; + + p.setBrush(kleur); + QPen pen(kleur,2,Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); + p.setPen(pen); + p.drawEllipse(coordinaten().first,coordinaten().second,20,20); +} diff --git a/draaideur.h b/draaideur.h new file mode 100644 index 0000000..250a02a --- /dev/null +++ b/draaideur.h @@ -0,0 +1,16 @@ +#ifndef DRAAIDEUR_H +#define DRAAIDEUR_H + +#include "deur.h" + +class QPaintDevice; + +class Draaideur : public Deur{ +private: + bool liggend; +public: + Draaideur(int, int, int); + void teken(QPaintDevice*); +}; + +#endif // DRAAIDEUR_H diff --git a/gebouw.pro b/gebouw.pro new file mode 100644 index 0000000..9afb0ab --- /dev/null +++ b/gebouw.pro @@ -0,0 +1,41 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2017-01-31T22:51:32 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = gebouw +TEMPLATE = app + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which as been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + + +SOURCES += main.cpp\ + deur.cpp \ + draaideur.cpp \ + hallsensor.cpp \ + mainwindow.cpp \ + schuifdeur.cpp \ + sensor.cpp + +HEADERS += mainwindow.h \ + deur.h \ + draaideur.h \ + hallsensor.h \ + schuifdeur.h \ + sensor.h + +FORMS += mainwindow.ui diff --git a/hallsensor.cpp b/hallsensor.cpp new file mode 100644 index 0000000..8238163 --- /dev/null +++ b/hallsensor.cpp @@ -0,0 +1,23 @@ +#include "hallsensor.h" +#include +#include +#include + +Hallsensor::Hallsensor(int x, int y): Sensor(x, y){ + +} + +void Hallsensor::teken(QPaintDevice *tp){ + QPainter p(tp); + QColor kleur; + p.setBrush(Qt::SolidPattern); + if(isGeactiveerd()) + kleur=Qt::blue; + else + kleur=Qt::yellow; + + p.setBrush(kleur); + QPen pen(kleur,2,Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); + p.setPen(pen); + p.drawEllipse(coordinaten().first,coordinaten().second,20,20); +} diff --git a/hallsensor.h b/hallsensor.h new file mode 100644 index 0000000..12e2c01 --- /dev/null +++ b/hallsensor.h @@ -0,0 +1,15 @@ +#ifndef HALLSENSOR_H +#define HALLSENSOR_H + +#include +#include "sensor.h" + +class QPaintDevice; + +class Hallsensor: public Sensor{ +public: + Hallsensor(int, int); + virtual void teken(QPaintDevice*); +}; + +#endif // HALLSENSOR_H diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..b48f94e --- /dev/null +++ b/main.cpp @@ -0,0 +1,11 @@ +#include "mainwindow.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..788e970 --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,51 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include +#include "sensor.h" +#include "hallsensor.h" +#include "schuifdeur.h" + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow){ + ui->setupUi(this); + s1=new Sensor(515,160); + vd = new Schuifdeur(503,250,80); +} + +MainWindow::~MainWindow(){ + delete ui; + delete s1; + delete vd; +} + +void MainWindow::paintEvent(QPaintEvent *event){ + + QPainter painter(this); + QPen pen; + QImage image("/home/shaquille/Downloads/gebouw/Gebouw.png"); + + pen.setColor(Qt::green); + pen.setWidth(4); + painter.setPen(pen); + painter.drawImage(10,10,image); + + s1->teken(this); + vd->teken(this); +} + +void MainWindow::on_schuifdeurSensorKnop_clicked(){ + if(s1->isGeactiveerd()) + s1->deactiveer(); + else + s1->activeer(); + update(); +} + +void MainWindow::on_vd_clicked(){ + if(vd->isDeurOpen()) + vd->sluit(); + else + vd->open(); + update(); +} diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000..3acbffb --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,30 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +namespace Ui { +class MainWindow; +} +class Hallsensor; +class Sensor; +class Schuifdeur; +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + void paintEvent(QPaintEvent *event); + ~MainWindow(); +private slots: + void on_schuifdeurSensorKnop_clicked(); + void on_vd_clicked(); + +private: + Ui::MainWindow *ui; + Sensor *s1; + Schuifdeur *vd; +}; + +#endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui new file mode 100644 index 0000000..7e18860 --- /dev/null +++ b/mainwindow.ui @@ -0,0 +1,73 @@ + + + MainWindow + + + + 0 + 0 + 670 + 431 + + + + MainWindow + + + + + + 510 + 100 + 31 + 31 + + + + S1 + + + false + + + + + + 513 + 250 + 31 + 31 + + + + vd + + + false + + + + + + + 0 + 0 + 670 + 27 + + + + + + TopToolBarArea + + + false + + + + + + + + diff --git a/schuifdeur.cpp b/schuifdeur.cpp new file mode 100644 index 0000000..08ff54b --- /dev/null +++ b/schuifdeur.cpp @@ -0,0 +1,26 @@ +#include "schuifdeur.h" +#include +#include +#include +#include "sensor.h" + +Schuifdeur::Schuifdeur(int x, int y, int lengte): Deur(x,y,lengte){ + +} + +void Schuifdeur::teken(QPaintDevice *tp){ + QPainter p(tp); + QColor kleur=Qt::black; + p.setBrush(Qt::SolidPattern); + p.setBrush(kleur); + QPen pen(kleur,2,Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); + p.setPen(pen); + if(isDeurOpen()) + p.drawLine(coordinaten().first, coordinaten().second, coordinaten().first, coordinaten().second + deurLengte()); + else + p.drawLine(coordinaten().first, coordinaten().second, coordinaten().first, coordinaten().second - deurLengte()); +} + +void Schuifdeur::sluit(){ + s->activeer(); +} diff --git a/schuifdeur.h b/schuifdeur.h new file mode 100644 index 0000000..d70c7d2 --- /dev/null +++ b/schuifdeur.h @@ -0,0 +1,17 @@ +#ifndef SCHUIFDEUR_H +#define SCHUIFDEUR_H + +#include "deur.h" + +class QPaintDevice; +class Sensor; + +class Schuifdeur : public Deur{ +public: + Schuifdeur(int, int, int); + void teken(QPaintDevice*) override; + void sluit(); + Sensor* s; +}; + +#endif // SCHUIFDEUR_H diff --git a/sensor.cpp b/sensor.cpp new file mode 100644 index 0000000..0ba6157 --- /dev/null +++ b/sensor.cpp @@ -0,0 +1,52 @@ +#include "sensor.h" + +#include +#include +#include + +Sensor::Sensor(int a,int b): x(a),y(b),geactiveerd(false) +{ +} + +void Sensor::activeer() +{ + geactiveerd=true; +} + +void Sensor::deactiveer() +{ + geactiveerd=false; +} + +bool Sensor::isGeactiveerd() const +{ + + return geactiveerd; + +} + + pair Sensor::coordinaten() const { + + pair temp; + temp.first=x; + temp.second=y; + return temp; + + } + +void Sensor::teken(QPaintDevice* tp) +{ + QPainter p(tp); + QColor kleur; + p.setBrush(Qt::SolidPattern); + if(geactiveerd) + kleur=Qt::blue; + else + kleur=Qt::yellow; + + p.setBrush(kleur); + QPen pen(kleur,2,Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); + p.setPen(pen); + p.drawEllipse(x,y,20,20); +} + diff --git a/sensor.h b/sensor.h new file mode 100644 index 0000000..d7249df --- /dev/null +++ b/sensor.h @@ -0,0 +1,26 @@ +#ifndef SENSOR_H +#define SENSOR_H + +#include + +using namespace std; + + +class QPaintDevice; + +class Sensor +{ +public: + Sensor(int,int); + virtual void teken(QPaintDevice*); + void activeer(); + void deactiveer(); + bool isGeactiveerd()const; + std::pair coordinaten() const; + +private: + int x,y; + bool geactiveerd; +}; + +#endif // SENSOR_H