Version 2 // Add detailled breaks
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user