Loading...
Searching...
No Matches
CableDragAutoScroller.hpp
1#pragma once
2#include <QObject>
3#include <QPoint>
4#include <QPointer>
5#include <QSize>
6#include <QTimer>
7
8#include <score_lib_process_export.h>
9
10#include <functional>
11
12class QGraphicsView;
13class QWidget;
14
15namespace Dataflow
16{
33class SCORE_LIB_PROCESS_EXPORT CableDragAutoScroller final : public QObject
34{
35public:
37 static constexpr int margin = 32;
39 static constexpr int maxStep = 24;
42 static constexpr int outsideLimit = 200;
43 static constexpr int intervalMs = 16;
44
46 using CursorProvider = std::function<QPoint(QWidget& viewport)>;
47
54 explicit CableDragAutoScroller(
55 std::function<void(QPointF scenePos)> onScrolled, CursorProvider cursor = {});
57
66 static QPoint scrollStep(QPoint viewportPos, QSize sz) noexcept;
67
73 void track(QWidget* viewport, QPointF scenePos);
74
79 void continueFromCursor();
80
82 void stop();
83
84 bool active() const noexcept { return m_timer.isActive(); }
85 QGraphicsView* view() const noexcept;
86
94 static bool scrollViewBy(QGraphicsView& view, QPoint delta);
96 static bool scrollBarsBy(QGraphicsView& view, QPoint delta);
97
98private:
99 void tick();
100 QPoint cursorInViewport() const;
101
102 std::function<void(QPointF)> m_onScrolled;
103 CursorProvider m_cursor;
104 QPointer<QGraphicsView> m_view{};
105 QTimer m_timer;
106};
107}
Scrolls a QGraphicsView while a cable is being dragged towards one of its edges, so that a port curre...
Definition CableDragAutoScroller.hpp:34
std::function< QPoint(QWidget &viewport)> CursorProvider
Where the cursor is, in viewport coordinates, for the given viewport.
Definition CableDragAutoScroller.hpp:46
STL namespace.