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

ossia / score / 44990834010

22 Nov 2026 05:46AM UTC coverage: 61.818% (+0.2%) from 61.617%
44990834010

push

github

jcelerier
UI: the main window opens centred on the screen under the mouse and fits a 4K screen at 300%

The window was sized from the primary screen, while Qt opens it on the
screen under the mouse. When it did not fit there, Qt left it at logical
0,0, which a screen of another scale maps outside the desktop
(x=-10248 on a 100% primary with 300% screens beside it). It is now sized
from the screen it opens on and placed at its centre, with room kept for
the title bar, and on Wayland for a panel the compositor does not report:
three quarters of the screen, but at least 1000x680 when the screen allows.

The inspector and the object tree ask for 200 and 100 px instead of 400
and 160, so the window's minimum height drops from 744 to 484 logical px.
The start screen's header shrinks from 220 to 140 px on a window shorter
than 640, so the start screen fits down to 560: a 4K screen at 300% leaves
about 590 under the macOS menu bar, dock and title bar.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KdPgugz48pdcaqHJAg2vid

266655 of 799939 branches covered (33.33%)

36 of 38 new or added lines in 4 files covered. (94.74%)

3164 existing lines in 91 files now uncovered.

271878 of 439807 relevant lines covered (61.82%)

767748.57 hits per line

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

61.84
/src/plugins/score-lib-process/Process/Dataflow/CableItem.cpp
1
#include "CableItem.hpp"
2

3
#include <score/model/Skin.hpp>
4

5
#include <Process/Dataflow/Cable.hpp>
6
#include <Process/Dataflow/NodeItem.hpp>
7
#include <Process/Dataflow/PortItem.hpp>
8
#include <Process/DocumentPlugin.hpp>
9
#include <Process/Process.hpp>
10
#include <Process/ProcessContext.hpp>
11
#include <Process/Style/ScenarioStyle.hpp>
12

13
#include <score/graphics/PainterPath.hpp>
14
#include <score/selection/Selection.hpp>
15
#include <score/selection/SelectionDispatcher.hpp>
16
#include <score/selection/SelectionStack.hpp>
17
#include <score/tools/Bind.hpp>
18

19
#include <ossia/detail/algorithms.hpp>
20

21
#include <QApplication>
22
#include <QCursor>
23
#include <Process/Dataflow/PortProbe.hpp>
24

25
#include <QGraphicsSceneHoverEvent>
26
#include <QGraphicsSceneMouseEvent>
27
#include <QKeyEvent>
28
#include <QPainter>
29
#include <QPointer>
30

31
#include <wobjectimpl.h>
32
W_OBJECT_IMPL(Dataflow::CableItem)
1,321 !
33
namespace Dataflow
34
{
35
bool CableItem::g_cables_enabled = true;
36

37
static bool canCreateCable(const Process::Cable& c, Process::DataflowManager& plug)
1,321 ✔
38
{
39
  auto it = plug.cables().find(&c);
1,321 ✔
40
  return it == plug.cables().end() || it->second == nullptr;
1,321 ✔
41
}
42
CableItem::CableItem(
1,321 ✔
43
    const Process::Cable& c, const Process::Context& ctx, QGraphicsItem* parent)
44
    : QGraphicsItem{parent}
1,321 !
45
    , m_cable{c}
1,321 ✔
46
    , m_context{ctx}
1,321 ✔
47
{
1,321 ✔
48
  auto& plug = ctx.dataflow;
1,321 ✔
49
  this->setCursor(score::Skin::instance().cursor(Qt::CrossCursor));
1,321 !
50
  setAcceptHoverEvents(true);
1,321 !
51
  this->setFlag(QGraphicsItem::ItemClipsToShape);
1,321 !
52
  this->setFlag(QGraphicsItem::ItemIsFocusable);
1,321 !
53
  this->setAcceptDrops(true);
1,321 !
54
  this->setToolTip(tr("Cable\n"));
1,321 !
55

56
  SCORE_ASSERT(canCreateCable(c, plug));
1,321 !
57

58
  con(c.selection, &Selectable::changed, this, [this](bool b) {
1,345 !
59
    if(m_p1 && m_p2)
24 ✔
60
    {
61
      if(b)
19 ✔
62
      {
63
        setZValue(selectedZ);
12 ✔
64
        m_p1->setHighlight(true);
12 ✔
65
        m_p2->setHighlight(true);
12 ✔
66
        this->setFocus(Qt::OtherFocusReason);
12 ✔
67
      }
12 ✔
68
      else
69
      {
70
        updateHighlight();
7 ✔
71
        m_p1->setHighlight(false);
7 ✔
72
        m_p2->setHighlight(false);
7 ✔
73
        this->clearFocus();
7 ✔
74
      }
75
      update();
19 ✔
76
    }
19 ✔
77
  });
24 ✔
78

79
  auto& p = plug.ports();
1,321 ✔
80
  if(auto src_port = c.source().try_find(ctx))
1,321 !
81
  {
82
    auto src = p.find(src_port);
1,321 !
83
    if(src != p.end())
1,321 ✔
84
    {
85
      m_p1 = src->second;
1,223 !
86
      m_p1->cables.push_back(this);
1,223 !
87
    }
1,223 ✔
88
  }
1,321 ✔
89

90
  if(auto snk_port = c.sink().try_find(ctx))
1,321 !
91
  {
92
    auto snk = p.find(snk_port);
1,321 !
93
    if(snk != p.end())
1,321 ✔
94
    {
95
      m_p2 = snk->second;
1,206 !
96
      m_p2->cables.push_back(this);
1,206 !
97
    }
1,206 ✔
98
  }
1,321 ✔
99
  check();
1,321 !
100
  resize();
1,321 !
101
}
1,321 ✔
102

103
CableItem::~CableItem()
1,348 ✔
104
{
27 ✔
105
  if(m_p1)
1,321 ✔
106
  {
107
    ossia::remove_erase(m_p1->cables, this);
1,220 !
108
  }
1,220 ✔
109
  if(m_p2)
1,321 ✔
110
  {
111
    ossia::remove_erase(m_p2->cables, this);
1,224 !
112
  }
1,224 ✔
113
  auto& plug = m_context.dataflow;
1,321 ✔
114
  auto& p = plug.cables();
1,321 ✔
115
  auto it = p.find(&m_cable);
1,321 !
116
  if(it != p.end())
1,321 !
117
    it->second = nullptr;
1,321 ✔
118
}
1,348 ✔
119

120
static const QPainterPathStroker& cableStroker()
292 ✔
121
{
122
  static const QPainterPathStroker cable_stroker{[] {
295 !
123
    QPen pen;
3 ✔
124
    pen.setCapStyle(Qt::PenCapStyle::RoundCap);
3 !
125
    pen.setJoinStyle(Qt::PenJoinStyle::RoundJoin);
3 !
126
    pen.setWidthF(14.);
3 !
127
    return pen;
3 ✔
128
  }()};
3 !
129
  return cable_stroker;
292 ✔
UNCOV
130
}
×
131

132
void CableItem::updateStroke() const
1,744 ✔
133
{
134
  if(!m_stroke.isEmpty())
1,744 ✔
135
    return;
1,452 ✔
136
  m_stroke = cableStroker().createStroke(m_path);
292 ✔
137
}
1,744 ✔
138

139
QRectF CableItem::boundingRect() const
1,242 ✔
140
{
141
  updateStroke();
1,242 ✔
142
  return m_stroke.boundingRect();
1,242 ✔
143
}
144

145
bool CableItem::contains(const QPointF& point) const
141 ✔
146
{
147
  if(m_mode == None)
141 !
UNCOV
148
    return false;
×
149
  updateStroke();
141 ✔
150
  return m_stroke.contains(point);
141 ✔
151
}
141 ✔
152

153
void CableItem::setPen(QPainter& painter, const Process::Style& style)
357 ✔
154
{
155
  auto& brush = [&]() -> score::BrushSet& {
714 ✔
156
    if(!m_cable.selection.get() && !m_highlight)
357 ✔
157
    {
158
      [[likely]];
159
      switch(m_type)
294 !
160
      {
161
        case Process::PortType::Message:
162
          return style.skin.Cable2.main;
294 ✔
163
        case Process::PortType::Audio:
164
          return style.skin.Cable1.main;
×
165
        case Process::PortType::Midi:
166
          return style.skin.Cable3.main;
×
167
        case Process::PortType::Texture:
168
          return style.skin.Cable4.main;
×
169
        case Process::PortType::Geometry:
UNCOV
170
          return style.skin.Cable5.main;
×
171
          break;
172
      }
UNCOV
173
    }
×
174
    else
175
    {
176
      switch(m_type)
63 !
177
      {
178
        case Process::PortType::Message:
UNCOV
179
          return style.skin.SelectedCable2.lighter;
×
180
        case Process::PortType::Audio:
181
          return style.skin.SelectedCable1.lighter;
63 ✔
182
        case Process::PortType::Midi:
183
          return style.skin.SelectedCable3.lighter;
×
184
        case Process::PortType::Texture:
185
          return style.skin.SelectedCable4.lighter;
×
186
        case Process::PortType::Geometry:
UNCOV
187
          return style.skin.SelectedCable5.lighter;
×
188
          break;
189
      }
190
    }
191
  }();
357 ✔
192

193
  switch(m_mode)
357 !
194
  {
195
    case Full: {
196
      if(m_dropping)
294 !
197
      {
198
        [[unlikely]];
UNCOV
199
        painter.setPen(style.skin.Base4.main.pen3_solid_round_round);
×
UNCOV
200
      }
×
201
      else
202
      {
203
        switch(this->m_cable.type())
294 !
204
        {
205
          case Process::CableType::ImmediateGlutton:
206
          case Process::CableType::ImmediateStrict:
207
            painter.setPen(brush.pen3_solid_round_round);
294 ✔
208
            break;
294 ✔
209
          case Process::CableType::DelayedGlutton:
210
          case Process::CableType::DelayedStrict:
UNCOV
211
            painter.setPen(brush.pen3_dashed_flat_miter);
×
UNCOV
212
            break;
×
213
        }
214
      }
215
      break;
294 ✔
216
    }
217
    case Partial_P1:
218
    case Partial_P2: {
219
      painter.setPen(brush.pen1_dotted);
63 ✔
220
      break;
63 ✔
221
    }
222
    default:
UNCOV
223
      break;
×
224
  }
225
}
357 ✔
226

227
void CableItem::paint(
407 ✔
228
    QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
229
{
230
  if(m_p1 && m_p2 && m_mode != CableDisplayMode::None)
407 !
231
  {
232
    auto& style = Process::Style::instance();
357 ✔
233
    painter->setRenderHint(QPainter::Antialiasing, true);
357 ✔
234
    painter->setBrush(style.TransparentBrush());
357 ✔
235
    setPen(*painter, style);
357 ✔
236
    painter->drawPath(m_path);
357 ✔
237
    painter->setRenderHint(QPainter::Antialiasing, false);
357 ✔
238
  }
357 ✔
239
}
407 ✔
240

241
void CableItem::resize()
4,616 ✔
242
{
243
  prepareGeometryChange();
4,616 ✔
244

245
  m_stroke.clear();
4,616 ✔
246
  m_path.clear();
4,616 ✔
247
  if(m_p1 && m_p2)
4,616 ✔
248
  {
249
    auto p1 = m_p1->sceneCenter();
4,475 ✔
250
    auto p2 = m_p2->sceneCenter();
4,475 ✔
251

252
    this->setPos(QRectF{p1, p2}.normalized().topLeft());
4,475 ✔
253

254
    p1 = mapFromScene(p1);
4,475 ✔
255
    p2 = mapFromScene(p2);
4,475 ✔
256
    bool x_dir = p1.x() > p2.x();
4,475 ✔
257

258
    if(m_mode == Full)
4,475 ✔
259
    {
260
      auto first = x_dir ? p1 : p2;
4,367 ✔
261
      auto last = !x_dir ? p1 : p2;
4,367 ✔
262

263
      int half_length = std::floor(0.5 * (last.x() - first.x()));
4,367 ✔
264

265
      auto y_direction = last.y() > first.y() ? 1 : -1;
4,367 ✔
266
      auto offset_y = y_direction * half_length / 10.f;
4,367 ✔
267

268
      m_path.moveTo(first.x(), first.y());
4,367 ✔
269
      m_path.cubicTo(
8,734 ✔
270
          first.x() + half_length, first.y() + offset_y, last.x() - half_length,
4,367 ✔
271
          last.y() - offset_y, last.x(), last.y());
4,367 ✔
272
    }
4,367 ✔
273
    else if(m_mode == Partial_P1)
108 ✔
274
    {
275
      auto dir = (p2 - p1) / QLineF(p1, p2).length();
36 ✔
276
      m_path.moveTo(p1.x(), p1.y());
36 ✔
277
      m_path.lineTo(p1 + 50. * dir);
36 ✔
278
    }
36 ✔
279
    else if(m_mode == Partial_P2)
72 ✔
280
    {
281
      auto dir = (p1 - p2) / QLineF(p1, p2).length();
64 ✔
282
      m_path.moveTo(p2.x(), p2.y());
64 ✔
283
      m_path.lineTo(p2 + 50. * dir);
64 ✔
284
    }
64 ✔
285
  }
4,475 ✔
286

287
  update();
4,616 ✔
288
}
4,616 ✔
289

290
static bool isPortActuallyVisible(QGraphicsItem* port)
412 ✔
291
{
292
  if(QGraphicsItem* parent = port->parentItem())
412 ✔
293
  {
294
    do
406 ✔
295
    {
296
      const auto parentRect = parent->boundingRect();
2,501 ✔
297

298
      // Case of the empty rect
299
      if(parentRect.width() == 0.0 && parentRect.height() == 0.0)
2,501 ✔
300
        continue;
366 ✔
301

302
      const auto point = port->mapToItem(parent, QPointF{5., 5.});
2,135 ✔
303
      if(!parentRect.contains(point))
2,135 ✔
304
      {
305
        return false;
246 ✔
306
      }
307

308
    } while((parent = parent->parentItem()));
2,255 ✔
309
  }
160 ✔
310
  return true;
166 ✔
311
}
412 ✔
312

313
static CableDisplayMode cableMustBeShown(CableItem& self, PortItem* p1, PortItem* p2)
3,753 ✔
314
{
315
  if(!p1 || !p2)
3,753 ✔
316
    return None;
395 ✔
317

318
  {
319
    const bool p1_vis = p1->isVisible();
3,358 ✔
320
    const bool p2_vis = p2->isVisible();
3,358 ✔
321
    if(p1_vis && !p2_vis)
3,358 !
UNCOV
322
      return Partial_P1;
×
323
    else if(!p1_vis && p2_vis)
3,358 !
324
      return Partial_P2;
28 ✔
325
    else if(!p1_vis && !p2_vis)
3,330 !
UNCOV
326
      return None;
×
327
  }
328

329
  auto proc_p1 = Process::parentProcess(&p1->port());
3,330 ✔
330
  auto proc_p2 = Process::parentProcess(&p2->port());
3,330 ✔
331

332
  if(proc_p1 && proc_p2 && proc_p1->parent() == proc_p2->parent())
3,330 !
333
  {
334
    if(self.parentItem()
3,189 ✔
335
       && self.parentItem()->type() == 65554) // We're in full nodal view
3,189 !
UNCOV
336
      return Full;
×
337

338
    // Ideal heuritstic: find the closest {interval, nodalcontainer} item for p1 and p2.
339
    // But too slow so we approximate - there is a potential issue if both are in different
340
    // intervals themselves in a scenario, itself in a single nodal view
341
    auto ancestor = p1->commonAncestorItem(p2);
3,189 !
342
    if(ancestor
3,189 ✔
343
       && ancestor->type()
3,189 ✔
344
              == (QGraphicsItem::UserType + 5555)) // we're in the same NodalContainer
3,175 ✔
345
      return Full;
3,124 ✔
346
  }
65 ✔
347

348
  {
349
    const bool p1_vis = isPortActuallyVisible(p1);
206 !
350
    const bool p2_vis = isPortActuallyVisible(p2);
206 !
351
    if(p1_vis && p2_vis)
206 ✔
352
      return Full;
54 ✔
353
    else if(p1_vis && !p2_vis)
152 !
354
      return Partial_P1;
32 ✔
355
    else if(!p1_vis && p2_vis)
120 !
356
      return Partial_P2;
26 ✔
357
    else
358
      return None;
94 ✔
359
  }
360
}
3,753 ✔
361

362
static const Process::NodeItem* nodeOf(const QGraphicsItem* item) noexcept
12,606 ✔
363
{
364
  for(; item; item = item->parentItem())
48,224 !
365
    if(item->type() == Process::NodeItem::Type)
48,035 !
366
      return static_cast<const Process::NodeItem*>(item);
12,417 !
367
  return nullptr;
189 ✔
368
}
12,606 ✔
369

370
bool CableItem::linksSelectedNode() const noexcept
3,315 ✔
371
{
372
  for(const PortItem* p : {m_p1.data(), m_p2.data()})
9,574 ✔
373
    if(auto* node = nodeOf(p); node && node->isNodeSelected())
6,518 !
374
      return true;
259 ✔
375
  return false;
3,056 ✔
376
}
3,315 ✔
377

378
void CableItem::updateHighlight()
3,309 ✔
379
{
380
  const bool h = linksSelectedNode();
3,309 ✔
381
  if(h != m_highlight)
3,309 ✔
382
  {
383
    m_highlight = h;
73 ✔
384
    update();
73 ✔
385
  }
73 ✔
386
  const bool raised = h || m_cable.selection.get()
6,354 ✔
387
                     || (m_p1 && m_p1->port().selection.get())
3,052 !
388
                     || (m_p2 && m_p2->port().selection.get());
3,045 !
389
  setZValue(raised ? selectedZ : restingZ());
3,309 ✔
390
}
3,309 ✔
391

392
qreal CableItem::restingZ() const noexcept
3,044 ✔
393
{
394
  // In a nodal view a cable goes over the nodes it links, which would
395
  // otherwise hide where it goes; in the timeline it stays under the boxes.
396
  if(m_p1 && m_p2)
3,044 !
397
    if(auto* n1 = nodeOf(m_p1), *n2 = nodeOf(m_p2);
5,995 !
398
       n1 && n2 && n1->parentItem() == n2->parentItem())
3,044 !
399
      return nodalZ;
2,904 ✔
400
  return -1.;
140 ✔
401
}
3,044 ✔
402

403
void CableItem::check()
3,753 ✔
404
{
405
  if(g_cables_enabled)
3,753 !
406
  {
407
    m_mode = cableMustBeShown(*this, m_p1, m_p2);
3,753 ✔
408
    if(m_mode != CableDisplayMode::None)
3,753 ✔
409
    {
410
      if(!isEnabled())
3,264 !
411
      {
412
        setVisible(true);
×
UNCOV
413
        setEnabled(true);
×
UNCOV
414
      }
×
415
      else if(!isVisible())
3,264 !
416
      {
UNCOV
417
        setVisible(true);
×
UNCOV
418
      }
×
419
      m_type = m_p1->port().type();
3,264 ✔
420
      if(auto c_o = m_p1->commonAncestorItem(m_p2))
3,264 !
421
        setParentItem(c_o);
3,256 ✔
422
      updateHighlight();
3,264 ✔
423
      resize();
3,264 ✔
424
    }
3,264 ✔
425
  }
3,753 ✔
426
  else if(isEnabled())
×
427
  {
428
    setVisible(false);
×
429
    setEnabled(false);
×
UNCOV
430
    update();
×
UNCOV
431
  }
×
432
}
3,753 ✔
433

434
PortItem* CableItem::source() const noexcept
343 ✔
435
{
436
  return m_p1;
343 ✔
437
}
438

439
PortItem* CableItem::target() const noexcept
343 ✔
440
{
441
  return m_p2;
343 ✔
442
}
443

444
void CableItem::setSource(PortItem* p)
123 ✔
445
{
446
  m_p1 = p;
123 ✔
447
  check();
123 ✔
448
}
123 ✔
449

450
void CableItem::setTarget(PortItem* p)
86 ✔
451
{
452
  m_p2 = p;
86 ✔
453
  check();
86 ✔
454
}
86 ✔
455

456
QPainterPath CableItem::shape() const
411 ✔
457
{
458
  if(m_mode == None)
411 ✔
459
    return {};
50 ✔
460
  updateStroke();
361 ✔
461
  return m_stroke;
361 ✔
462
}
411 ✔
463

464
QPainterPath CableItem::opaqueArea() const
×
465
{
466
  if(m_mode == None)
×
467
    return {};
×
468
  updateStroke();
×
UNCOV
469
  return m_stroke;
×
UNCOV
470
}
×
471

472
namespace
473
{
474
CableItem::GrabbedEnd grabbedCableEnd{};
475
bool cableSelectOnRelease{};
476
bool cableSelectCumulation{};
477
}
478

479
double CableItem::grabZoneRadius(QPointF p1, QPointF p2) noexcept
34 ✔
480
{
481
  // Never more than a third of the cable from each end, or the two zones would
482
  // meet and the cable could only ever be re-plugged, never selected -- which is
483
  // what happens to a short one, and to every cable once the view is zoomed out,
484
  // since these are scene units and the nodal canvas scales them.
485
  const double len = QLineF{p1, p2}.length();
34 !
486
  return std::min(std::max(28., 0.15 * len), 0.35 * len);
34 !
487
}
488

489
CableItem::GrabbedEnd
490
CableItem::endNear(QPointF scenePos, QPointF p1, QPointF p2) noexcept
20 ✔
491
{
492
  const double threshold = grabZoneRadius(p1, p2);
20 ✔
493
  if(QLineF{p2, scenePos}.length() <= threshold)
20 !
494
    return GrabbedEnd::Sink;
3 ✔
495
  if(QLineF{p1, scenePos}.length() <= threshold)
17 !
496
    return GrabbedEnd::Source;
3 ✔
497
  return GrabbedEnd::None;
14 ✔
498
}
20 ✔
499

500
void CableItem::hoverMoveEvent(QGraphicsSceneHoverEvent* event)
×
501
{
502
  const bool onEnd
×
503
      = m_p1 && m_p2
×
504
        && endNear(event->scenePos(), m_p1->sceneCenter(), m_p2->sceneCenter())
×
505
               != GrabbedEnd::None;
×
506
  auto& skin = score::Skin::instance();
×
507
  setCursor(onEnd ? skin.CursorPointingHand : skin.cursor(Qt::CrossCursor));
×
UNCOV
508
  probe(event->scenePos());
×
509
  event->accept();
×
UNCOV
510
}
×
511

512
void CableItem::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
×
513
{
UNCOV
514
  probe(event->scenePos());
×
515
  event->accept();
×
UNCOV
516
}
×
517

UNCOV
518
void CableItem::probe(QPointF scenePos)
×
519
{
520
  // Near its end, a cable shows what the process there receives, all its
521
  // cables merged; elsewhere, what its source produces
522
  auto* s = scene();
×
523
  if(!s || !m_p1 || !m_p2)
×
524
    return;
×
525
  const bool sink
×
526
      = endNear(scenePos, m_p1->sceneCenter(), m_p2->sceneCenter()) == GrabbedEnd::Sink;
×
UNCOV
527
  const Process::Port& port = sink ? m_p2->port() : m_p1->port();
×
528
  Process::PortProbeHover::instance().enter(port, m_context, *s, scenePos);
×
UNCOV
529
}
×
530

531
void CableItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
×
532
{
533
  setCursor(score::Skin::instance().cursor(Qt::CrossCursor));
×
UNCOV
534
  Process::PortProbeHover::instance().leave();
×
535
  event->accept();
×
UNCOV
536
}
×
537

538
void CableItem::mousePressEvent(QGraphicsSceneMouseEvent* event)
×
539
{
UNCOV
540
  grabbedCableEnd = CableItem::GrabbedEnd::None;
×
541
  cableSelectOnRelease = false;
×
542
  if(!m_p1 || !m_p2)
×
543
  {
UNCOV
544
    event->ignore();
×
UNCOV
545
    return;
×
546
  }
547

548
  // Only the left button re-plugs: mouseMoveEvent measures against
549
  // buttonDownScreenPos(LeftButton), which is a null point for any other
550
  // button and would read as a drag that has already started.
551
  if(event->button() != Qt::LeftButton)
×
552
  {
UNCOV
553
    event->ignore();
×
554
    return;
×
555
  }
556

557
  score::SelectionDispatcher disp{m_context.selectionStack};
×
558
  if(m_p1->contains(m_p1->mapFromScene(event->scenePos())))
×
559
  {
UNCOV
560
    disp.select(m_p1->port());
×
UNCOV
561
    event->ignore();
×
562
    return;
×
563
  }
564

565
  if(m_p2->contains(m_p2->mapFromScene(event->scenePos())))
×
566
  {
UNCOV
567
    disp.select(m_p2->port());
×
UNCOV
568
    event->ignore();
×
UNCOV
569
    return;
×
570
  }
571

572
  grabbedCableEnd
UNCOV
573
      = endNear(event->scenePos(), m_p1->sceneCenter(), m_p2->sceneCenter());
×
574

575
  // Dragging an end carries the whole selection along, so a press on a cable
576
  // that is already selected must not reduce the selection to it before the
577
  // drag had a chance to start; that is settled on release instead.
UNCOV
578
  const bool cumulation = event->modifiers() & Qt::ControlModifier;
×
579
  const Selection current = m_context.selectionStack.currentSelection();
×
580
  if(current.contains(&m_cable))
×
581
  {
UNCOV
582
    cableSelectOnRelease = true;
×
UNCOV
583
    cableSelectCumulation = cumulation;
×
584
  }
×
585
  else
586
  {
587
    cableSelectOnRelease = false;
×
588
    Selection sel;
×
589
    if(cumulation)
×
590
      sel = current;
×
591
    sel.append(&m_cable);
×
592
    disp.select(sel);
×
UNCOV
593
  }
×
594
  event->accept();
×
UNCOV
595
}
×
596

597
void CableItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
×
598
{
UNCOV
599
  event->accept();
×
600
  if(grabbedCableEnd == CableItem::GrabbedEnd::None)
×
601
    return;
×
602

603
  const auto dragged
×
604
      = (event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton))
×
UNCOV
605
            .manhattanLength();
×
UNCOV
606
  if(dragged <= QApplication::startDragDistance())
×
UNCOV
607
    return;
×
608

609
  // The end that stays put anchors the drag: the magnetic search then only
610
  // considers ports the moving end can legally go to.
611
  PortItem* anchor = grabbedCableEnd == CableItem::GrabbedEnd::Sink ? m_p1.data() : m_p2.data();
×
612
  grabbedCableEnd = CableItem::GrabbedEnd::None;
×
UNCOV
613
  cableSelectOnRelease = false;
×
614
  if(!anchor)
×
615
    return;
×
616

617
  auto& plug = m_context.dataflow;
×
618
  std::vector<Process::Cable*> cables;
×
619
  std::vector<QPointer<CableItem>> items;
×
620
  auto add = [&](Process::Cable* c) {
×
621
    if(!c || ossia::contains(cables, c))
×
UNCOV
622
      return;
×
623
    cables.push_back(c);
×
624
    if(auto it = plug.cables().find(c); it != plug.cables().end() && it->second)
×
625
    {
626
      it->second->m_dropping = true;
×
627
      it->second->update();
×
UNCOV
628
      items.push_back(it->second);
×
629
    }
×
630
  };
×
631

UNCOV
632
  add(const_cast<Process::Cable*>(&m_cable));
×
633
  for(auto& obj : m_context.selectionStack.currentSelection())
×
UNCOV
634
    add(qobject_cast<Process::Cable*>(obj.data()));
×
635

636
  Dataflow::beginPortDrag(*anchor, event->scenePos(), std::move(cables));
×
637

638
  // Past this point the drop may have deleted this item and any of those.
639
  for(auto& item : items)
×
UNCOV
640
    if(item)
×
641
      item->resetDrop();
×
UNCOV
642
}
×
643

644
void CableItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
×
645
{
646
  grabbedCableEnd = CableItem::GrabbedEnd::None;
×
647
  if(cableSelectOnRelease)
×
648
  {
649
    cableSelectOnRelease = false;
×
650
    Selection sel = filterSelections(
×
651
        &m_cable, m_context.selectionStack.currentSelection(), cableSelectCumulation);
×
652
    score::SelectionDispatcher{m_context.selectionStack}.select(sel);
×
UNCOV
653
  }
×
654
  event->accept();
×
UNCOV
655
}
×
656

UNCOV
657
void CableItem::keyPressEvent(QKeyEvent* event)
×
658
{
UNCOV
659
  switch(event->key())
×
660
  {
661
    case Qt::Key_Left:
662
    case Qt::Key_Up: {
UNCOV
663
      auto& source = this->m_cable.source().find(this->m_context);
×
UNCOV
664
      this->m_context.selectionStack.pushNewSelection({&source});
×
UNCOV
665
      break;
×
666
    }
667
    case Qt::Key_Right:
668
    case Qt::Key_Down: {
UNCOV
669
      auto& sink = this->m_cable.sink().find(this->m_context);
×
UNCOV
670
      this->m_context.selectionStack.pushNewSelection({&sink});
×
671
      break;
×
672
    }
673
  }
674
  event->accept();
×
UNCOV
675
}
×
676

677
void CableItem::keyReleaseEvent(QKeyEvent* event)
×
678
{
UNCOV
679
  event->accept();
×
UNCOV
680
}
×
681

682
void CableItem::dragEnterEvent(QGraphicsSceneDragDropEvent* event)
1 ✔
683
{
684
  m_dropping = true;
1 ✔
685
  event->accept();
1 ✔
686
  update();
1 ✔
687
}
1 ✔
688

689
void CableItem::dragLeaveEvent(QGraphicsSceneDragDropEvent* event)
×
690
{
691
  m_dropping = false;
×
UNCOV
692
  event->accept();
×
693
  update();
×
UNCOV
694
}
×
695

696
void CableItem::dropEvent(QGraphicsSceneDragDropEvent* event)
×
697
{
698
  m_dropping = false;
×
699
  dropReceived(event->pos(), *event->mimeData());
×
UNCOV
700
  event->accept();
×
UNCOV
701
  update();
×
UNCOV
702
}
×
703
}
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