diff --git a/pictures.qrc b/pictures.qrc index b533b81..809ff95 100644 --- a/pictures.qrc +++ b/pictures.qrc @@ -1,11 +1,9 @@ - pictures/clock-8-128.png - pictures/sport.png - pictures/calendar.png pictures/about.png pictures/banner.png pictures/validate.png pictures/warning.png + pictures/leave.png diff --git a/pictures/calendar.png b/pictures/calendar.png deleted file mode 100644 index f139a22..0000000 Binary files a/pictures/calendar.png and /dev/null differ diff --git a/pictures/clock-8-128.png b/pictures/clock-8-128.png deleted file mode 100644 index fd45a67..0000000 Binary files a/pictures/clock-8-128.png and /dev/null differ diff --git a/pictures/leave.png b/pictures/leave.png new file mode 100644 index 0000000..4e4cd0a Binary files /dev/null and b/pictures/leave.png differ diff --git a/pictures/sport.png b/pictures/sport.png deleted file mode 100644 index b44e066..0000000 Binary files a/pictures/sport.png and /dev/null differ diff --git a/sources/mainwindow.cpp b/sources/mainwindow.cpp index b342bc2..a8dc2b8 100644 --- a/sources/mainwindow.cpp +++ b/sources/mainwindow.cpp @@ -185,12 +185,8 @@ void MainWindow::compute_time() { ui->thu_time_label->setText(Tools::double_to_string_time(current_week->getThu()->get_total())); ui->fri_time_label->setText(Tools::double_to_string_time(current_week->getFri()->get_total())); ui->total_time_label->setText(Tools::double_to_string_time(current_week->total())); - updateStartLabel(); - updateBreakLabel(); - updateEndLabel(); + updateLabels(); updateWeekTime(); - updateValidIcon(); - updateWarningIcon(); double late = 0.0; double overtime = 0.0; @@ -199,8 +195,8 @@ void MainWindow::compute_time() { while (i.hasNext()) { Week *w = i.next().value(); if (w->getWeekNumber() <= todayWeekNumber) { - late += (week_template->total() - w->total()) - w->getTimeDeltaInHours(); - overtime += (w->total() - week_template->total()) + w->getTimeDeltaInHours(); + late += (week_template->total() - w->total(week_template)) - w->getTimeDeltaInHours(); + overtime += (w->total() - week_template->total(week_template)) + w->getTimeDeltaInHours(); } } late -= current_week->getTimeDeltaInHours(); @@ -209,25 +205,9 @@ void MainWindow::compute_time() { ui->overtime_time_label->setText(Tools::double_to_string_time((overtime > 0.0) ? overtime : 0.0)); } -void MainWindow::updateValidIcon() { - ui->mondayValidate->setVisible(current_week->getMon()->get_validate()); - ui->tuesdayValidate->setVisible(current_week->getTue()->get_validate()); - ui->wednesdayValidate->setVisible(current_week->getWed()->get_validate()); - ui->thurdayValidate->setVisible(current_week->getThu()->get_validate()); - ui->fridayValidate->setVisible(current_week->getFri()->get_validate()); -} - -void MainWindow::updateWarningIcon() { - ui->mondayWarning->setVisible(current_week->getMon()->has_warning()); - ui->tuesdayWarning->setVisible(current_week->getTue()->has_warning()); - ui->wednesdayWarning->setVisible(current_week->getWed()->has_warning()); - ui->thurdayWarning->setVisible(current_week->getThu()->has_warning()); - ui->fridayWarning->setVisible(current_week->getFri()->has_warning()); -} - void MainWindow::updateWeekTime() { - double t = (current_week->total() + current_week->getTimeDeltaInHours()) - week_template->total(); + double t = (current_week->total(week_template) + current_week->getTimeDeltaInHours()) - week_template->total(); if (t > 0) { ui->overtime_time_label_week->setText(Tools::double_to_string_time(t)); ui->late_time_label_week->setText("0h"); @@ -240,28 +220,30 @@ void MainWindow::updateWeekTime() } } -void MainWindow::updateStartLabel() { - ui->monStartLabel->setText(current_week->getMon()->get_start().toString("HH:mm")); - ui->tueStartLabel->setText(current_week->getTue()->get_start().toString("HH:mm")); - ui->wedStartLabel->setText(current_week->getWed()->get_start().toString("HH:mm")); - ui->thuStartLabel->setText(current_week->getThu()->get_start().toString("HH:mm")); - ui->friStartLabel->setText(current_week->getFri()->get_start().toString("HH:mm")); +void MainWindow::updateLabels() { + updateDayLabels(ui->monStartLabel, ui->monEndLabel, ui->monBreakLabel, ui->mondayValidate, ui->mondayWarning, ui->mondayNotWorking, current_week->getMon()); + updateDayLabels(ui->tueStartLabel, ui->tueEndLabel, ui->tueBreakLabel, ui->tuesdayValidate, ui->tuesdayWarning, ui->tuesdayNotWorking, current_week->getTue()); + updateDayLabels(ui->wedStartLabel, ui->wedEndLabel, ui->wedBreakLabel, ui->wednesdayValidate, ui->wednesdayWarning, ui->wednesdayNotWorking, current_week->getWed()); + updateDayLabels(ui->thuStartLabel, ui->thuEndLabel, ui->thuBreakLabel, ui->thurdayValidate, ui->thurdayWarning, ui->thurdayNotWorking, current_week->getThu()); + updateDayLabels(ui->friStartLabel, ui->friEndLabel, ui->friBreakLabel, ui->fridayValidate, ui->fridayWarning, ui->fridayNotWorking, current_week->getFri()); } -void MainWindow::updateBreakLabel() { - ui->monBreakLabel->setText(QString("%1 min.").arg(current_week->getMon()->get_time_break())); - ui->tueBreakLabel->setText(QString("%1 min.").arg(current_week->getTue()->get_time_break())); - ui->wedBreakLabel->setText(QString("%1 min.").arg(current_week->getWed()->get_time_break())); - ui->thuBreakLabel->setText(QString("%1 min.").arg(current_week->getThu()->get_time_break())); - ui->friBreakLabel->setText(QString("%1 min.").arg(current_week->getFri()->get_time_break())); -} - -void MainWindow::updateEndLabel() { - ui->monEndLabel->setText(current_week->getMon()->get_end().toString("HH:mm")); - ui->tueEndLabel->setText(current_week->getTue()->get_end().toString("HH:mm")); - ui->wedEndLabel->setText(current_week->getWed()->get_end().toString("HH:mm")); - ui->thuEndLabel->setText(current_week->getThu()->get_end().toString("HH:mm")); - ui->friEndLabel->setText(current_week->getFri()->get_end().toString("HH:mm")); +void MainWindow::updateDayLabels(QLabel *start, QLabel *end, QLabel *breaks, QFrame *validate, QFrame *warning, QFrame *not_working, Day *d) +{ + not_working->setVisible(d->not_working()); + if (!d->not_working()) { + start->setText(d->get_start().toString("HH:mm")); + end->setText(d->get_end().toString("HH:mm")); + breaks->setText(QString("%1 min.").arg(d->get_time_break())); + validate->setVisible(d->get_validate()); + warning->setVisible(d->has_warning()); + } else { + start->setText("--:--"); + end->setText("--:--"); + breaks->setText("0 min."); + validate->setVisible(false); + warning->setVisible(false); + } } void MainWindow::edit() { diff --git a/sources/mainwindow.h b/sources/mainwindow.h index 74e0e2e..5244856 100644 --- a/sources/mainwindow.h +++ b/sources/mainwindow.h @@ -4,7 +4,7 @@ #define KEY_TEMPLATE "template" #define KEY_YEARS "years" #define SAVE_FILENAME "data.json" -#define SAVE_FILE_VERSION 3 +#define SAVE_FILE_VERSION 4 #define KEY_SAVE_FILE_VERSION "version" #include @@ -25,7 +25,6 @@ #include "models/week.h" #include "models/year.h" #include "welcome.h" -#include "tools.h" #include "aboutbox.h" #include "weekoption.h" @@ -52,13 +51,10 @@ private: void panic_dialog(QString text); // UI Update - void updateStartLabel(); - void updateBreakLabel(); - void updateEndLabel(); + void updateLabels(); void highlightDayOfWeek(); - void updateValidIcon(); - void updateWarningIcon(); void updateWeekTime(); + void updateDayLabels(QLabel *start, QLabel *end, QLabel *breaks, QFrame *validate, QFrame *warning, QFrame *not_working, Day *d); QString get_save_file_path(); Identifier get_identifier(QString objectName); diff --git a/sources/models/day.cpp b/sources/models/day.cpp index 8ae883a..672e108 100644 --- a/sources/models/day.cpp +++ b/sources/models/day.cpp @@ -7,6 +7,7 @@ Day::Day() BreakPoint *lunch = new BreakPoint(QTime(12, 0, 0, 0), QTime(12, 45, 0, 0)); breaks.append(lunch); validate = false; + notWorking = false; } Day::Day(Day *old) @@ -16,6 +17,7 @@ Day::Day(Day *old) BreakPoint *lunch = new BreakPoint(QTime(12, 0, 0, 0), QTime(12, 45, 0, 0)); breaks.append(lunch); validate = false; + notWorking = false; update(old); } @@ -51,7 +53,7 @@ void Day::set_validate(bool value) { validate = value; } -void Day::set_working(bool value) +void Day::set_not_working(bool value) { this->notWorking = value; } @@ -86,7 +88,8 @@ QJsonObject Day::to_json() {KEY_START, start.toString(Qt::DateFormat::ISODate)}, {KEY_END, end.toString(Qt::DateFormat::ISODate)}, {KEY_BREAKS, arr}, - {KEY_VALIDATE, validate} + {KEY_VALIDATE, validate}, + {KEY_NOT_WORKING, notWorking} }; return obj; @@ -112,7 +115,8 @@ 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->validate = obj[KEY_VALIDATE].toBool(); + result->validate = obj[KEY_VALIDATE].toBool(false); + result->notWorking = obj[KEY_NOT_WORKING].toBool(false); result->breaks.clear(); QJsonArray arr = obj[KEY_BREAKS].toArray(); diff --git a/sources/models/day.h b/sources/models/day.h index a30544e..435d23e 100644 --- a/sources/models/day.h +++ b/sources/models/day.h @@ -5,6 +5,7 @@ #define KEY_END "end" #define KEY_BREAKS "breaks" #define KEY_VALIDATE "validate" +#define KEY_NOT_WORKING "not_working" #include #include @@ -31,7 +32,7 @@ public: void set_start(QTime value); void set_end(QTime value); void set_validate(bool); - void set_working(bool); + void set_not_working(bool); void setBreaks(QVector); QTime get_start(); diff --git a/sources/models/week.cpp b/sources/models/week.cpp index c2531ad..37e948c 100644 --- a/sources/models/week.cpp +++ b/sources/models/week.cpp @@ -61,6 +61,37 @@ double Week::total() { return mon->get_total() + tue->get_total() + wed->get_total() + thu->get_total() + fri->get_total(); } +double Week::total(Week *wtemplate) +{ + double t = 0.0; + if (mon->not_working()) { + t += wtemplate->mon->get_total(); + } else { + t += mon->get_total(); + } + if (tue->not_working()) { + t += wtemplate->tue->get_total(); + } else { + t += tue->get_total(); + } + if (wed->not_working()) { + t += wtemplate->wed->get_total(); + } else { + t += wed->get_total(); + } + if (thu->not_working()) { + t += wtemplate->thu->get_total(); + } else { + t += thu->get_total(); + } + if (fri->not_working()) { + t += wtemplate->fri->get_total(); + } else { + t += fri->get_total(); + } + return t; +} + Day* Week::getMon() { return mon; } diff --git a/sources/models/week.h b/sources/models/week.h index 109b3b9..844e75f 100644 --- a/sources/models/week.h +++ b/sources/models/week.h @@ -19,6 +19,7 @@ public: Week(Week*); ~Week(); double total(); + double total(Week *wtemplate); void setMon(Day*); void setTue(Day*); diff --git a/sources/setdaydialog.cpp b/sources/setdaydialog.cpp index 6bbf703..9f1ceb0 100644 --- a/sources/setdaydialog.cpp +++ b/sources/setdaydialog.cpp @@ -22,6 +22,8 @@ SetDayDialog::~SetDayDialog() void SetDayDialog::init() { ui->start_edit->setTime(copy->get_start()); ui->end_edit->setTime(copy->get_end()); + ui->notWorkingCheckbox->setCheckState((copy->not_working()) ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); + lockControls(copy->not_working()); updateBreakList(); connect(ui->start_edit, &QTimeEdit::timeChanged, this, &SetDayDialog::compute_time); connect(ui->end_edit, &QTimeEdit::timeChanged, this, &SetDayDialog::compute_time); @@ -30,6 +32,7 @@ void SetDayDialog::init() { 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); + connect(ui->notWorkingCheckbox, &QCheckBox::stateChanged, this, &SetDayDialog::change_not_working); ui->total_label->setText(Tools::double_to_string_time(d->get_total())); } @@ -41,6 +44,17 @@ void SetDayDialog::updateBreakList() } } +void SetDayDialog::lockControls(bool lock) +{ + ui->addBreakButton->setDisabled(lock); + ui->start_edit->setDisabled(lock); + ui->end_edit->setDisabled(lock); + ui->breakList->setDisabled(lock); + if (ui->breakList->currentRow() != -1) { + ui->removeBreakButton->setDisabled(lock); + } +} + void SetDayDialog::compute_time() { copy->set_validate(false); copy->set_start(ui->start_edit->time()); @@ -91,3 +105,10 @@ void SetDayDialog::break_selected(int i) { ui->removeBreakButton->setEnabled(i > -1); } + +void SetDayDialog::change_not_working(int state) +{ + copy->set_not_working(state != 0); + lockControls(copy->not_working()); + compute_time(); +} diff --git a/sources/setdaydialog.h b/sources/setdaydialog.h index 4e003fc..1bed753 100644 --- a/sources/setdaydialog.h +++ b/sources/setdaydialog.h @@ -28,6 +28,7 @@ private slots: void add_break_point(); void remove_break_point(); void break_selected(int); + void change_not_working(int); private: Ui::SetDayDialog *ui; @@ -37,6 +38,7 @@ private: void init(); void updateBreakList(); + void lockControls(bool); }; #endif // SETDAYDIALOG_H diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index efd840c..f2c27fb 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -193,6 +193,31 @@ font-size: 22px; + + + + + 16 + 16 + + + + + 16 + 16 + + + + border-image: url(:/clock/pictures/leave.png) 0 0 0 0 stretch stretch; + + + QFrame::StyledPanel + + + QFrame::Raised + + + @@ -266,6 +291,31 @@ font-size: 22px; + + + + + 16 + 16 + + + + + 16 + 16 + + + + border-image: url(:/clock/pictures/leave.png) 0 0 0 0 stretch stretch; + + + QFrame::StyledPanel + + + QFrame::Raised + + + @@ -339,6 +389,31 @@ font-size: 22px; + + + + + 16 + 16 + + + + + 16 + 16 + + + + border-image: url(:/clock/pictures/leave.png) 0 0 0 0 stretch stretch; + + + QFrame::StyledPanel + + + QFrame::Raised + + + @@ -412,6 +487,31 @@ font-size: 22px; + + + + + 16 + 16 + + + + + 16 + 16 + + + + border-image: url(:/clock/pictures/leave.png) 0 0 0 0 stretch stretch; + + + QFrame::StyledPanel + + + QFrame::Raised + + + @@ -485,6 +585,31 @@ font-size: 22px; + + + + + 16 + 16 + + + + + 16 + 16 + + + + border-image: url(:/clock/pictures/leave.png) 0 0 0 0 stretch stretch; + + + QFrame::StyledPanel + + + QFrame::Raised + + + @@ -1774,25 +1899,6 @@ font-weight: bold; label_semaine today_button dateEdit - tuesdayWarning - tueBreakLabel - horizontalSpacer_6 - horizontalSpacer_7 - mondayWarning - horizontalSpacer_8 - horizontalSpacer_9 - wednesdayWarning - wedBreakLabel - horizontalSpacer_10 - horizontalSpacer_11 - thurdayWarning - horizontalSpacer_12 - horizontalSpacer_13 - thuBreakLabel - fridayWarning - horizontalSpacer_14 - horizontalSpacer_15 - friBreakLabel