-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdragscrollarea.h
45 lines (35 loc) · 955 Bytes
/
dragscrollarea.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
/*
* dragscrollarea.h
* MazeGenerator
*
* Copyright 2018 Matthew T. Pandina. All rights reserved.
*
*/
#ifndef DRAGSCROLLAREA_H
#define DRAGSCROLLAREA_H
#include <QScrollArea>
#include <QPoint>
#include <QCursor>
class DragScrollArea : public QScrollArea
{
Q_PROPERTY(DragMode dragMode READ dragMode WRITE setDragMode)
public:
enum DragMode {
NoDrag,
ScrollHandDrag
};
Q_ENUM(DragMode)
explicit DragScrollArea(QWidget *parent = nullptr);
DragScrollArea::DragMode getDragMode() const;
void setDragMode(const DragScrollArea::DragMode &value);
protected:
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
private:
QPoint lastPosition;
QCursor originalCursor;
DragMode dragMode = DragMode::ScrollHandDrag;
bool handScrolling = false;
};
#endif // DRAGSCROLLAREA_H