File indexing completed on 2024-05-19 05:08:31
0001 /* 0002 SPDX-FileCopyrightText: 2021 Thomas Baumgart <tbaumgart@kde.org> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #ifndef CREDITDEBITEDIT_H 0007 #define CREDITDEBITEDIT_H 0008 0009 // #include <qobjectdefs.h> 0010 0011 #include "kmm_base_widgets_export.h" 0012 0013 // ---------------------------------------------------------------------------- 0014 // QT Includes 0015 0016 #include <QWidget> 0017 0018 // ---------------------------------------------------------------------------- 0019 // KDE Includes 0020 0021 // ---------------------------------------------------------------------------- 0022 // Project Includes 0023 0024 #include "multicurrencyedit.h" 0025 0026 class MyMoneyMoney; 0027 class MyMoneySecurity; 0028 0029 class CreditDebitEditPrivate; 0030 class KMM_BASE_WIDGETS_EXPORT CreditDebitEdit : public QWidget, public MultiCurrencyEdit 0031 { 0032 Q_OBJECT 0033 Q_DISABLE_COPY(CreditDebitEdit) 0034 0035 public: 0036 explicit CreditDebitEdit(QWidget* parent); 0037 ~CreditDebitEdit(); 0038 0039 /** 0040 * Returns the value of the widget that is filled. 0041 * A credit is returned as negative, a debit as positive value. 0042 */ 0043 MyMoneyMoney value() const override; 0044 MyMoneyMoney shares() const override; 0045 0046 /** 0047 * Loads the value of the widgets with the @a amount passed. If 0048 * @a amount is negative it is loaded into the credit 0049 * widget, otherwise into the debit widget. 0050 */ 0051 void setValue(const MyMoneyMoney& amount) override; 0052 void setShares(const MyMoneyMoney& amount) override; 0053 0054 /** 0055 * This method returns true if at least one 0056 * of the two widgets is filled with text. 0057 * It returns false if both widgets are empty. 0058 */ 0059 bool haveValue() const; 0060 0061 void setCommodity(const MyMoneySecurity& commodity) override; 0062 void setValueCommodity(const MyMoneySecurity& commodity) override; 0063 MyMoneySecurity valueCommodity() const override; 0064 void setSharesCommodity(const MyMoneySecurity& commodity) override; 0065 MyMoneySecurity sharesCommodity() const override; 0066 0067 void setInitialExchangeRate(const MyMoneyMoney& price) override; 0068 MyMoneyMoney initialExchangeRate() const override; 0069 0070 QWidget* widget() override; 0071 0072 void swapCreditDebit(); 0073 0074 /** 0075 * @sa AmountEdit::setAllowEmpty() 0076 */ 0077 void setAllowEmpty(bool allowed = true); 0078 0079 void setPlaceholderText(const QString& creditText, const QString& debitText); 0080 0081 DisplayState displayState() const override; 0082 0083 void setDisplayState(MultiCurrencyEdit::DisplayState state) override; 0084 0085 bool hasMultipleCurrencies() const override; 0086 0087 int precision(MultiCurrencyEdit::DisplayState state) const override; 0088 0089 public Q_SLOTS: 0090 /** 0091 * Show the symbol next to the edit field in case 0092 * @a symbol is not empty. Hide it, in case it 0093 * is empty. 0094 */ 0095 void setCurrencySymbol(const QString& symbol, const QString& name); 0096 0097 Q_SIGNALS: 0098 void amountChanged(); 0099 0100 private Q_SLOTS: 0101 void creditChanged(); 0102 void debitChanged(); 0103 0104 private: 0105 CreditDebitEditPrivate* const d_ptr; 0106 Q_DECLARE_PRIVATE(CreditDebitEdit) 0107 }; 0108 0109 #endif