Improve drag & drop behaviour of macro segments

- Depending on the drop position you can either drop before or after a
  widget
- Added a visual indicator where the macro segment will be dropped
This commit is contained in:
WarmUpTill
2022-03-20 22:05:49 +01:00
committed by WarmUpTill
parent e0763a4957
commit 6a8066795b
4 changed files with 225 additions and 50 deletions

View File

@@ -31,15 +31,22 @@ protected:
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void dragLeaveEvent(QDragLeaveEvent *event);
void dragEnterEvent(QDragEnterEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
void dropEvent(QDropEvent *event);
private:
int GetIndex(QPoint);
int GetDropIndex(QPoint);
int GetDragIndex(const QPoint &);
int GetDropIndex(const QPoint &);
int GetWidgetIdx(const QPoint &);
bool IsInListArea(const QPoint &);
QRect GetContentItemRectWithPadding(int idx);
void HideLastDropLine();
MacroSegmentEdit *WidgetAt(int idx);
int _dragPosition = -1;
int _dropLineIdx = -1;
QVBoxLayout *_layout;
QVBoxLayout *_contentLayout;

View File

@@ -63,15 +63,38 @@ protected:
Section *_section;
QLabel *_headerInfo;
QWidget *_frame;
QFrame *_noBorderframe;
QFrame *_borderFrame;
QVBoxLayout *_contentLayout;
private:
enum class DropLineState {
NONE,
ABOVE,
BELOW,
};
virtual MacroSegment *Data() = 0;
void ShowDropLine(DropLineState);
// The reason for using two separate frame widget each with their own
// stylesheet and changing their visibility vs. using a single frame
// and changing the stylesheet at runtime is that the operation of
// adjusting the stylesheet is very expensive and can take multiple
// hundred milliseconds per widget.
// This performance impact would hurt in areas like drag and drop or
// emitting the "SelectionChanged" signal.
QFrame *_noBorderframe;
QFrame *_borderFrame;
// In most cases the line above the widget will be used.
// The lower one will only be used if the segment is the last one in
// the list.
QFrame *_dropLineAbove;
QFrame *_dropLineBelow;
bool _showHighlight;
QTimer _timer;
friend class MacroSegmentList;
};
class MouseWheelWidgetAdjustmentGuard : public QObject {