diff --git a/Chronos.pro.user b/Chronos.pro.user index ba16706..4a8d138 100644 --- a/Chronos.pro.user +++ b/Chronos.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -77,7 +77,7 @@ Desktop Qt 5.15.0 MSVC2019 64bit Desktop Qt 5.15.0 MSVC2019 64bit qt.qt5.5150.win64_msvc2019_64_kit - 1 + 0 0 0 @@ -320,7 +320,7 @@ false true - C:/Users/robof/OneDrive/Documents/build-Chronos-Desktop_Qt_5_15_0_MSVC2019_64bit-Release + C:/Users/robof/OneDrive/Documents/build-Chronos-Desktop_Qt_5_15_0_MSVC2019_64bit-Debug 1 diff --git a/icon.ico b/icon.ico index d0018ec..5b785e6 100644 Binary files a/icon.ico and b/icon.ico differ diff --git a/pictures.qrc b/pictures.qrc index cf84f37..0d62e85 100644 --- a/pictures.qrc +++ b/pictures.qrc @@ -5,5 +5,6 @@ pictures/calendar.png pictures/about.png pictures/banner.png + pictures/validate.png diff --git a/pictures/banner.png b/pictures/banner.png index 44377b8..bf95775 100644 Binary files a/pictures/banner.png and b/pictures/banner.png differ diff --git a/pictures/validate.png b/pictures/validate.png new file mode 100644 index 0000000..9471cc7 Binary files /dev/null and b/pictures/validate.png differ diff --git a/sources/day.cpp b/sources/day.cpp index 7d85d38..813e71b 100644 --- a/sources/day.cpp +++ b/sources/day.cpp @@ -28,6 +28,10 @@ void Day::set_time_break(double value) time_break = value; } +void Day::set_validate(bool value) { + validate = value; +} + QTime Day::get_start() { return start; @@ -48,7 +52,8 @@ QJsonObject Day::to_json() QJsonObject obj{ {KEY_START, start.toString(Qt::DateFormat::ISODate)}, {KEY_END, end.toString(Qt::DateFormat::ISODate)}, - {KEY_BREAK, time_break} + {KEY_BREAK, time_break}, + {KEY_VALIDATE, validate} }; return obj; @@ -61,6 +66,11 @@ 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(); return result; } + +bool Day::get_validate() { + return validate; +} diff --git a/sources/day.h b/sources/day.h index 8b7622c..789080d 100644 --- a/sources/day.h +++ b/sources/day.h @@ -4,6 +4,7 @@ #define KEY_START "start" #define KEY_END "end" #define KEY_BREAK "break" +#define KEY_VALIDATE "validate" #include #include @@ -16,6 +17,7 @@ private: QTime start; QTime end; double time_break; + bool validate; public: Day(); @@ -23,10 +25,12 @@ public: void set_start(QTime value); void set_end(QTime value); void set_time_break(double value); + void set_validate(bool); QTime get_start(); QTime get_end(); double get_time_break(); + bool get_validate(); QJsonObject to_json(); double get_total(); diff --git a/sources/mainwindow.cpp b/sources/mainwindow.cpp index c2fa241..26332dc 100644 --- a/sources/mainwindow.cpp +++ b/sources/mainwindow.cpp @@ -67,8 +67,9 @@ void MainWindow::init() { connect(ui->wed_button, &QPushButton::clicked, this, &MainWindow::edit); connect(ui->thu_button, &QPushButton::clicked, this, &MainWindow::edit); connect(ui->fri_button, &QPushButton::clicked, this, &MainWindow::edit); - - highlightDayOfWeek(); + todayWeekNumber = QDate::currentDate().weekNumber(); + dayOfWeek = QDate::currentDate().dayOfWeek(); + saveLoaded = false; if (QFile::exists(get_save_file_path())) { open_save(); @@ -77,34 +78,42 @@ void MainWindow::init() { w.exec(); week_template = w.get_result(); } - set_date_to_now(); - compute_time(); + if (saveLoaded) { + set_date_to_now(); + compute_time(); + } } void MainWindow::highlightDayOfWeek() { - int dayOfWeek = QDate::currentDate().dayOfWeek(); - switch (dayOfWeek) { - case 1: { - ui->monLabel->setText(QString("> %1 <").arg(ui->monLabel->text())); - break; + ui->monLabel->setText("Lundi"); + ui->tueLabel->setText("Mardi"); + ui->wedLabel->setText("Mercredi"); + ui->thuLabel->setText("Jeudi"); + ui->friLabel->setText("Friday"); + if (todayWeekNumber == current_week.getWeekNumber()) { + switch (dayOfWeek) { + case 1: { + ui->monLabel->setText(QString("> %1 <").arg(ui->monLabel->text())); + break; + } + case 2: { + ui->tueLabel->setText(QString("> %1 <").arg(ui->tueLabel->text())); + break; + } + case 3: { + ui->wedLabel->setText(QString("> %1 <").arg(ui->wedLabel->text())); + break; + } + case 4: { + ui->thuLabel->setText(QString("> %1 <").arg(ui->thuLabel->text())); + break; + } + case 5: { + ui->friLabel->setText(QString("> %1 <").arg(ui->friLabel->text())); + break; + } + default: break; } - case 2: { - ui->tueLabel->setText(QString("> %1 <").arg(ui->tueLabel->text())); - break; - } - case 3: { - ui->wedLabel->setText(QString("> %1 <").arg(ui->wedLabel->text())); - break; - } - case 4: { - ui->thuLabel->setText(QString("> %1 <").arg(ui->thuLabel->text())); - break; - } - case 5: { - ui->friLabel->setText(QString("> %1 <").arg(ui->friLabel->text())); - break; - } - default: break; } } @@ -127,18 +136,30 @@ void MainWindow::open_save() { 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 { - QMessageBox msgBox; - msgBox.setText("Le fichier de sauvegarde n'est pas à jour, " - "des changements ont été apporté a la structure du fichier lors de la dernière mise à jour"); - msgBox.setInformativeText("Mettez à jour votre fichier de sauvegarde puis relancez l'application"); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - msgBox.exec(); - QTimer::singleShot(0, this, &MainWindow::close); + 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"); } } +void MainWindow::panic_dialog(QString text) { + QMessageBox::critical(this, tr("Chronos"), text, + QMessageBox::Ok, QMessageBox::Ok); + QTimer::singleShot(0, this, &MainWindow::close); +} + void MainWindow::save_to_file() { QJsonArray arr; for (Week w : weeks) { @@ -178,6 +199,7 @@ void MainWindow::compute_week_number(const QDateTime &dt) { save_to_file(); } compute_time(); + highlightDayOfWeek(); } void MainWindow::compute_time() { @@ -190,6 +212,7 @@ void MainWindow::compute_time() { updateStartLabel(); updateBreakLabel(); updateEndLabel(); + updateValidIcon(); double late = 0.0; double overtime = 0.0; @@ -205,6 +228,14 @@ 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::updateStartLabel() { ui->monStartLabel->setText(current_week.getMon().get_start().toString("HH:mm")); ui->tueStartLabel->setText(current_week.getTue().get_start().toString("HH:mm")); @@ -254,7 +285,8 @@ void MainWindow::edit() { } Day MainWindow::modify_value(Day d) { - SetDayDialog sdd(d, this); + bool isNotValidable = (current_week.getWeekNumber() > todayWeekNumber); + SetDayDialog sdd(d, isNotValidable, this); int result = sdd.exec(); if (result == QDialog::Accepted) { return sdd.get_result(); diff --git a/sources/mainwindow.h b/sources/mainwindow.h index 31a4385..cf3ff7e 100644 --- a/sources/mainwindow.h +++ b/sources/mainwindow.h @@ -4,7 +4,7 @@ #define KEY_TEMPLATE "template" #define KEY_WEEKS "weeks" #define SAVE_FILENAME "data.json" -#define SAVE_FILE_VERSION 1 +#define SAVE_FILE_VERSION 2 #define KEY_SAVE_FILE_VERSION "version" #include @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include "week.h" #include "welcome.h" @@ -45,12 +47,14 @@ private: void init(); void open_save(); void save_to_file(); + void panic_dialog(QString text); // UI Update void updateStartLabel(); void updateBreakLabel(); void updateEndLabel(); void highlightDayOfWeek(); + void updateValidIcon(); QString get_save_file_path(); Identifier get_identifier(QString objectName); @@ -60,6 +64,9 @@ private: Week current_week; QMap weeks; QMap objectId; + int todayWeekNumber; + int dayOfWeek; + bool saveLoaded; void mousePressEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event); diff --git a/sources/setdaydialog.cpp b/sources/setdaydialog.cpp index 7e486bb..57115f5 100644 --- a/sources/setdaydialog.cpp +++ b/sources/setdaydialog.cpp @@ -1,11 +1,12 @@ #include "setdaydialog.h" #include "ui_setdaydialog.h" -SetDayDialog::SetDayDialog(Day d, QWidget *parent) : +SetDayDialog::SetDayDialog(Day d, bool isNotValidable, QWidget *parent) : QDialog(parent), ui(new Ui::SetDayDialog) { ui->setupUi(this); + ui->validateButton->setEnabled(!isNotValidable); this->d = d; init(); } @@ -21,6 +22,7 @@ void SetDayDialog::init() { ui->break_edit->setValue(d.get_time_break()); 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(&QDoubleSpinBox::valueChanged), this, &SetDayDialog::compute_time); ui->total_label->setText(Tools::double_to_string_time(d.get_total())); } @@ -35,3 +37,8 @@ void SetDayDialog::compute_time() { Day SetDayDialog::get_result() { return d; } + +void SetDayDialog::validate() { + d.set_validate(true); + accept(); +} diff --git a/sources/setdaydialog.h b/sources/setdaydialog.h index 53fb0a3..9a7877c 100644 --- a/sources/setdaydialog.h +++ b/sources/setdaydialog.h @@ -15,13 +15,14 @@ class SetDayDialog : public QDialog Q_OBJECT public: - explicit SetDayDialog(Day d, QWidget *parent = nullptr); + explicit SetDayDialog(Day d, bool isNotValidable, QWidget *parent = nullptr); ~SetDayDialog(); Day get_result(); public slots: void compute_time(); + void validate(); private: Ui::SetDayDialog *ui; diff --git a/sources/welcome.cpp b/sources/welcome.cpp index 1e4488d..05ff99f 100644 --- a/sources/welcome.cpp +++ b/sources/welcome.cpp @@ -65,7 +65,7 @@ void Welcome::edit() { } Day Welcome::modify_value(Day d) { - SetDayDialog sdd(d, this); + SetDayDialog sdd(d, true, this); int result = sdd.exec(); if (result == QDialog::Accepted) { return sdd.get_result(); diff --git a/ui/aboutbox.ui b/ui/aboutbox.ui index 743d11d..0b59af2 100644 --- a/ui/aboutbox.ui +++ b/ui/aboutbox.ui @@ -91,7 +91,7 @@ font-size: 12px; - Version: 1.0.0 (Beta 4) + Version: 1.0.0 (Beta 5) diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index 36ce0a9..6bda025 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -394,6 +394,61 @@ color: white; + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 16 + 16 + + + + + 16 + 16 + + + + border-image: url(:/clock/pictures/validate.png) 0 0 0 0 stretch stretch; + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + @@ -592,6 +647,61 @@ color: white; + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 16 + 16 + + + + + 16 + 16 + + + + border-image: url(:/clock/pictures/validate.png) 0 0 0 0 stretch stretch; + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + @@ -790,6 +900,61 @@ color: white; + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 16 + 16 + + + + + 16 + 16 + + + + border-image: url(:/clock/pictures/validate.png) 0 0 0 0 stretch stretch; + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + @@ -988,6 +1153,61 @@ color: white; + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 16 + 16 + + + + + 16 + 16 + + + + border-image: url(:/clock/pictures/validate.png) 0 0 0 0 stretch stretch; + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + @@ -1186,6 +1406,61 @@ color: white; + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 16 + 16 + + + + + 16 + 16 + + + + border-image: url(:/clock/pictures/validate.png) 0 0 0 0 stretch stretch; + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + diff --git a/ui/setdaydialog.ui b/ui/setdaydialog.ui index faaf658..2d117db 100644 --- a/ui/setdaydialog.ui +++ b/ui/setdaydialog.ui @@ -34,14 +34,17 @@ - 320 - 140 - 75 + 214 + 110 + 181 23 + + font-size: 12px + - Valider + Enregistrer la modification @@ -219,6 +222,22 @@ color: white; + + + + 214 + 140 + 181 + 23 + + + + font-size: 12px + + + Définir l'horaire comme valide + +