From 0b037cff7c5ed76f0f467b3cdbf0c65b440a5b1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Sun, 1 Jan 2017 17:20:08 +0100 Subject: [PATCH] =?UTF-8?q?Set=20background=20calendar=20color=20to=20red?= =?UTF-8?q?=20or=20yellow=20when=20one=20account=20is=20negative=20or=20le?= =?UTF-8?q?ss=20than=20200=E2=82=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/KissCount.hpp | 4 +- src/view/AccountPanel.cpp | 93 ++++++++++++++++++++++++++++++------ 2 files changed, 81 insertions(+), 16 deletions(-) diff --git a/src/controller/KissCount.hpp b/src/controller/KissCount.hpp index 7e3ebbf..24a9c3c 100644 --- a/src/controller/KissCount.hpp +++ b/src/controller/KissCount.hpp @@ -1,5 +1,5 @@ /* - Copyright 2010-2015 Grégory Soutadé + Copyright 2010-2016 Grégory Soutadé This file is part of KissCount. @@ -30,7 +30,7 @@ #include -#define APP_VERSION "0.6" +#define APP_VERSION "0.7" #define ESCAPE_CHARS(s) s = s.replace("\"", " "); // #define ESCAPE_CHARS(s) s = s.replace("\"", "\\\""); s = s.replace("\'", "\\\'"); diff --git a/src/view/AccountPanel.cpp b/src/view/AccountPanel.cpp index 8e6bee8..6efb093 100644 --- a/src/view/AccountPanel.cpp +++ b/src/view/AccountPanel.cpp @@ -506,11 +506,12 @@ void AccountPanel::InitAccountsGrid(User* user, int month, int year) void AccountPanel::UpdateStats() { - int i; + int i, nbDays, minimalValue; User* user = _kiss->GetUser(); std::vector::iterator it; int curCredit, curDebit, totalCredit, totalDebit, balance, value, value2, percents; - std::map curAccountAmount, finalAccountAmount; + std::map finalAccountAmount; + std::map* curAccountAmounts; // For each day std::map::iterator intIt; std::vector::iterator accountIt; unsigned int day; @@ -521,6 +522,10 @@ void AccountPanel::UpdateStats() Operation op; bool blocked_account ; QString v; + QDate selectedDate; + QTextCharFormat textFormat; + QBrush brush; + int minStartAccount = 0; _inModification = true; @@ -536,19 +541,24 @@ void AccountPanel::UpdateStats() if (mode == REAL_MODE || mode == CHECK_MODE) virtuals = _kiss->GetVirtualAmount(_curMonth, _curYear); - day = _calendar->selectedDate().day()-1; + selectedDate = _calendar->selectedDate(); + day = selectedDate.day()-1; + nbDays = selectedDate.daysInMonth(); + curAccountAmounts = new std::map[nbDays]; for (i=0; iGetCategoriesNumber(); i++) _categoriesValues[i] = 0.0; for (intIt=_accountsInitValues.begin(); intIt!=_accountsInitValues.end(); intIt++) { - curAccountAmount[intIt->first] = _accountsInitValues[intIt->first]; - finalAccountAmount[intIt->first] = _accountsInitValues[intIt->first]; + finalAccountAmount[intIt->first] = _accountsInitValues[intIt->first]; + for(i=0; ifirst] = _accountsInitValues[intIt->first]; if (mode == REAL_MODE || mode == CHECK_MODE) { - curAccountAmount[intIt->first] += -(*virtuals)[intIt->first]; + for(i=0; ifirst] += -(*virtuals)[intIt->first]; finalAccountAmount[intIt->first] += -(*virtuals)[intIt->first]; } } @@ -590,9 +600,7 @@ void AccountPanel::UpdateStats() { if (!op.transfert && !account.blocked) curCredit += op.amount; - curAccountAmount[op.account] += op.amount; } - finalAccountAmount[op.account] += op.amount; } else { @@ -610,11 +618,67 @@ void AccountPanel::UpdateStats() if (blocked_account) op.amount = -op.amount; - - if (day >= op.day) - curAccountAmount[op.account] += op.amount; - finalAccountAmount[op.account] += op.amount; } + finalAccountAmount[op.account] += op.amount; + curAccountAmounts[op.day][op.account] += op.amount; + for(i=op.day+1; iGetAccount(intIt->first).hidden) + { + minStartAccount = intIt->first; + break; + } + } + } + + for(i=0; idateTextFormat(QDate(_curYear, _curMonth+1, i+1)); + if (mode != CHECK_MODE) + { + minimalValue = curAccountAmounts[i][minStartAccount]; + + for (intIt=curAccountAmounts[i].begin(); intIt!=curAccountAmounts[i].end(); intIt++) + { + if (user->GetAccount(intIt->first).hidden) + continue; + + if (curAccountAmounts[i][intIt->first] < minimalValue) + minimalValue = curAccountAmounts[i][intIt->first]; + } + + if (minimalValue <= 0) + { + brush.setColor(Qt::red); + textFormat.setBackground(brush); + QDate date(_curYear, _curMonth+1, i+1); + if (date.dayOfWeek() == 6 || date.dayOfWeek() == 7) + { + brush.setColor(Qt::black); + textFormat.setForeground(brush); + } + } + else if (minimalValue <= 200*100) + { + brush.setColor(QColor(240,195,0)); + textFormat.setBackground(brush); + } + else + { + textFormat.clearBackground(); + } + } + else + { + textFormat.clearBackground(); + } + _calendar->setDateTextFormat(QDate(_curYear, _curMonth+1, i+1), textFormat); } balance = totalCredit - totalDebit; @@ -640,7 +704,7 @@ void AccountPanel::UpdateStats() if (mode == REAL_MODE) value -= (*virtuals)[accountIt->id]; _accountsGrid->item(i, ACCOUNT_INIT)->setText(v.sprintf("%.2lf", (double)value/100)); - value = curAccountAmount[accountIt->id]; + value = curAccountAmounts[day][accountIt->id]; _accountsGrid->item(i, ACCOUNT_CUR)->setText(v.sprintf("%.2lf", (double)value/100)); _accountsGrid->item(i, ACCOUNT_CUR)->setForeground((value >= 0) ? QBrush(Qt::black) : QBrush(Qt::red)); value = finalAccountAmount[accountIt->id]; @@ -652,7 +716,7 @@ void AccountPanel::UpdateStats() value2 = (*notChecked)[accountIt->id]; _accountsGrid->item(i, ACCOUNT_INIT)->setText(v.sprintf("%.2lf (%.2lf)", (double)value/100, (double)(value-value2)/100)); - value = curAccountAmount[accountIt->id]; + value = curAccountAmounts[day][accountIt->id]; _accountsGrid->item(i, ACCOUNT_CUR)->setText(v.sprintf("%.2lf (%.2lf)", (double)value/100, (double)(value-value2)/100)); _accountsGrid->item(i, ACCOUNT_CUR)->setForeground((value >= 0) ? QBrush(Qt::black) : QBrush(Qt::red)); value = finalAccountAmount[accountIt->id]; @@ -668,6 +732,7 @@ void AccountPanel::UpdateStats() if (notChecked) delete notChecked; if (virtuals) delete virtuals; + delete[] curAccountAmounts; _statsGrid->resizeColumnToContents(1);