-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbastardsnooze.cpp
79 lines (73 loc) · 1.94 KB
/
bastardsnooze.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "bastardsnooze.h"
#include "schedules.h"
#include "ui_bastardsnooze.h"
#include <QRandomGenerator>
#include <QDateTime>
#include <QMessageBox>
#include <QCloseEvent>
BastardSnooze::BastardSnooze(QWidget *parent, Alarm * curAlarm, Schedules * schedule_list) :
QMainWindow(parent),
ui(new Ui::BastardSnooze)
{
ui->setupUi(this);
QRandomGenerator *generator=new QRandomGenerator();
generator->seed(QDateTime::currentSecsSinceEpoch());
val1 = generator->bounded(13);
val2 = generator->bounded(13);
randOp = generator->bounded(3);
this->ui->num1->setProperty("value",val1);
this->ui->num2->setProperty("value",val2);
switch(randOp)
{
case 0:
this->ui->Operator->setText("+");
break;
case 1:
this->ui->Operator->setText("-");
break;
case 2:
this->ui->Operator->setText("X");
break;
}
this->_curAlarm=curAlarm;
this->_schdule_list = schedule_list;
//connect btn
connect(ui->okbtn,SIGNAL(clicked()),this,SLOT(checkMath()));
connect(ui->Ans,SIGNAL(returnPressed()),this,SLOT(checkMath()));
}
void BastardSnooze::checkMath()
{
bool retVal=false;
switch (randOp) {
case 0:
retVal=val1+val2==ui->Ans->text().toInt();
break;
case 1:
retVal=val1-val2==ui->Ans->text().toInt();
break;
case 2:
retVal=val1*val2==ui->Ans->text().toInt();
break;
}
if(retVal)
{
this->_curAlarm->Stop();
if(this->_curAlarm->isOneshot)
{
this->_schdule_list->removeScheduleByIndex(this->_curAlarm->listId);
}
this->hide();
this->deleteLater();
}else{
QMessageBox::critical(this,"WRONG","WRONG");
}
}
BastardSnooze::~BastardSnooze()
{
delete ui;
}
void BastardSnooze::closeEvent(QCloseEvent *event)
{
event->ignore();
QMessageBox::warning(this,"Nope","you didn't think it was going to be that easy did you?");
}