Qt-Gebouw/mainwindow.cpp

128 lines
3.4 KiB
C++
Raw Normal View History

2022-02-10 16:44:22 +00:00
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPainter>
#include "sensor.h"
#include "hallsensor.h"
#include "schuifdeur.h"
2022-02-17 23:51:34 +00:00
#include "draaideur.h"
#include <stdio.h>
#include <iostream>
2022-03-29 16:38:53 +00:00
#include <QLineEdit>
#include <sleutelslot.h>
#include <codeslot.h>
2022-04-06 16:01:47 +00:00
#include "slot.h"
#include "herkenningsslot.h"
#include "afdrukker.h"
#include "drukbox.h"
2022-02-10 16:44:22 +00:00
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow){
ui->setupUi(this);
2022-02-17 23:51:34 +00:00
s1=new Hallsensor(515,160);
2022-03-29 16:38:53 +00:00
//sleutelSlot0 = new SleutelSlot("cisco");
//sleutelSlot1 = new SleutelSlot("cisco");
deuren.emplace_back(std::shared_ptr<Deur> (new Schuifdeur(503,250,80,s1)));
2022-04-06 16:01:47 +00:00
deuren[0]->addSlot(new HerkenningsSlot(new Drukbox()));
//deuren[0]->addSlot(new SleutelSlot("cisco2"));
2022-03-29 16:38:53 +00:00
deuren.emplace_back(std::shared_ptr<Deur> (new draaideur(248,140,40,false)));
deuren[1]->addSlot(new CodeSlot(1234));
deuren[1]->addSlot(new CodeSlot(5678));
deuren.emplace_back(std::shared_ptr<Deur> (new draaideur(295,290,30,true)));
deuren[2]->addSlot(new CodeSlot(0000));
2022-02-10 16:44:22 +00:00
}
MainWindow::~MainWindow(){
delete ui;
delete s1;
}
void MainWindow::paintEvent(QPaintEvent *event){
QPainter painter(this);
QPen pen;
2022-03-29 16:38:53 +00:00
QImage image("/home/shaquilles/Downloads/gebouw/Gebouw.png");
2022-02-10 16:44:22 +00:00
pen.setColor(Qt::green);
pen.setWidth(4);
painter.setPen(pen);
painter.drawImage(10,10,image);
s1->teken(this);
2022-02-17 23:51:34 +00:00
deuren.at(0)->teken(this);
deuren.at(1)->teken(this);
deuren.at(2)->teken(this);
2022-02-10 16:44:22 +00:00
}
void MainWindow::on_schuifdeurSensorKnop_clicked(){
if(s1->isGeactiveerd())
s1->deactiveer();
else
s1->activeer();
update();
}
void MainWindow::on_vd_clicked(){
2022-02-17 23:51:34 +00:00
if(deuren.at(0)->isDeurOpen()){
2022-03-29 16:38:53 +00:00
deuren[0]->sluit();
2022-02-17 23:51:34 +00:00
}
else{
deuren.at(0)->open();
s1->deactiveer();
}
2022-02-10 16:44:22 +00:00
update();
}
2022-02-17 23:51:34 +00:00
void MainWindow::on_d1_clicked(){
if(deuren.at(1)->isDeurOpen()){
deuren.at(1)->sluit();
}
else{
deuren.at(1)->open();
}
update();
}
void MainWindow::on_d2_clicked(){
if(deuren.at(2)->isDeurOpen()){
deuren.at(2)->sluit();
}
else{
deuren.at(2)->open();
}
update();
}
2022-03-29 16:38:53 +00:00
void MainWindow::on_lineEdit_returnPressed(){
string eenSleutel = ui->lineEdit->text().toStdString();
2022-04-06 16:01:47 +00:00
// Slot* sleutelSlot0 = deuren[0]->geefSleutel(0);
// Slot* sleutelSlot1 = deuren[0]->geefSleutel(1);
// Slot* codeSlot0 = deuren[1]->geefSleutel(0);
// Slot* codeSlot1 = deuren[1]->geefSleutel(1);
// Slot* codeSlot2 = deuren[2]->geefSleutel(0);
// sleutelSlot0->ontgrendel(eenSleutel);
// sleutelSlot1->ontgrendel(eenSleutel);
// codeSlot0->ontgrendel(eenSleutel);
// codeSlot1->ontgrendel(eenSleutel);
// codeSlot2->ontgrendel(eenSleutel);
for(ulong i = 0; i < deuren.size(); i++) {
std::list<Slot*> slotenDeur = deuren[i]->geefSlot();
for (auto &j:slotenDeur)
(*j).ontgrendel(ui->lineEdit->text().toStdString());
}
}
2022-03-29 16:38:53 +00:00
2022-04-06 16:01:47 +00:00
void MainWindow::on_Allow_clicked(){
Slot* a = deuren[0]->geefSleutel(0);
HerkenningsSlot* b = dynamic_cast<HerkenningsSlot*>(a);
b->voegAutorisatieToe(ui->HerkenningAdd->text().toStdString(), true);
2022-03-29 16:38:53 +00:00
}
2022-04-06 16:01:47 +00:00
void MainWindow::on_Deny_clicked(){
Slot* a = deuren[0]->geefSleutel(0);
HerkenningsSlot* b = dynamic_cast<HerkenningsSlot*>(a);
b->voegAutorisatieToe(ui->HerkenningAdd->text().toStdString(), false);
2022-03-29 16:38:53 +00:00
}