File indexing completed on 2024-05-12 16:43:52

0001 /*
0002     SPDX-FileCopyrightText: 2015 Thomas Baumgart <tbaumgart@kde.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef LEDGERDELEGATE_H
0007 #define LEDGERDELEGATE_H
0008 
0009 // ----------------------------------------------------------------------------
0010 // QT Includes
0011 
0012 #include <QStyledItemDelegate>
0013 class QColor;
0014 
0015 // ----------------------------------------------------------------------------
0016 // KDE Includes
0017 
0018 // ----------------------------------------------------------------------------
0019 // Project Includes
0020 
0021 #include "ledgermodel.h"
0022 #include "modelenums.h"
0023 
0024 class LedgerView;
0025 class MyMoneyMoney;
0026 
0027 class LedgerSeparator
0028 {
0029 public:
0030     explicit LedgerSeparator(eLedgerModel::Role role) : m_role(role) {}
0031     virtual ~LedgerSeparator() {}
0032 
0033     virtual bool rowHasSeparator(const QModelIndex& index) const = 0;
0034     virtual QString separatorText(const QModelIndex& index) const = 0;
0035 
0036     virtual void adjustBackgroundScheme(QPalette& palette, const QModelIndex& index) const = 0;
0037 
0038     static void setFirstFiscalDate(int firstMonth, int firstDay);
0039     static void setShowFiscalDate(bool show) {
0040         showFiscalDate = show;
0041     }
0042     static void setShowFancyDate(bool show) {
0043         showFancyDate = show;
0044     }
0045 
0046 protected:
0047     inline QModelIndex nextIndex(const QModelIndex& index) const;
0048 
0049     eLedgerModel::Role         m_role;
0050 
0051     static QDate firstFiscalDate;
0052     static bool  showFiscalDate;
0053     static bool  showFancyDate;
0054 };
0055 
0056 
0057 
0058 class LedgerDelegate : public QStyledItemDelegate
0059 {
0060     Q_OBJECT
0061 public:
0062     explicit LedgerDelegate(LedgerView* parent = 0);
0063     virtual ~LedgerDelegate();
0064 
0065     void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const final override;
0066     QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const final override;
0067     QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const final override;
0068     void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const final override;
0069     void setEditorData(QWidget* editWidget, const QModelIndex& index) const final override;
0070 
0071     virtual void setSortRole(eLedgerModel::Role role);
0072 
0073     void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const final override;
0074 
0075     /**
0076      * This method returns the row that currently has an editor
0077      * or -1 if no editor is open
0078      */
0079     virtual int editorRow() const;
0080 
0081     void setOnlineBalance(const QDate& date, const MyMoneyMoney& amount, int fraction = 0);
0082 
0083     static void setErroneousColor(const QColor& color);
0084     static void setImportedColor(const QColor& color);
0085 
0086     static QColor erroneousColor();
0087 
0088 protected:
0089     bool eventFilter(QObject* o, QEvent* event) final override;
0090 
0091 protected Q_SLOTS:
0092     void endEdit();
0093 
0094 Q_SIGNALS:
0095     void sizeHintChanged(const QModelIndex&) const;
0096 
0097 private:
0098     class Private;
0099     Private * const d;
0100 
0101     static QColor m_erroneousColor;
0102     static QColor m_importedColor;
0103     static QColor m_separatorColor;
0104 };
0105 
0106 #endif // LEDGERDELEGATE_H
0107