init
This commit is contained in:
commit
b9f62b20e5
29
deur.cpp
Normal file
29
deur.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include "deur.h"
|
||||
#include <utility>
|
||||
|
||||
Deur::Deur(int x, int y, int lengte): x_coordinaat(x), y_coordinaat(y), lengte(lengte){
|
||||
|
||||
}
|
||||
|
||||
pair<int,int> Deur::coordinaten() const {
|
||||
pair<int,int> 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;
|
||||
}
|
25
deur.h
Normal file
25
deur.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef DEUR_H
|
||||
#define DEUR_H
|
||||
|
||||
#include <QPaintDevice>
|
||||
#include <utility>
|
||||
|
||||
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<int,int> coordinaten() const;
|
||||
Deur(int, int, int);
|
||||
};
|
||||
|
||||
#endif // DEUR_H
|
23
draaideur.cpp
Normal file
23
draaideur.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include "draaideur.h"
|
||||
#include <QPaintDevice>
|
||||
#include <QPainter>
|
||||
#include <QPen>
|
||||
|
||||
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);
|
||||
}
|
16
draaideur.h
Normal file
16
draaideur.h
Normal file
@ -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
|
41
gebouw.pro
Normal file
41
gebouw.pro
Normal file
@ -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
|
23
hallsensor.cpp
Normal file
23
hallsensor.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include "hallsensor.h"
|
||||
#include <QPaintDevice>
|
||||
#include <QPainter>
|
||||
#include <QPen>
|
||||
|
||||
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);
|
||||
}
|
15
hallsensor.h
Normal file
15
hallsensor.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef HALLSENSOR_H
|
||||
#define HALLSENSOR_H
|
||||
|
||||
#include <utility>
|
||||
#include "sensor.h"
|
||||
|
||||
class QPaintDevice;
|
||||
|
||||
class Hallsensor: public Sensor{
|
||||
public:
|
||||
Hallsensor(int, int);
|
||||
virtual void teken(QPaintDevice*);
|
||||
};
|
||||
|
||||
#endif // HALLSENSOR_H
|
11
main.cpp
Normal file
11
main.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include "mainwindow.h"
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
MainWindow w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
51
mainwindow.cpp
Normal file
51
mainwindow.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include <QPainter>
|
||||
#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();
|
||||
}
|
30
mainwindow.h
Normal file
30
mainwindow.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
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
|
73
mainwindow.ui
Normal file
73
mainwindow.ui
Normal file
@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>670</width>
|
||||
<height>431</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<widget class="QPushButton" name="schuifdeurSensorKnop">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>510</x>
|
||||
<y>100</y>
|
||||
<width>31</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>S1</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="vd">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>513</x>
|
||||
<y>250</y>
|
||||
<width>31</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>vd</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menuBar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>670</width>
|
||||
<height>27</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="mainToolBar">
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
</attribute>
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
26
schuifdeur.cpp
Normal file
26
schuifdeur.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include "schuifdeur.h"
|
||||
#include <QPaintDevice>
|
||||
#include <QPainter>
|
||||
#include <QPen>
|
||||
#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();
|
||||
}
|
17
schuifdeur.h
Normal file
17
schuifdeur.h
Normal file
@ -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
|
52
sensor.cpp
Normal file
52
sensor.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
#include "sensor.h"
|
||||
|
||||
#include <QPaintDevice>
|
||||
#include <QPainter>
|
||||
#include <QPen>
|
||||
|
||||
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<int,int> Sensor::coordinaten() const {
|
||||
|
||||
pair<int,int> 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);
|
||||
}
|
||||
|
26
sensor.h
Normal file
26
sensor.h
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef SENSOR_H
|
||||
#define SENSOR_H
|
||||
|
||||
#include <utility>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
class QPaintDevice;
|
||||
|
||||
class Sensor
|
||||
{
|
||||
public:
|
||||
Sensor(int,int);
|
||||
virtual void teken(QPaintDevice*);
|
||||
void activeer();
|
||||
void deactiveer();
|
||||
bool isGeactiveerd()const;
|
||||
std::pair<int,int> coordinaten() const;
|
||||
|
||||
private:
|
||||
int x,y;
|
||||
bool geactiveerd;
|
||||
};
|
||||
|
||||
#endif // SENSOR_H
|
Loading…
Reference in New Issue
Block a user