Skip to content

Commit

Permalink
Added solve math to stop alarm feature
Browse files Browse the repository at this point in the history
  • Loading branch information
CountMurphy authored and cgugas committed Oct 6, 2021
1 parent 8a5535b commit fab23d1
Show file tree
Hide file tree
Showing 16 changed files with 456 additions and 185 deletions.
3 changes: 3 additions & 0 deletions QTalarm.pro
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ TEMPLATE = app


SOURCES += main.cpp\
bastardsnooze.cpp \
mainwindow.cpp \
timer.cpp \
alarm.cpp \
Expand All @@ -24,6 +25,7 @@ SOURCES += main.cpp\
settingdialog.cpp

HEADERS += mainwindow.h \
bastardsnooze.h \
timer.h \
alarm.h \
fileio.h \
Expand All @@ -35,6 +37,7 @@ HEADERS += mainwindow.h \

FORMS += mainwindow.ui \
aboutdialog.ui \
bastardsnooze.ui \
snooze.ui \
settingdialog.ui

Expand Down
2 changes: 1 addition & 1 deletion aboutdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AboutDialog : public QDialog
public:
explicit AboutDialog(QWidget *parent = 0);
~AboutDialog();
const QString version="2.1.1";
const QString version="2.2.0";

private:
Ui::AboutDialog *ui;
Expand Down
9 changes: 8 additions & 1 deletion alarm.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@ class Alarm : public QObject
{
Q_OBJECT
public:
explicit Alarm(QObject *parent = 0);
virtual ~Alarm(){};
static Alarm & GetInstance()
{
static Alarm instance;
return instance;
}
void Start(bool useCustom);
void Stop();
bool isPlaying();
bool canResume;
void SetCustomPath(QString);
bool UsingCustomPath;
bool isBastard;
private:
explicit Alarm(QObject *parent = 0);
QMediaPlayer * media;
QString _DefaultPath;
QString _CustPath;
Expand Down
74 changes: 74 additions & 0 deletions bastardsnooze.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "bastardsnooze.h"
#include "ui_bastardsnooze.h"
#include <QRandomGenerator>
#include <QDateTime>
#include <QMessageBox>
#include <QCloseEvent>

BastardSnooze::BastardSnooze(QWidget *parent, Alarm * curAlarm) :
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;

//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();
this->hide();
this->~BastardSnooze();
}else{
QMessageBox::critical(this,"WRONG","WRONG");
}
}

BastardSnooze::~BastardSnooze()
{
delete ui;
this->deleteLater();
}

void BastardSnooze::closeEvent(QCloseEvent *event)
{
event->ignore();
QMessageBox::warning(this,"Nope","you didn't think it was going to be that easy did you?");
}
30 changes: 30 additions & 0 deletions bastardsnooze.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef BASTARDSNOOZE_H
#define BASTARDSNOOZE_H

#include <QMainWindow>
#include "alarm.h"

namespace Ui {
class BastardSnooze;
}

class BastardSnooze : public QMainWindow
{
Q_OBJECT

public:
explicit BastardSnooze(QWidget *parent = nullptr, Alarm * curAlarm=0);
~BastardSnooze();

private:
Ui::BastardSnooze *ui;
qint32 val1;
qint32 val2;
qint32 randOp;
Alarm * _curAlarm;
void closeEvent(QCloseEvent*);
private slots:
void checkMath();
};

#endif // BASTARDSNOOZE_H
119 changes: 119 additions & 0 deletions bastardsnooze.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BastardSnooze</class>
<widget class="QMainWindow" name="BastardSnooze">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>977</width>
<height>332</height>
</rect>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="windowTitle">
<string>Bastard Snooze</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QLCDNumber" name="num1">
<property name="geometry">
<rect>
<x>210</x>
<y>30</y>
<width>171</width>
<height>111</height>
</rect>
</property>
</widget>
<widget class="QLCDNumber" name="num2">
<property name="geometry">
<rect>
<x>610</x>
<y>30</y>
<width>161</width>
<height>111</height>
</rect>
</property>
<property name="segmentStyle">
<enum>QLCDNumber::Filled</enum>
</property>
</widget>
<widget class="QLabel" name="Operator">
<property name="geometry">
<rect>
<x>450</x>
<y>50</y>
<width>91</width>
<height>81</height>
</rect>
</property>
<property name="baseSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="font">
<font>
<pointsize>53</pointsize>
</font>
</property>
<property name="text">
<string>X</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QPushButton" name="okbtn">
<property name="geometry">
<rect>
<x>520</x>
<y>220</y>
<width>161</width>
<height>51</height>
</rect>
</property>
<property name="text">
<string>OK</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
<widget class="QLineEdit" name="Ans">
<property name="geometry">
<rect>
<x>260</x>
<y>220</y>
<width>211</width>
<height>51</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>50</pointsize>
</font>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>977</width>
<height>23</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
Loading

0 comments on commit fab23d1

Please sign in to comment.