Loading...
Searching...
No Matches
InfiniteScroller.hpp
1#pragma once
2#include <score/tools/Cursor.hpp>
3
4#include <QGraphicsItem>
5#include <QGuiApplication>
6#include <QScreen>
7
8namespace score
9{
10
12{
13 static inline QRectF currentGeometry{};
14 static inline double origValue{};
15 static inline double currentSpeed{};
16 static inline double currentDelta{};
17
18 static void start(QGraphicsItem& self, double orig)
19 {
20 currentDelta = 0.;
21 origValue = orig;
22
23#if !defined(__EMSCRIPTEN__)
24 self.setCursor(QCursor(Qt::BlankCursor));
25#endif
26 auto* screen = qGuiApp->screenAt(QCursor::pos());
27 if(!screen)
28 screen = qGuiApp->primaryScreen();
29 currentGeometry = screen->availableGeometry();
30 }
31
32 static void move_free(QGraphicsSceneMouseEvent* event)
33 {
34 auto delta = (event->screenPos().y() - event->lastScreenPos().y());
35 double ratio = qGuiApp->keyboardModifiers() & Qt::CTRL ? 0.2 : 1.;
36 if(std::abs(delta) < 500)
37 {
38 currentSpeed = ratio * delta;
39 currentDelta += ratio * delta;
40 }
41
42 const double top = currentGeometry.top();
43 const double bottom = currentGeometry.bottom();
44 if(event->screenPos().y() <= top + 100)
45 {
46 score::setCursorPos(QPointF(event->screenPos().x(), bottom - 101));
47 }
48 else if(event->screenPos().y() >= bottom - 100)
49 {
50 score::setCursorPos(QPointF(event->screenPos().x(), top + 101));
51 }
52 }
53
54 static double move(QGraphicsSceneMouseEvent* event)
55 {
56 move_free(event);
57
58 const double max = currentGeometry.height();
59 double v = origValue - currentDelta / max;
60 if(v <= 0.)
61 {
62 currentDelta = origValue * max;
63 v = 0.;
64 }
65 else if(v >= 1.)
66 {
67 currentDelta = ((origValue - 1.) * max);
68 v = 1.;
69 }
70
71 return v;
72 }
73
74 static void stop(QGraphicsItem& self, QGraphicsSceneMouseEvent* event)
75 {
76 score::setCursorPos(event->buttonDownScreenPos(Qt::LeftButton));
77 self.unsetCursor();
78 }
79};
80}
Base toolkit upon which the software is built.
Definition Application.cpp:113
Definition InfiniteScroller.hpp:12