Auto scroll during drag if touching top or bottom areas of list widget

This commit is contained in:
WarmUpTill
2022-03-22 21:34:53 +01:00
committed by WarmUpTill
parent 6a8066795b
commit dbbcf04b8a
2 changed files with 87 additions and 35 deletions

View File

@@ -5,12 +5,14 @@
#include <QScrollArea>
#include <QVBoxLayout>
#include <QLabel>
#include <thread>
class MacroSegmentList : public QScrollArea {
Q_OBJECT
public:
MacroSegmentList(QWidget *parent = nullptr);
virtual ~MacroSegmentList();
void SetHelpMsg(const QString &msg);
void SetHelpMsgVisible(bool visible);
void Insert(int idx, QWidget *widget);
@@ -40,6 +42,8 @@ private:
int GetDragIndex(const QPoint &);
int GetDropIndex(const QPoint &);
int GetWidgetIdx(const QPoint &);
void CheckScroll();
void CheckDropLine(const QPoint &);
bool IsInListArea(const QPoint &);
QRect GetContentItemRectWithPadding(int idx);
void HideLastDropLine();
@@ -47,6 +51,9 @@ private:
int _dragPosition = -1;
int _dropLineIdx = -1;
QPoint _dragCursorPos;
std::thread _autoScrollThread;
std::atomic_bool _autoScroll{false};
QVBoxLayout *_layout;
QVBoxLayout *_contentLayout;