-
Notifications
You must be signed in to change notification settings - Fork 0
/
customScrollContainer.h
144 lines (108 loc) · 3 KB
/
customScrollContainer.h
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#ifndef CUSTOMSCROLLCONTAINER_H
#define CUSTOMSCROLLCONTAINER_H
#include <QWidget>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPainter>
#include <QPropertyAnimation>
#include <QParallelAnimationGroup>
#include <QSequentialAnimationGroup>
#include <QGraphicsOpacityEffect>
#include <QVector>
#include <QMouseEvent>
#include <QWheelEvent>
#include <QTimer>
#define MAXSPEED 70
class ScrollAreaCustom;
class ScrollListContainer;
class ScrollIndicator;
class ScrollAreaCustom : public QWidget
{
Q_OBJECT
private:
QTimer* getCord;
QTimer* rfrshView;
ScrollListContainer* container;
ScrollIndicator* indicator;
QPropertyAnimation* bounce;
bool pressed = false;
bool scrollDown = true;
bool outOfEdge = false;
bool ignoreMaxSpeed = false;
int strtY;
int lastY;
int bfEdgeY; //last y value before out of edge
int curSpd = 0;
int damp = 1;
int moveStored = 0;
int nextMove = 1;
void paintEvent(QPaintEvent* event);
void mousePressEvent(QMouseEvent* event);
void mouseMoveEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
void wheelEvent(QWheelEvent* event);
void bounceBack();
public:
explicit ScrollAreaCustom(QWidget *parent = nullptr);
void addWidget(QWidget* newWidget, bool setAnimation = true);
void addWidgets(QVector<QWidget*> widgets){for(int i = 0; i < widgets.size(); i++)addWidget(widgets[i], false);}
void removeWidget(QWidget* w = nullptr);
void scrollToTop();
void updateHeight();
void clear();
signals:
private slots:
void scrollContainer();
void updateSpd();
void scrollIndicator(int dp);
};
class ScrollListContainer : public QWidget
{
Q_OBJECT
public:
explicit ScrollListContainer(QWidget *parent = nullptr);
void AddWidget(QWidget* widget, bool setAnimation = true);
void RemoveWidget(QWidget* widget = nullptr);
void updateHeight();
void clear();
//void RemoveWidget(QWidget* widget);
private:
//QTimer* newWidgetFade;
int spacing = 3;
QVector<QWidget*> widgets;
int size = 0;
QVector<int> ys;
void paintEvent(QPaintEvent* event);
signals:
private slots:
};
class ScrollIndicator : public QWidget
{
Q_OBJECT
private:
QColor curColor;
QColor defaultColor = QColor(100, 100, 100, 130);
QColor hoverColor = QColor(70, 70, 70, 150);
QColor pressColor = QColor(50, 50, 50, 170);
QTimer* hovTimer;
QTimer* aniPause;
int lastY;
int defaultWidth = 2;
int defaultWidthAtFocus = 9;
int margin = 3;
bool pressed = false;
public:
explicit ScrollIndicator(QWidget *parent = nullptr);
private:
void paintEvent(QPaintEvent* event);
void enterEvent(QEnterEvent* event);
void leaveEvent(QEvent* event);
void mousePressEvent(QMouseEvent* event);
void mouseMoveEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
signals:
void scrollPage(int);
private slots:
void setHoverActive();
};
#endif // CUSTOMSCROLLCONTAINER_H