File indexing completed on 2024-05-12 05:07:37
0001 /* 0002 SPDX-FileCopyrightText: 2015-2019 Thomas Baumgart <tbaumgart@kde.org> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #ifndef JOURNALDELEGATE_H 0007 #define JOURNALDELEGATE_H 0008 0009 // ---------------------------------------------------------------------------- 0010 // QT Includes 0011 0012 #include <kmmstyleditemdelegate.h> 0013 class QColor; 0014 0015 // ---------------------------------------------------------------------------- 0016 // KDE Includes 0017 0018 // ---------------------------------------------------------------------------- 0019 // Project Includes 0020 0021 #include "mymoneyenums.h" 0022 0023 class LedgerView; 0024 class MyMoneyMoney; 0025 0026 class JournalDelegate : public KMMStyledItemDelegate 0027 { 0028 Q_OBJECT 0029 public: 0030 explicit JournalDelegate(LedgerView* parent = 0); 0031 virtual ~JournalDelegate(); 0032 0033 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const final override; 0034 QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const final override; 0035 QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const final override; 0036 void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const final override; 0037 void setEditorData(QWidget* editWidget, const QModelIndex& index) const final override; 0038 0039 void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const final override; 0040 0041 /** 0042 * This method returns the row that currently has an editor 0043 * or -1 if no editor is open 0044 */ 0045 virtual int editorRow() const; 0046 0047 void setOnlineBalance(const QDate& date, const MyMoneyMoney& amount, int fraction = 0); 0048 0049 /** 0050 * Which data (@a role) shall be displayed in the detail column 0051 * when only a single line is shown. The default is the payee. 0052 */ 0053 void setSingleLineRole(eMyMoney::Model::Roles role); 0054 0055 /** 0056 * If @a show is @c true, the payee name is shown in the 0057 * detail column if no payee column is present. During the 0058 * creation of a JournalDelegate this is set to @c true. 0059 */ 0060 void setShowPayeeInDetailColumn(bool show); 0061 0062 void setAccountType(eMyMoney::Account::Type accountType); 0063 0064 static void setErroneousColor(const QColor& color); 0065 static void setImportedColor(const QColor& color); 0066 0067 static QColor erroneousColor(); 0068 0069 /** 0070 * The maximum number of icons that can show up in parallel on 0071 * a transaction. 0072 */ 0073 static int maxIcons() 0074 { 0075 return 3; 0076 } 0077 0078 /** 0079 * This will force the next call to sizeHint to re-calculate 0080 * the size of a single line. Should be called when the font 0081 * characteristics change. 0082 */ 0083 void resetLineHeight(); 0084 0085 protected: 0086 bool eventFilter(QObject* o, QEvent* event) final override; 0087 0088 protected Q_SLOTS: 0089 void endEdit(); 0090 0091 private: 0092 class Private; 0093 Private * const d; 0094 0095 static QColor m_erroneousColor; 0096 static QColor m_importedColor; 0097 static QColor m_separatorColor; 0098 }; 0099 0100 #endif // JOURNALDELEGATE_H 0101