InfiniteScroller.hpp
1 #pragma once
2 #include <score/tools/Cursor.hpp>
3 
4 #include <QGraphicsItem>
5 #include <QGuiApplication>
6 #include <QScreen>
7 
8 namespace 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  currentGeometry = qGuiApp->primaryScreen()->availableGeometry();
27  }
28 
29  static void move_free(QGraphicsSceneMouseEvent* event)
30  {
31  auto delta = (event->screenPos().y() - event->lastScreenPos().y());
32  double ratio = qGuiApp->keyboardModifiers() & Qt::CTRL ? 0.2 : 1.;
33  if(std::abs(delta) < 500)
34  {
35  currentSpeed = ratio * delta;
36  currentDelta += ratio * delta;
37  }
38 
39  const double max = currentGeometry.height();
40  if(event->screenPos().y() <= 100)
41  {
42  score::setCursorPos(QPointF(event->screenPos().x(), max - 101));
43  }
44  else if(event->screenPos().y() >= (max - 100))
45  {
46  score::setCursorPos(QPointF(event->screenPos().x(), 101));
47  }
48  }
49 
50  static double move(QGraphicsSceneMouseEvent* event)
51  {
52  move_free(event);
53 
54  const double max = currentGeometry.height();
55  double v = origValue - currentDelta / max;
56  if(v <= 0.)
57  {
58  currentDelta = origValue * max;
59  v = 0.;
60  }
61  else if(v >= 1.)
62  {
63  currentDelta = ((origValue - 1.) * max);
64  v = 1.;
65  }
66 
67  return v;
68  }
69 
70  static void stop(QGraphicsItem& self, QGraphicsSceneMouseEvent* event)
71  {
72  score::setCursorPos(event->buttonDownScreenPos(Qt::LeftButton));
73  self.unsetCursor();
74  }
75 };
76 }
Base toolkit upon which the software is built.
Definition: Application.cpp:90
Definition: InfiniteScroller.hpp:12