Version 2 // Add detailled breaks
This commit is contained in:
BIN
sources/.DS_Store
vendored
Normal file
BIN
sources/.DS_Store
vendored
Normal file
Binary file not shown.
@@ -19,14 +19,14 @@ AboutBox::~AboutBox()
|
||||
}
|
||||
|
||||
void AboutBox::mousePressEvent(QMouseEvent *event) {
|
||||
m_nMouseClick_X_Coordinate = event->x();
|
||||
m_nMouseClick_Y_Coordinate = event->y();
|
||||
m_nMouseClick_X_Coordinate = event->position().rx();
|
||||
m_nMouseClick_Y_Coordinate = event->position().ry();
|
||||
}
|
||||
|
||||
void AboutBox::mouseMoveEvent(QMouseEvent *event) {
|
||||
if (isWidgetIsTitleBar()) {
|
||||
move(event->globalX() - m_nMouseClick_X_Coordinate ,
|
||||
event->globalY() - m_nMouseClick_Y_Coordinate);
|
||||
move(event->globalPosition().rx() - m_nMouseClick_X_Coordinate ,
|
||||
event->globalPosition().ry() - m_nMouseClick_Y_Coordinate);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
32
sources/breakdialog.cpp
Normal file
32
sources/breakdialog.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "breakdialog.h"
|
||||
#include "ui_breakdialog.h"
|
||||
|
||||
BreakDialog::BreakDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::BreakDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
connect(ui->startTime, &QTimeEdit::timeChanged, this, &BreakDialog::compute);
|
||||
connect(ui->endTime, &QTimeEdit::timeChanged, this, &BreakDialog::compute);
|
||||
}
|
||||
|
||||
BreakDialog::~BreakDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
BreakPoint BreakDialog::get_result()
|
||||
{
|
||||
return bp;
|
||||
}
|
||||
|
||||
void BreakDialog::compute()
|
||||
{
|
||||
if (ui->endTime->time() < ui->startTime->time()) {
|
||||
ui->endTime->setTime(ui->startTime->time());
|
||||
}
|
||||
bp.setStart(ui->startTime->time());
|
||||
bp.setEnd(ui->endTime->time());
|
||||
float minutes = bp.getDuration();
|
||||
ui->totalTime->setText(QString("%1 minutes").arg(QString::number(minutes, 'g', 2)));
|
||||
}
|
||||
29
sources/breakdialog.h
Normal file
29
sources/breakdialog.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef BREAKDIALOG_H
|
||||
#define BREAKDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#include "breakpoint.h"
|
||||
|
||||
namespace Ui {
|
||||
class BreakDialog;
|
||||
}
|
||||
|
||||
class BreakDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit BreakDialog(QWidget *parent = nullptr);
|
||||
~BreakDialog();
|
||||
BreakPoint get_result();
|
||||
|
||||
private slots:
|
||||
void compute();
|
||||
|
||||
private:
|
||||
Ui::BreakDialog *ui;
|
||||
BreakPoint bp;
|
||||
};
|
||||
|
||||
#endif // BREAKDIALOG_H
|
||||
56
sources/breakpoint.cpp
Normal file
56
sources/breakpoint.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include "breakpoint.h"
|
||||
|
||||
BreakPoint::BreakPoint()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
BreakPoint::BreakPoint(QTime start, QTime end)
|
||||
{
|
||||
this->start = start;
|
||||
this->end = end;
|
||||
}
|
||||
|
||||
QTime BreakPoint::getStart()
|
||||
{
|
||||
return start;
|
||||
}
|
||||
|
||||
QTime BreakPoint::getEnd()
|
||||
{
|
||||
return end;
|
||||
}
|
||||
|
||||
float BreakPoint::getDuration()
|
||||
{
|
||||
return start.secsTo(end) / 60;
|
||||
}
|
||||
|
||||
void BreakPoint::setStart(QTime start)
|
||||
{
|
||||
this->start = start;
|
||||
}
|
||||
|
||||
void BreakPoint::setEnd(QTime end)
|
||||
{
|
||||
this->end = end;
|
||||
}
|
||||
|
||||
QJsonObject BreakPoint::to_json()
|
||||
{
|
||||
QJsonObject obj{
|
||||
{"start", start.toString(Qt::DateFormat::ISODate)},
|
||||
{"end", end.toString(Qt::DateFormat::ISODate)}
|
||||
};
|
||||
return obj;
|
||||
}
|
||||
|
||||
BreakPoint BreakPoint::from_json(QJsonObject obj)
|
||||
{
|
||||
BreakPoint result;
|
||||
|
||||
result.start = QTime::fromString(obj["start"].toString(), Qt::DateFormat::ISODate);
|
||||
result.end = QTime::fromString(obj["end"].toString(), Qt::DateFormat::ISODate);
|
||||
|
||||
return result;
|
||||
}
|
||||
29
sources/breakpoint.h
Normal file
29
sources/breakpoint.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef BREAKPOINT_H
|
||||
#define BREAKPOINT_H
|
||||
|
||||
#include <QTime>
|
||||
#include <QJsonObject>
|
||||
#include <cmath>
|
||||
|
||||
class BreakPoint
|
||||
{
|
||||
private:
|
||||
QTime start;
|
||||
QTime end;
|
||||
|
||||
public:
|
||||
BreakPoint();
|
||||
BreakPoint(QTime, QTime);
|
||||
|
||||
QTime getStart();
|
||||
QTime getEnd();
|
||||
float getDuration();
|
||||
|
||||
void setStart(QTime);
|
||||
void setEnd(QTime);
|
||||
|
||||
QJsonObject to_json();
|
||||
static BreakPoint from_json(QJsonObject);
|
||||
};
|
||||
|
||||
#endif // BREAKPOINT_H
|
||||
@@ -4,13 +4,16 @@ Day::Day()
|
||||
{
|
||||
start = QTime(9, 0, 0, 0);
|
||||
end = QTime(17, 15, 0, 0);
|
||||
time_break = 45.0;
|
||||
BreakPoint lunch(QTime(12, 0, 0, 0), QTime(12, 45, 0, 0));
|
||||
breaks.append(lunch);
|
||||
validate = false;
|
||||
}
|
||||
|
||||
double Day::get_total() {
|
||||
float Day::get_total() {
|
||||
int sec = start.secsTo(end);
|
||||
int minutes = sec / 60;
|
||||
return (minutes - time_break) / 60;
|
||||
float breakTime = get_time_break();
|
||||
return (minutes - breakTime) / 60;
|
||||
}
|
||||
|
||||
void Day::set_start(QTime value)
|
||||
@@ -23,15 +26,15 @@ void Day::set_end(QTime value)
|
||||
end = value;
|
||||
}
|
||||
|
||||
void Day::set_time_break(double value)
|
||||
{
|
||||
time_break = value;
|
||||
}
|
||||
|
||||
void Day::set_validate(bool value) {
|
||||
validate = value;
|
||||
}
|
||||
|
||||
void Day::setBreaks(QVector<BreakPoint> breaks)
|
||||
{
|
||||
this->breaks = breaks;
|
||||
}
|
||||
|
||||
QTime Day::get_start()
|
||||
{
|
||||
return start;
|
||||
@@ -42,17 +45,21 @@ QTime Day::get_end()
|
||||
return end;
|
||||
}
|
||||
|
||||
double Day::get_time_break()
|
||||
QVector<BreakPoint> Day::getBreaks()
|
||||
{
|
||||
return time_break;
|
||||
return breaks;
|
||||
}
|
||||
|
||||
QJsonObject Day::to_json()
|
||||
{
|
||||
QJsonArray arr;
|
||||
foreach (BreakPoint bp, breaks) {
|
||||
arr.append(bp.to_json());
|
||||
}
|
||||
QJsonObject obj{
|
||||
{KEY_START, start.toString(Qt::DateFormat::ISODate)},
|
||||
{KEY_END, end.toString(Qt::DateFormat::ISODate)},
|
||||
{KEY_BREAK, time_break},
|
||||
{KEY_BREAKS, arr},
|
||||
{KEY_VALIDATE, validate}
|
||||
};
|
||||
|
||||
@@ -65,12 +72,26 @@ Day Day::from_json(QJsonObject obj)
|
||||
|
||||
result.start = QTime::fromString(obj[KEY_START].toString(), Qt::DateFormat::ISODate);
|
||||
result.end = QTime::fromString(obj[KEY_END].toString(), Qt::DateFormat::ISODate);
|
||||
result.time_break = obj[KEY_BREAK].toDouble();
|
||||
result.validate = obj[KEY_VALIDATE].toBool();
|
||||
|
||||
result.breaks.clear();
|
||||
QJsonArray arr = obj[KEY_BREAKS].toArray();
|
||||
foreach (QJsonValue val, arr) {
|
||||
result.breaks.append(BreakPoint::from_json(val.toObject()));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Day::get_validate() {
|
||||
return validate;
|
||||
}
|
||||
|
||||
float Day::get_time_break()
|
||||
{
|
||||
float result = 0;
|
||||
foreach (BreakPoint bp, breaks) {
|
||||
result += bp.getDuration();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -3,20 +3,23 @@
|
||||
|
||||
#define KEY_START "start"
|
||||
#define KEY_END "end"
|
||||
#define KEY_BREAK "break"
|
||||
#define KEY_BREAKS "breaks"
|
||||
#define KEY_VALIDATE "validate"
|
||||
|
||||
#include <QTime>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <math.h>
|
||||
|
||||
#include "breakpoint.h"
|
||||
|
||||
class Day
|
||||
{
|
||||
|
||||
private:
|
||||
QTime start;
|
||||
QTime end;
|
||||
double time_break;
|
||||
QVector<BreakPoint> breaks;
|
||||
bool validate;
|
||||
|
||||
public:
|
||||
@@ -24,16 +27,17 @@ public:
|
||||
|
||||
void set_start(QTime value);
|
||||
void set_end(QTime value);
|
||||
void set_time_break(double value);
|
||||
void set_validate(bool);
|
||||
void setBreaks(QVector<BreakPoint>);
|
||||
|
||||
QTime get_start();
|
||||
QTime get_end();
|
||||
double get_time_break();
|
||||
QVector<BreakPoint> getBreaks();
|
||||
bool get_validate();
|
||||
float get_time_break();
|
||||
QJsonObject to_json();
|
||||
|
||||
double get_total();
|
||||
float get_total();
|
||||
|
||||
static Day from_json(QJsonObject);
|
||||
};
|
||||
|
||||
@@ -6,31 +6,9 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->window_title->setText(this->windowTitle());
|
||||
this->setWindowFlags(Qt::FramelessWindowHint);
|
||||
init();
|
||||
}
|
||||
|
||||
void MainWindow::mousePressEvent(QMouseEvent *event) {
|
||||
m_nMouseClick_X_Coordinate = event->x();
|
||||
m_nMouseClick_Y_Coordinate = event->y();
|
||||
}
|
||||
|
||||
void MainWindow::mouseMoveEvent(QMouseEvent *event) {
|
||||
if (isWidgetIsTitleBar()) {
|
||||
move(event->globalX() - m_nMouseClick_X_Coordinate ,
|
||||
event->globalY() - m_nMouseClick_Y_Coordinate);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool MainWindow::isWidgetIsTitleBar() {
|
||||
return (m_nMouseClick_X_Coordinate >= xmin &&
|
||||
m_nMouseClick_X_Coordinate < xmax &&
|
||||
m_nMouseClick_Y_Coordinate >= ymin &&
|
||||
m_nMouseClick_Y_Coordinate < ymax);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
@@ -55,10 +33,6 @@ void MainWindow::init() {
|
||||
objectId.insert(ui->wed_button->objectName(), Identifier::wed);
|
||||
objectId.insert(ui->thu_button->objectName(), Identifier::thu);
|
||||
objectId.insert(ui->fri_button->objectName(), Identifier::fri);
|
||||
xmax = ui->titleBar->x() + ui->titleBar->width();
|
||||
xmin = ui->titleBar->x();
|
||||
ymax = ui->titleBar->x() + ui->titleBar->height();
|
||||
ymin = ui->titleBar->y();
|
||||
connect(ui->aboutButton, &QPushButton::clicked, this, &MainWindow::open_about);
|
||||
connect(ui->template_settings_button, &QPushButton::clicked, this, &MainWindow::edit_template);
|
||||
connect(ui->dateEdit, &QDateEdit::dateTimeChanged, this, &MainWindow::compute_week_number);
|
||||
@@ -130,28 +104,13 @@ void MainWindow::open_save() {
|
||||
delete file;
|
||||
|
||||
QJsonObject obj = QJsonDocument::fromJson(json.toUtf8()).object();
|
||||
if (obj[KEY_SAVE_FILE_VERSION].toInt() == SAVE_FILE_VERSION) {
|
||||
week_template = Week::from_json(obj[KEY_TEMPLATE].toObject());
|
||||
QJsonArray arr = obj[KEY_WEEKS].toArray();
|
||||
for (QJsonValue val : arr) {
|
||||
weeks[val.toObject()["weekNumber"].toInt()] = Week::from_json(val.toObject());
|
||||
}
|
||||
saveLoaded = true;
|
||||
} else if (obj[KEY_SAVE_FILE_VERSION].toInt() < SAVE_FILE_VERSION) {
|
||||
QString updater = QCoreApplication::applicationDirPath() + "/save-updater.exe";
|
||||
if (QFile::exists(updater)) {
|
||||
QProcess* process = new QProcess(this);
|
||||
process->execute(updater, QStringList({"update"}));
|
||||
delete process;
|
||||
open_save();
|
||||
} else {
|
||||
panic_dialog("Cette application n'a pas pu démarrer car save-updater.exe est introuvable.\n"
|
||||
"La réinstallation de cette application peut corriger ce problème");
|
||||
}
|
||||
} else {
|
||||
panic_dialog("Votre fichier de sauvegarde a été enregistré depuis une version plus récente de Chronos\n"
|
||||
"Mettez à jour Chronos pour pouvoir utiliser ce fichier");
|
||||
week_template = Week::from_json(obj[KEY_TEMPLATE].toObject());
|
||||
QJsonArray arr = obj[KEY_YEARS].toArray();
|
||||
foreach (QJsonValue val, arr) {
|
||||
Year y = Year::from_json(val.toObject());
|
||||
years[y.getNumber()] = y;
|
||||
}
|
||||
saveLoaded = true;
|
||||
}
|
||||
|
||||
void MainWindow::panic_dialog(QString text) {
|
||||
@@ -162,12 +121,12 @@ void MainWindow::panic_dialog(QString text) {
|
||||
|
||||
void MainWindow::save_to_file() {
|
||||
QJsonArray arr;
|
||||
for (Week w : weeks) {
|
||||
arr.append(w.to_json());
|
||||
foreach (Year y, years) {
|
||||
arr.append(y.to_json());
|
||||
}
|
||||
QJsonObject obj {
|
||||
{KEY_TEMPLATE, week_template.to_json()},
|
||||
{KEY_WEEKS, arr},
|
||||
{KEY_YEARS, arr},
|
||||
{KEY_SAVE_FILE_VERSION, SAVE_FILE_VERSION}
|
||||
};
|
||||
QJsonDocument doc(obj);
|
||||
@@ -180,22 +139,24 @@ void MainWindow::save_to_file() {
|
||||
|
||||
void MainWindow::compute_week_number(const QDateTime &dt) {
|
||||
int n = dt.date().weekNumber();
|
||||
int y = dt.date().year();
|
||||
ui->label_semaine->setText(QString("Semaine : %1").arg(QString::number(n)));
|
||||
QMapIterator<int, Week> it(weeks);
|
||||
bool working = true;
|
||||
bool found = false;
|
||||
while (it.hasNext() && working) {
|
||||
Week w = it.next().value();
|
||||
if (w.getWeekNumber() == n) {
|
||||
current_week = w;
|
||||
working = false;
|
||||
found = true;
|
||||
}
|
||||
if (years.contains(y)) {
|
||||
current_year = years[y];
|
||||
} else {
|
||||
Year nYear(y);
|
||||
years[y] = nYear;
|
||||
current_year = nYear;
|
||||
save_to_file();
|
||||
}
|
||||
if (!found) {
|
||||
|
||||
if (current_year.getWeeks().contains(n)) {
|
||||
auto weeks = current_year.getWeeks();
|
||||
current_week = weeks[n];
|
||||
} else {
|
||||
current_week = Week(week_template);
|
||||
current_week.setWeekNumber(n);
|
||||
weeks.insert(n, current_week);
|
||||
current_year.addWeek(current_week);
|
||||
save_to_file();
|
||||
}
|
||||
compute_time();
|
||||
@@ -217,13 +178,12 @@ void MainWindow::compute_time() {
|
||||
double late = 0.0;
|
||||
double overtime = 0.0;
|
||||
int todayWeekNumber = QDate::currentDate().weekNumber();
|
||||
for (Week w : weeks) {
|
||||
foreach (Week w, current_year.getWeeks()) {
|
||||
if (w.getWeekNumber() <= todayWeekNumber) {
|
||||
late += (week_template.total() - w.total());
|
||||
overtime += (w.total() - week_template.total());
|
||||
}
|
||||
}
|
||||
|
||||
ui->late_time_label->setText(Tools::double_to_string_time((late > 0.0) ? late : 0.0));
|
||||
ui->overtime_time_label->setText(Tools::double_to_string_time((overtime > 0.0) ? overtime : 0.0));
|
||||
}
|
||||
@@ -279,7 +239,10 @@ void MainWindow::edit() {
|
||||
current_week.setFri(modify_value(current_week.getFri()));
|
||||
break;
|
||||
}
|
||||
auto weeks = current_year.getWeeks();
|
||||
weeks[current_week.getWeekNumber()] = current_week;
|
||||
current_year.setWeeks(weeks);
|
||||
years[current_year.getNumber()] = current_year;
|
||||
save_to_file();
|
||||
compute_time();
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#define KEY_TEMPLATE "template"
|
||||
#define KEY_WEEKS "weeks"
|
||||
#define KEY_YEARS "years"
|
||||
#define SAVE_FILENAME "data.json"
|
||||
#define SAVE_FILE_VERSION 2
|
||||
#define SAVE_FILE_VERSION 3
|
||||
#define KEY_SAVE_FILE_VERSION "version"
|
||||
|
||||
#include <QMouseEvent>
|
||||
@@ -21,9 +21,9 @@
|
||||
#include <QTimer>
|
||||
#include <QProcess>
|
||||
#include <QDir>
|
||||
#include <QtWinExtras/QtWin>
|
||||
|
||||
#include "week.h"
|
||||
#include "year.h"
|
||||
#include "welcome.h"
|
||||
#include "tools.h"
|
||||
#include "aboutbox.h"
|
||||
@@ -63,22 +63,13 @@ private:
|
||||
|
||||
Week week_template;
|
||||
Week current_week;
|
||||
QMap<int, Week> weeks;
|
||||
Year current_year;
|
||||
QMap<int, Year> years;
|
||||
QMap<QString, Identifier> objectId;
|
||||
int todayWeekNumber;
|
||||
int dayOfWeek;
|
||||
bool saveLoaded;
|
||||
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
int m_nMouseClick_X_Coordinate;
|
||||
int m_nMouseClick_Y_Coordinate;
|
||||
int xmax;
|
||||
int xmin;
|
||||
int ymax;
|
||||
int ymin;
|
||||
inline bool isWidgetIsTitleBar();
|
||||
|
||||
public slots:
|
||||
void compute_week_number(const QDateTime &dt);
|
||||
void compute_time();
|
||||
|
||||
@@ -6,9 +6,8 @@ SetDayDialog::SetDayDialog(Day d, bool isNotValidable, QWidget *parent) :
|
||||
ui(new Ui::SetDayDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->window_title->setText(this->windowTitle());
|
||||
this->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
|
||||
ui->validateButton->setEnabled(!isNotValidable);
|
||||
ui->validateButton->setVisible(!isNotValidable);
|
||||
this->d = d;
|
||||
init();
|
||||
}
|
||||
@@ -18,45 +17,31 @@ SetDayDialog::~SetDayDialog()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void SetDayDialog::mousePressEvent(QMouseEvent *event) {
|
||||
m_nMouseClick_X_Coordinate = event->x();
|
||||
m_nMouseClick_Y_Coordinate = event->y();
|
||||
}
|
||||
|
||||
void SetDayDialog::mouseMoveEvent(QMouseEvent *event) {
|
||||
if (isWidgetIsTitleBar()) {
|
||||
move(event->globalX() - m_nMouseClick_X_Coordinate ,
|
||||
event->globalY() - m_nMouseClick_Y_Coordinate);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool SetDayDialog::isWidgetIsTitleBar() {
|
||||
return (m_nMouseClick_X_Coordinate >= xmin &&
|
||||
m_nMouseClick_X_Coordinate < xmax &&
|
||||
m_nMouseClick_Y_Coordinate >= ymin &&
|
||||
m_nMouseClick_Y_Coordinate < ymax);
|
||||
}
|
||||
|
||||
void SetDayDialog::init() {
|
||||
ui->start_edit->setTime(d.get_start());
|
||||
ui->end_edit->setTime(d.get_end());
|
||||
ui->break_edit->setValue(d.get_time_break());
|
||||
xmax = ui->titleBar->x() + ui->titleBar->width();
|
||||
xmin = ui->titleBar->x();
|
||||
ymax = ui->titleBar->x() + ui->titleBar->height();
|
||||
ymin = ui->titleBar->y();
|
||||
updateBreakList();
|
||||
connect(ui->start_edit, &QTimeEdit::timeChanged, this, &SetDayDialog::compute_time);
|
||||
connect(ui->end_edit, &QTimeEdit::timeChanged, this, &SetDayDialog::compute_time);
|
||||
connect(ui->validateButton, &QPushButton::clicked, this, &SetDayDialog::validate);
|
||||
connect(ui->break_edit, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &SetDayDialog::compute_time);
|
||||
connect(ui->addBreakButton, &QPushButton::clicked, this, &SetDayDialog::add_break_point);
|
||||
connect(ui->removeBreakButton, &QPushButton::clicked, this, &SetDayDialog::remove_break_point);
|
||||
connect(ui->breakList, &QListWidget::currentRowChanged, this, &SetDayDialog::break_selected);
|
||||
ui->total_label->setText(Tools::double_to_string_time(d.get_total()));
|
||||
}
|
||||
|
||||
void SetDayDialog::updateBreakList()
|
||||
{
|
||||
ui->breakList->clear();
|
||||
foreach (BreakPoint bp, d.getBreaks()) {
|
||||
ui->breakList->addItem(QString("%1 -> %2").arg(bp.getStart().toString("hh:mm"), bp.getEnd().toString("hh:mm")));
|
||||
}
|
||||
}
|
||||
|
||||
void SetDayDialog::compute_time() {
|
||||
d.set_validate(false);
|
||||
d.set_start(ui->start_edit->time());
|
||||
d.set_end(ui->end_edit->time());
|
||||
d.set_time_break(ui->break_edit->value());
|
||||
ui->total_label->setText(Tools::double_to_string_time(d.get_total()));
|
||||
}
|
||||
|
||||
@@ -68,3 +53,34 @@ void SetDayDialog::validate() {
|
||||
d.set_validate(true);
|
||||
accept();
|
||||
}
|
||||
|
||||
void SetDayDialog::add_break_point()
|
||||
{
|
||||
BreakDialog bd(this);
|
||||
int result = bd.exec();
|
||||
if (result == QDialog::Accepted) {
|
||||
BreakPoint bp = bd.get_result();
|
||||
auto breaks = d.getBreaks();
|
||||
breaks.append(bp);
|
||||
d.setBreaks(breaks);
|
||||
updateBreakList();
|
||||
compute_time();
|
||||
}
|
||||
}
|
||||
|
||||
void SetDayDialog::remove_break_point()
|
||||
{
|
||||
int i = ui->breakList->currentRow();
|
||||
if (i > -1) {
|
||||
auto breaks = d.getBreaks();
|
||||
breaks.removeAt(i);
|
||||
d.setBreaks(breaks);
|
||||
updateBreakList();
|
||||
compute_time();
|
||||
}
|
||||
}
|
||||
|
||||
void SetDayDialog::break_selected(int i)
|
||||
{
|
||||
ui->removeBreakButton->setEnabled(i > -1);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
#include "day.h"
|
||||
#include "tools.h"
|
||||
#include "breakdialog.h"
|
||||
#include "breakpoint.h"
|
||||
|
||||
namespace Ui {
|
||||
class SetDayDialog;
|
||||
@@ -21,9 +23,12 @@ public:
|
||||
|
||||
Day get_result();
|
||||
|
||||
public slots:
|
||||
private slots:
|
||||
void compute_time();
|
||||
void validate();
|
||||
void add_break_point();
|
||||
void remove_break_point();
|
||||
void break_selected(int);
|
||||
|
||||
private:
|
||||
Ui::SetDayDialog *ui;
|
||||
@@ -31,16 +36,7 @@ private:
|
||||
Day d;
|
||||
|
||||
void init();
|
||||
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
int m_nMouseClick_X_Coordinate;
|
||||
int m_nMouseClick_Y_Coordinate;
|
||||
int xmax;
|
||||
int xmin;
|
||||
int ymax;
|
||||
int ymin;
|
||||
inline bool isWidgetIsTitleBar();
|
||||
void updateBreakList();
|
||||
};
|
||||
|
||||
#endif // SETDAYDIALOG_H
|
||||
|
||||
@@ -6,8 +6,6 @@ Welcome::Welcome(Week wtemplate, QWidget *parent) :
|
||||
ui(new Ui::Welcome)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->window_title->setText(this->windowTitle());
|
||||
this->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
|
||||
w = wtemplate;
|
||||
init();
|
||||
}
|
||||
@@ -17,26 +15,6 @@ Welcome::~Welcome()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void Welcome::mousePressEvent(QMouseEvent *event) {
|
||||
m_nMouseClick_X_Coordinate = event->x();
|
||||
m_nMouseClick_Y_Coordinate = event->y();
|
||||
}
|
||||
|
||||
void Welcome::mouseMoveEvent(QMouseEvent *event) {
|
||||
if (isWidgetIsTitleBar()) {
|
||||
move(event->globalX() - m_nMouseClick_X_Coordinate ,
|
||||
event->globalY() - m_nMouseClick_Y_Coordinate);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool Welcome::isWidgetIsTitleBar() {
|
||||
return (m_nMouseClick_X_Coordinate >= xmin &&
|
||||
m_nMouseClick_X_Coordinate < xmax &&
|
||||
m_nMouseClick_Y_Coordinate >= ymin &&
|
||||
m_nMouseClick_Y_Coordinate < ymax);
|
||||
}
|
||||
|
||||
void Welcome::init() {
|
||||
set_value_to_widget();
|
||||
objectId.insert(ui->mon_button->objectName(), Identifier::mon);
|
||||
@@ -44,10 +22,6 @@ void Welcome::init() {
|
||||
objectId.insert(ui->wed_button->objectName(), Identifier::wed);
|
||||
objectId.insert(ui->thu_button->objectName(), Identifier::thu);
|
||||
objectId.insert(ui->fri_button->objectName(), Identifier::fri);
|
||||
xmax = ui->titleBar->x() + ui->titleBar->width();
|
||||
xmin = ui->titleBar->x();
|
||||
ymax = ui->titleBar->x() + ui->titleBar->height();
|
||||
ymin = ui->titleBar->y();
|
||||
connect(ui->mon_button, &QPushButton::clicked, this, &Welcome::edit);
|
||||
connect(ui->tue_button, &QPushButton::clicked, this, &Welcome::edit);
|
||||
connect(ui->wed_button, &QPushButton::clicked, this, &Welcome::edit);
|
||||
|
||||
@@ -44,16 +44,6 @@ private:
|
||||
Identifier get_identifier(QString objectName);
|
||||
Day modify_value(Day);
|
||||
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
int m_nMouseClick_X_Coordinate;
|
||||
int m_nMouseClick_Y_Coordinate;
|
||||
int xmax;
|
||||
int xmin;
|
||||
int ymax;
|
||||
int ymin;
|
||||
inline bool isWidgetIsTitleBar();
|
||||
|
||||
public slots:
|
||||
void edit();
|
||||
};
|
||||
|
||||
55
sources/year.cpp
Normal file
55
sources/year.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include "year.h"
|
||||
|
||||
Year::Year()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Year::Year(int number)
|
||||
{
|
||||
this->number = number;
|
||||
}
|
||||
|
||||
Year Year::from_json(QJsonObject obj)
|
||||
{
|
||||
Year result;
|
||||
result.number = obj[KEY_NUMBER].toInt();
|
||||
QJsonArray arr = obj[KEY_WEEKS].toArray();
|
||||
foreach (QJsonValue val, arr) {
|
||||
Week w = Week::from_json(val.toObject());
|
||||
result.weeks[w.getWeekNumber()] = w;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QJsonObject Year::to_json()
|
||||
{
|
||||
QJsonObject obj;
|
||||
QJsonArray arr;
|
||||
foreach (Week w, weeks) {
|
||||
arr.append(w.to_json());
|
||||
}
|
||||
obj[KEY_NUMBER] = number;
|
||||
obj[KEY_WEEKS] = arr;
|
||||
return obj;
|
||||
}
|
||||
|
||||
QMap<int, Week> Year::getWeeks()
|
||||
{
|
||||
return weeks;
|
||||
}
|
||||
|
||||
int Year::getNumber()
|
||||
{
|
||||
return number;
|
||||
}
|
||||
|
||||
void Year::addWeek(Week w)
|
||||
{
|
||||
weeks[w.getWeekNumber()] = w;
|
||||
}
|
||||
|
||||
void Year::setWeeks(QMap<int, Week> weeks)
|
||||
{
|
||||
this->weeks = weeks;
|
||||
}
|
||||
32
sources/year.h
Normal file
32
sources/year.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef YEAR_H
|
||||
#define YEAR_H
|
||||
|
||||
#define KEY_NUMBER "number"
|
||||
#define KEY_WEEKS "weeks"
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
|
||||
#include "week.h"
|
||||
|
||||
class Year
|
||||
{
|
||||
private:
|
||||
int number;
|
||||
QMap<int, Week> weeks;
|
||||
|
||||
public:
|
||||
Year();
|
||||
Year(int number);
|
||||
|
||||
static Year from_json(QJsonObject);
|
||||
QJsonObject to_json();
|
||||
|
||||
QMap<int, Week> getWeeks();
|
||||
int getNumber();
|
||||
|
||||
void addWeek(Week w);
|
||||
void setWeeks(QMap<int, Week> weeks);
|
||||
};
|
||||
|
||||
#endif // YEAR_H
|
||||
Reference in New Issue
Block a user