File: versionlistdelegate.h

package info (click to toggle)
kup-backup 0.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,576 kB
  • sloc: cpp: 8,422; xml: 311; makefile: 6; sh: 3
file content (99 lines) | stat: -rw-r--r-- 2,592 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// SPDX-FileCopyrightText: 2020 Simon Persson <simon.persson@mykolab.com>
//
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL

#ifndef VERSIONLISTDELEGATE_H
#define VERSIONLISTDELEGATE_H

#include <QAbstractItemDelegate>
#include <QParallelAnimationGroup>

class Button : public QObject
{
    Q_OBJECT

public:
    Button(QString pText, QWidget *pParent);
    bool mPushed;
    QStyleOptionButton mStyleOption;
    QWidget *mParent;

    void setPosition(const QPoint &pTopRight);
    void paint(QPainter *pPainter, float pOpacity);
    bool event(QEvent *pEvent) override;

signals:
    void focusChangeRequested(bool pForward);
};

class VersionItemAnimation : public QParallelAnimationGroup
{
    Q_OBJECT
    Q_PROPERTY(float extraHeight READ extraHeight WRITE setExtraHeight)
    Q_PROPERTY(float opacity READ opacity WRITE setOpacity)

public:
    explicit VersionItemAnimation(QWidget *pParent);
    ~VersionItemAnimation()
    {
        delete mOpenButton;
        delete mRestoreButton;
    }
    qreal extraHeight()
    {
        return mExtraHeight;
    }
    float opacity()
    {
        return mOpacity;
    }

signals:
    void sizeChanged(const QModelIndex &pIndex);

public slots:
    void setExtraHeight(qreal pExtraHeight);
    void setOpacity(float pOpacity)
    {
        mOpacity = pOpacity;
    }
    void changeFocus(bool pForward);
    void setFocus(bool pFocused);

public:
    QPersistentModelIndex mIndex;
    qreal mExtraHeight;
    float mOpacity;
    Button *mOpenButton;
    Button *mRestoreButton;
    QWidget *mParent;
};

class VersionListDelegate : public QAbstractItemDelegate
{
    Q_OBJECT
public:
    explicit VersionListDelegate(QAbstractItemView *pItemView, QObject *pParent = nullptr);
    ~VersionListDelegate() override;
    void paint(QPainter *pPainter, const QStyleOptionViewItem &pOption, const QModelIndex &pIndex) const override;
    QSize sizeHint(const QStyleOptionViewItem &pOption, const QModelIndex &pIndex) const override;
    bool eventFilter(QObject *pObject, QEvent *pEvent) override;

signals:
    void openRequested(const QModelIndex &pIndex);
    void restoreRequested(const QModelIndex &pIndex);

public slots:
    void updateCurrent(const QModelIndex &pCurrent, const QModelIndex &pPrevious);
    void reset();
    void reclaimAnimation();

protected:
    void initialize();
    QAbstractItemView *mView;
    QAbstractItemModel *mModel;
    QHash<QPersistentModelIndex, VersionItemAnimation *> mActiveAnimations;
    QList<VersionItemAnimation *> mInactiveAnimations;
};

#endif // VERSIONLISTDELEGATE_H