1 /*
2  * Copyright 2002       Michael Edwardes <mte@users.sourceforge.net>
3  * Copyright 2002-2011  Thomas Baumgart <tbaumgart@kde.org>
4  * Copyright 2017-2018  Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef KSPLITTRANSACTIONDLG_H
21 #define KSPLITTRANSACTIONDLG_H
22 
23 // ----------------------------------------------------------------------------
24 // QT Includes
25 
26 #include <QDialog>
27 
28 // ----------------------------------------------------------------------------
29 // KDE Includes
30 
31 // ----------------------------------------------------------------------------
32 // Project Includes
33 
34 class MyMoneyMoney;
35 class MyMoneySplit;
36 class MyMoneyTransaction;
37 class MyMoneyAccount;
38 class MyMoneyTag;
39 
40 namespace Ui { class KSplitCorrectionDlg; }
41 
42 class KSplitCorrectionDlg : public QDialog
43 {
44   Q_OBJECT
45   Q_DISABLE_COPY(KSplitCorrectionDlg)
46 
47 public:
48   explicit KSplitCorrectionDlg(QWidget *parent = nullptr);
49   ~KSplitCorrectionDlg();
50 
51   Ui::KSplitCorrectionDlg *ui;
52 };
53 
54 /**
55   * @author Thomas Baumgart
56   */
57 
58 class KSplitTransactionDlgPrivate;
59 class KSplitTransactionDlg : public QDialog
60 {
61   Q_OBJECT
62   Q_DISABLE_COPY(KSplitTransactionDlg)
63 
64 public:
65   explicit KSplitTransactionDlg(const MyMoneyTransaction& t,
66                                 const MyMoneySplit& s,
67                                 const MyMoneyAccount& acc,
68                                 const bool amountValid,
69                                 const bool deposit,
70                                 const MyMoneyMoney& calculatedValue,
71                                 const QMap<QString, MyMoneyMoney>& priceInfo,
72                                 QWidget* parent = nullptr);
73 
74   ~KSplitTransactionDlg();
75 
76   /**
77     * Using this method, an external object can retrieve the result
78     * of the dialog.
79     *
80     * @return MyMoneyTransaction based on the transaction passes during
81     *         the construction of this object and modified using the
82     *         dialog.
83     */
84   MyMoneyTransaction transaction() const;
85 
86   /**
87     * This method calculates the difference between the split that references
88     * the account passed as argument to the constructor of this object and
89     * all the other splits shown in the register of this dialog.
90     *
91     * @return difference as MyMoneyMoney object
92     */
93   MyMoneyMoney diffAmount();
94 
95   /**
96     * This method calculates the sum of the splits shown in the register
97     * of this dialog.
98     *
99     * @return sum of splits as MyMoneyMoney object
100     */
101   MyMoneyMoney splitsValue();
102 
103 public Q_SLOTS:
104   int exec() override;
105 
106 protected Q_SLOTS:
107   void accept() override;
108   void reject() override;
109   void slotClearAllSplits();
110   void slotClearUnusedSplits();
111   void slotSetTransaction(const MyMoneyTransaction& t);
112   void slotCreateCategory(const QString& txt, QString& id);
113   void slotCreateTag(const QString &txt, QString &id);
114   void slotUpdateButtons();
115   void slotMergeSplits();
116   void slotEditStarted();
117 
118   /// used internally to setup the initial size of all widgets
119   void initSize();
120 
121 Q_SIGNALS:
122   /**
123     * This signal is sent out, when a new category needs to be created
124     * Depending on the setting of either a payment or deposit, the parent
125     * account will be preset to Expense or Income.
126     *
127     * @param account reference to account info. Will be filled by called slot
128     * @param parent reference to parent account
129     */
130   void createCategory(MyMoneyAccount& account, const MyMoneyAccount& parent);
131 
132   /**
133     * This signal is sent out, when a new tag needs to be created
134     * @param txt The name of the tag to be created
135     * @param id A connected slot should store the id of the created object in this variable
136     */
137   void createTag(const QString& txt, QString& id);
138 
139   /**
140     * Signal is emitted, if any of the widgets enters (@a state equals @a true)
141     *  or leaves (@a state equals @a false) object creation mode.
142     *
143     * @param state Enter (@a true) or leave (@a false) object creation
144     */
145   void objectCreation(bool state);
146 
147 private:
148   KSplitTransactionDlgPrivate * const d_ptr;
149   Q_DECLARE_PRIVATE(KSplitTransactionDlg)
150 };
151 
152 #endif
153