File indexing completed on 2024-04-21 05:46:29

0001 // SPDX-FileCopyrightText: 2020 Simon Persson <simon.persson@mykolab.com>
0002 //
0003 // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 
0005 #ifndef VERSIONLISTDELEGATE_H
0006 #define VERSIONLISTDELEGATE_H
0007 
0008 #include <QAbstractItemDelegate>
0009 #include <QParallelAnimationGroup>
0010 
0011 class Button : public QObject {
0012     Q_OBJECT
0013 
0014 public:
0015     Button(QString pText, QWidget *pParent);
0016     bool mPushed;
0017     QStyleOptionButton mStyleOption;
0018     QWidget *mParent;
0019 
0020     void setPosition(const QPoint &pTopRight);
0021     void paint(QPainter *pPainter, float pOpacity);
0022     bool event(QEvent *pEvent) override;
0023 
0024 signals:
0025     void focusChangeRequested(bool pForward);
0026 };
0027 
0028 class VersionItemAnimation : public QParallelAnimationGroup
0029 {
0030     Q_OBJECT
0031     Q_PROPERTY(float extraHeight READ extraHeight WRITE setExtraHeight)
0032     Q_PROPERTY(float opacity READ opacity WRITE setOpacity)
0033 
0034 public:
0035     explicit VersionItemAnimation(QWidget *pParent);
0036     ~VersionItemAnimation() {
0037         delete mOpenButton;
0038         delete mRestoreButton;
0039     }
0040     qreal extraHeight() {return mExtraHeight;}
0041     float opacity() {return mOpacity;}
0042 
0043 signals:
0044     void sizeChanged(const QModelIndex &pIndex);
0045 
0046 public slots:
0047     void setExtraHeight(qreal pExtraHeight);
0048     void setOpacity(float pOpacity) {mOpacity = pOpacity;}
0049     void changeFocus(bool pForward);
0050     void setFocus(bool pFocused);
0051 
0052 public:
0053     QPersistentModelIndex mIndex;
0054     qreal mExtraHeight;
0055     float mOpacity;
0056     Button *mOpenButton;
0057     Button *mRestoreButton;
0058     QWidget *mParent;
0059 };
0060 
0061 class VersionListDelegate : public QAbstractItemDelegate
0062 {
0063     Q_OBJECT
0064 public:
0065     explicit VersionListDelegate(QAbstractItemView *pItemView, QObject *pParent = nullptr);
0066     ~VersionListDelegate() override;
0067     void paint(QPainter *pPainter, const QStyleOptionViewItem &pOption, const QModelIndex &pIndex) const override;
0068     QSize sizeHint(const QStyleOptionViewItem &pOption, const QModelIndex &pIndex) const override;
0069     bool eventFilter(QObject *pObject, QEvent *pEvent) override;
0070 
0071 signals:
0072     void openRequested(const QModelIndex &pIndex);
0073     void restoreRequested(const QModelIndex &pIndex);
0074 
0075 public slots:
0076     void updateCurrent(const QModelIndex &pCurrent, const QModelIndex &pPrevious);
0077     void reset();
0078     void reclaimAnimation();
0079 
0080 protected:
0081     void initialize();
0082     QAbstractItemView *mView;
0083     QAbstractItemModel *mModel;
0084     QHash<QPersistentModelIndex, VersionItemAnimation *> mActiveAnimations;
0085     QList<VersionItemAnimation *> mInactiveAnimations;
0086 };
0087 
0088 #endif // VERSIONLISTDELEGATE_H