1 /*
2  * Copyright 2017-2018  Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef KMYMONEYACCOUNTSVIEWBASE_P_H
19 #define KMYMONEYACCOUNTSVIEWBASE_P_H
20 
21 // ----------------------------------------------------------------------------
22 // QT Includes
23 
24 #include <QLabel>
25 
26 // ----------------------------------------------------------------------------
27 // KDE Includes
28 
29 #include "KLocalizedString"
30 
31 // ----------------------------------------------------------------------------
32 // Project Includes
33 
34 #include "mymoneyutils.h"
35 #include "kmymoneyviewbase_p.h"
36 #include "kmymoneysettings.h"
37 #include "mymoneyfile.h"
38 #include "mymoneymoney.h"
39 #include "mymoneysecurity.h"
40 #include "viewenums.h"
41 
42 class AccountsViewProxyModel;
43 class KMyMoneyAccountTreeView;
44 class KMyMoneyAccountsViewBasePrivate : public KMyMoneyViewBasePrivate
45 {
46 public:
KMyMoneyAccountsViewBasePrivate()47   KMyMoneyAccountsViewBasePrivate() :
48     m_proxyModel(nullptr),
49     m_accountTree(nullptr)
50   {
51   }
52 
~KMyMoneyAccountsViewBasePrivate()53   ~KMyMoneyAccountsViewBasePrivate()
54   {
55   }
56 
netBalProChanged(const MyMoneyMoney & val,QLabel * label,const View view)57   void netBalProChanged(const MyMoneyMoney &val, QLabel *label, const View view)
58   {
59     QString s;
60     const auto isNegative = val.isNegative();
61     switch (view) {
62       case View::Institutions:
63       case View::Accounts:
64         s = i18n("Net Worth: ");
65         break;
66       case View::Categories:
67         if (isNegative)
68           s = i18n("Loss: ");
69         else
70           s = i18n("Profit: ");
71         break;
72       case View::Budget:
73         s = (i18nc("The balance of the selected budget", "Balance: "));
74         break;
75       default:
76         return;
77     }
78 
79     // FIXME figure out how to deal with the approximate
80     // if(!(file->totalValueValid(assetAccount.id()) & file->totalValueValid(liabilityAccount.id())))
81     //  s += "~ ";
82 
83     s.replace(QLatin1Char(' '), QLatin1String("&nbsp;"));
84 
85     if (isNegative)
86       s.append(QLatin1String("<b><font color=\"red\">"));
87     const auto sec = MyMoneyFile::instance()->baseCurrency();
88     QString v(MyMoneyUtils::formatMoney(val, sec));
89     s.append((v.replace(QLatin1Char(' '), QLatin1String("&nbsp;"))));
90     if (isNegative)
91       s.append(QLatin1String("</font></b>"));
92 
93     label->setFont(KMyMoneySettings::listCellFontEx());
94     label->setText(s);
95   }
96 
97   AccountsViewProxyModel  *m_proxyModel;
98   KMyMoneyAccountTreeView **m_accountTree;
99 };
100 
101 #endif
102