• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ossia / score / 30237868584

27 Jul 2026 04:43AM UTC coverage: 15.388% (+0.09%) from 15.298%
30237868584

Pull #2146

github

web-flow
Merge 648972a7d into d36abedc4
Pull Request #2146: Per-platform relative mouse motion (pointer lock) instead of cursor warping

120 of 181 new or added lines in 7 files covered. (66.3%)

422 existing lines in 6 files now uncovered.

30591 of 198799 relevant lines covered (15.39%)

1072.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/src/lib/score/graphics/widgets/QGraphicsNoteChooser.cpp
1
#include <score/graphics/InfiniteScroller.hpp>
2
#include <score/graphics/widgets/QGraphicsNoteChooser.hpp>
3
#include <score/model/Skin.hpp>
4

5
#include <ossia/detail/math.hpp>
6

7
#include <QGraphicsSceneMouseEvent>
8
#include <QPainter>
9

10
#include <wobjectimpl.h>
11
namespace score
12
{
13
namespace
14
{
15
constexpr double pixelsPerNote = 10.;
16

17
double dragValue(QGraphicsSceneMouseEvent* event, int min, int max) noexcept
9✔
18
{
19
  InfiniteScroller::move_free(event);
9✔
20

21
  double v = InfiniteScroller::origValue - InfiniteScroller::currentDelta / pixelsPerNote;
9✔
22
  if(v <= min)
9✔
23
  {
NEW
24
    InfiniteScroller::currentDelta = (InfiniteScroller::origValue - min) * pixelsPerNote;
×
NEW
25
    v = min;
×
NEW
26
  }
×
27
  else if(v >= max)
9✔
28
  {
29
    InfiniteScroller::currentDelta = (InfiniteScroller::origValue - max) * pixelsPerNote;
1✔
30
    v = max;
1✔
31
  }
1✔
32
  return v;
9✔
33
}
34
}
35

36
QRectF QGraphicsNoteChooser::boundingRect() const
3✔
37
{
38
  return {0, 0, m_width, m_height};
3✔
39
}
40

41
QGraphicsNoteChooser::QGraphicsNoteChooser(QGraphicsItem* parent)
3✔
42
    : QGraphicsItem{parent}
3✔
43
{
3✔
44
  auto& skin = score::Skin::instance();
3✔
45
  setCursor(skin.CursorScaleV);
3✔
46
  this->setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton);
3✔
47
}
×
48

49
void QGraphicsNoteChooser::setValue(int v)
3✔
50
{
51
  switch(v)
3✔
52
  {
53
    case 255:
54
      m_value = -1;
×
55
      break;
×
56
    case 254:
57
      m_value = -2;
×
58
      break;
×
59
    default:
60
      m_value = ossia::clamp(v, m_min, m_max);
3✔
61
      break;
3✔
62
  }
63

64
  update();
3✔
65
}
3✔
66

67
int QGraphicsNoteChooser::value() const
9✔
68
{
69
  return m_value;
9✔
70
}
71

72
void QGraphicsNoteChooser::mousePressEvent(QGraphicsSceneMouseEvent* event)
3✔
73
{
74
  const auto srect = boundingRect();
3✔
75
  if(srect.contains(event->pos()))
3✔
76
  {
77
    m_grab = true;
3✔
78
    m_curValue = m_value;
3✔
79
    InfiniteScroller::start(*this, m_value);
3✔
80
  }
3✔
81

82
  event->accept();
3✔
83
}
3✔
84

85
void QGraphicsNoteChooser::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
6✔
86
{
87
  if(m_grab)
6✔
88
  {
89
    m_curValue = dragValue(event, m_min, m_max);
6✔
90

91
    if(int res = std::round(m_curValue); res != m_value)
6✔
92
    {
93
      m_value = res;
6✔
94
      sliderMoved();
6✔
95
      update();
6✔
96
    }
6✔
97
  }
6✔
98
  event->accept();
6✔
99
}
6✔
100

101
void QGraphicsNoteChooser::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
3✔
102
{
103
  if(m_grab)
3✔
104
  {
105
    m_curValue = dragValue(event, m_min, m_max);
3✔
106
    if(int res = std::round(m_curValue); res != m_value)
3✔
107
    {
NEW
108
      m_value = res;
×
NEW
109
      update();
×
NEW
110
    }
×
111

112
    InfiniteScroller::stop(*this, event);
3✔
113

114
    m_grab = false;
3✔
115
    sliderReleased();
3✔
116

117
    setCursor(score::Skin::instance().CursorScaleV);
3✔
118
  }
3✔
119
  event->accept();
3✔
120
}
3✔
121

122
static QString noteText(int n)
×
123
{
124
  static constexpr QStringView lit[12]{u"C",  u"C#", u"D",  u"D#", u"E",  u"F",
125
                                       u"F#", u"G",  u"G#", u"A",  u"A#", u"B"};
126
  switch(n)
×
127
  {
128
    case -1:
129
      return "AC";
×
130
    case -2:
131
      return "SL";
×
132
    default:
133
      return QString{"%1%2"}.arg(lit[n % 12]).arg(n / 12 - 1);
×
134
  }
135
}
×
136

137
void QGraphicsNoteChooser::paint(
×
138
    QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
139
{
140
  auto& style = score::Skin::instance();
×
141
  //const QPen& text = style.Gray.main.pen1;
142
  const QFont& textFont = style.MonoFontSmall;
×
143
  const QPen& currentText = style.Base4.lighter180.pen1;
×
144
  // const QBrush& bg = style.SliderBrush;
145
  // const QPen& noPen = style.NoPen;
146

147
  painter->setFont(textFont);
×
148
  //painter->setPen(noPen);
149
  //painter->setBrush(bg);
150

151
  //painter->drawRect(boundingRect());
152
  painter->setPen(currentText);
×
153
  painter->drawText(
×
154
      boundingRect(), QString{"%1\n%2"}.arg(noteText(m_value)).arg(m_value),
×
155
      QTextOption(Qt::AlignLeft));
×
156
}
×
157
}
158

159
W_OBJECT_IMPL(score::QGraphicsNoteChooser)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc