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

ossia / score / 40987115292

30 Oct 2026 01:27AM UTC coverage: 51.229% (+2.1%) from 49.178%
40987115292

push

github

jcelerier
avendish: main

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

179452 of 350293 relevant lines covered (51.23%)

175809.48 hits per line

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

75.47
/src/plugins/score-lib-process/Process/Dataflow/NodeItem.cpp
1
#include <Process/Commands/Properties.hpp>
2
#include <Process/Dataflow/CableItem.hpp>
3
#include <Process/Dataflow/NodeItem.hpp>
4
#include <Process/Dataflow/PortFactory.hpp>
5
#include <Process/Dataflow/PortItem.hpp>
6
#include <Process/Dataflow/PortVisibility.hpp>
7
#include <Process/DocumentPlugin.hpp>
8
#include <Process/Focus/FocusDispatcher.hpp>
9
#include <Process/Process.hpp>
10
#include <Process/ProcessFactory.hpp>
11
#include <Process/ProcessList.hpp>
12
#include <Process/Style/Pixmaps.hpp>
13
#include <Process/Style/ScenarioStyle.hpp>
14

15
#include <Control/DefaultEffectItem.hpp>
16
#include <Effect/EffectLayer.hpp>
17
#include <Effect/EffectPainting.hpp>
18

19
#include <Process/ApplicationPlugin.hpp>
20
#include <score/application/GUIApplicationContext.hpp>
21
#include <score/command/Dispatchers/CommandDispatcher.hpp>
22
#include <score/command/Dispatchers/RuntimeDispatcher.hpp>
23
#include <score/document/DocumentContext.hpp>
24
#include <score/graphics/GraphicWidgets.hpp>
25
#include <score/graphics/GraphicsLayout.hpp>
26
#include <score/graphics/TextItem.hpp>
27
#include <score/model/Skin.hpp>
28
#include <score/selection/Selection.hpp>
29
#include <score/selection/SelectionDispatcher.hpp>
30
#include <score/selection/SelectionStack.hpp>
31
#include <score/tools/Bind.hpp>
32

33
#include <ossia/detail/algorithms.hpp>
34
#include <ossia/detail/ssize.hpp>
35

36
#include <ossia-qt/invoke.hpp>
37

38
#include <QCursor>
39
#include <QGraphicsScene>
40
#include <QGraphicsSceneMouseEvent>
41
#include <QKeyEvent>
42
#include <QMenu>
43
#include <QPainter>
44
#include <QTimer>
45

46
#include <wobjectimpl.h>
47
W_OBJECT_IMPL(Process::NodeItem)
2,802 ✔
48
namespace Process
49
{
50

51
static const constexpr qreal TitleHeight = 20.;
52
//static const constexpr qreal TitleX0 = 15;
53
static const constexpr qreal TitleY0 = -TitleHeight + 2.;
54
static const constexpr qreal FoldX0 = 2;
55
static const constexpr qreal FoldY0 = TitleY0 + 1;
56
static const constexpr qreal UiX0 = 16;
57
static const constexpr qreal UiY0 = TitleY0 + 1.;
58
static const constexpr qreal TitleWithUiX0 = 27;
59
static const constexpr qreal SpacingIcon = 3;
60

61
static const constexpr qreal FooterHeight = 0.;
62
static const constexpr qreal Corner = 2.;
63
static const constexpr qreal PortSpacing = 10.;
64
static const constexpr qreal InletX0 = -10.;
65
static const constexpr qreal InletY0 = 0;
66
static const constexpr qreal OutletX0 = -2.;
67
static const constexpr qreal OutletY0 = InletY0; // Add to height
68
static const constexpr qreal TopButtonX0 = -12.;
69
static const constexpr qreal TopButtonY0 = TitleY0 + 2.;
70
static const constexpr qreal LeftSideWidth = 10.;
71
static const constexpr qreal RightSideWidth = LeftSideWidth;
72

73
NodeItem::NodeItem(
1,641 ✔
74
    const Process::ProcessModel& process, const Process::Context& ctx, TimeVal parentDur,
75
    QGraphicsItem* parent)
76
    : QGraphicsItem{parent}
1,641 ✔
77
    , m_model{process}
78
    , m_context{ctx}
79
    , m_dispatcher{ctx.commandStack}
80
    , m_parentDuration{parentDur}
81
{
1,641 ✔
82
  setObjectName("NodeItem");
1,641 ✔
83
  setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton);
1,641 ✔
84
  setAcceptHoverEvents(true);
1,641 ✔
85
  setAcceptDrops(true);
1,641 ✔
86
  setFlag(ItemIsFocusable, true);
1,641 ✔
87
  setFlag(ItemClipsChildrenToShape, true);
1,641 ✔
88
  const auto& pf
1,641 ✔
89
      = ctx.app.interfaces<Process::ProcessFactoryList>().get(process.concreteKey());
1,641 ✔
90
  setData(0xF1, pf->descriptor(process).documentationLink);
1,641 ✔
91

92
  if(process.flags() & Process::ProcessFlags::FullyCustomItem)
1,641 ✔
93
  {
94
    createWithoutDecorations();
1 ✔
95
  }
1 ✔
96
  else
97
  {
98
    createWithDecorations();
1,640 ✔
99
  }
100

101
  initConnections();
1,641 ✔
102
}
×
103

104
void NodeItem::createWithDecorations()
1,647 ✔
105
{
106
  auto& process = m_model;
1,647 ✔
107
  auto& ctx = m_context;
1,647 ✔
108

109
  m_folded = process.folded();
1,647 ✔
110

111
  // Title
112
  const auto& pixmaps = Process::Pixmaps::instance();
1,647 ✔
113
  m_fold
3,294 ✔
114
      = new score::QGraphicsPixmapToggle{pixmaps.unroll_small, pixmaps.roll_small, this};
1,647 ✔
115
  m_fold->setState(!m_folded);
1,647 ✔
116

117
  m_scriptButton = Process::makeScriptButton(
1,647 ✔
118
      const_cast<Process::ProcessModel&>(process), ctx, this, this);
1,647 ✔
119
  m_uiButton = Process::makeExternalUIButton(
1,647 ✔
120
      const_cast<Process::ProcessModel&>(process), ctx, this, this);
1,647 ✔
121
  m_presetButton = Process::makePresetButton(process, ctx, this, this);
1,647 ✔
122

123
  auto& skin = score::Skin::instance();
1,647 ✔
124
  m_label = new score::SimpleTextItem{skin.Light.main, this};
1,647 ✔
125
  m_label->setFont(skin.Bold10Pt);
1,647 ✔
126

127
  updateLabel();
1,647 ✔
128

129
  con(process.metadata(), &score::ModelMetadata::NameChanged, this,
3,294 ✔
130
      &NodeItem::updateLabel);
1,647 ✔
131
  con(process.metadata(), &score::ModelMetadata::LabelChanged, this,
3,294 ✔
132
      &NodeItem::updateLabel);
1,647 ✔
133

134
  con(process, &Process::ProcessModel::loopsChanged, this, [&] { updateZoomRatio(); });
1,648 ✔
135
  con(process, &Process::ProcessModel::loopDurationChanged, this,
3,294 ✔
136
      [&] { updateZoomRatio(); });
1,648 ✔
137
  con(process, &Process::ProcessModel::startOffsetChanged, this,
3,294 ✔
138
      [&] { updateZoomRatio(); });
1,647 ✔
139

140
  // Selection
141
  con(process.selection, &Selectable::changed, this, &NodeItem::setSelected);
1,647 ✔
142
  m_selected = process.selection.get();
1,647 ✔
143

144
  if(!m_folded)
1,647 ✔
145
    createContentItem();
1,534 ✔
146
  else
147
    createFoldedItem();
113 ✔
148

149
  // This is because if it's a DefaultEffectItem the ports are created asynchronously
150
  // Thus they are added to the vertical lists instead of the actual items
151
  ossia::qt::run_async(this, [this] {
2,877 ✔
152
    resetInlets();
1,230 ✔
153
    resetOutlets();
1,230 ✔
154

155
    resizeAsync();
1,230 ✔
156
  });
1,230 ✔
157
  connect(&process, &Process::ProcessModel::controlAdded, this, &NodeItem::resetInlets);
1,647 ✔
158
  connect(
1,647 ✔
159
      &process, &Process::ProcessModel::controlRemoved, this, &NodeItem::resetInlets);
1,647 ✔
160
  connect(
1,647 ✔
161
      &process, &Process::ProcessModel::controlOutletAdded, this,
1,647 ✔
162
      &NodeItem::resetOutlets);
163
  connect(
1,647 ✔
164
      &process, &Process::ProcessModel::controlOutletRemoved, this,
1,647 ✔
165
      &NodeItem::resetOutlets);
166
  connect(&process, &Process::ProcessModel::inletsChanged, this, &NodeItem::resetInlets);
1,647 ✔
167
  connect(
1,647 ✔
168
      &process, &Process::ProcessModel::outletsChanged, this, &NodeItem::resetOutlets);
1,647 ✔
169

170
  // The button only states the intent; the model is what decides, so that undo,
171
  // reload and a preset dropped on the node all end up drawing the same thing.
172
  connect(m_fold, &score::QGraphicsPixmapToggle::toggled, this, [this](bool b) {
1,647 ✔
173
    CommandDispatcher<> disp{m_context.commandStack};
×
174
    disp.submit<Process::SetNodeFoldMode>(
×
175
        m_model, b ? Process::FoldMode::Unfolded : Process::FoldMode::Folded);
×
176
  });
×
177

178
  con(process, &Process::ProcessModel::foldModeChanged, this,
3,294 ✔
179
      [this] { applyFold(m_model.folded()); });
1,649 ✔
180

181
  resizeAsync();
1,647 ✔
182
  updateTooltip();
1,647 ✔
183
}
1,647 ✔
184

185
void NodeItem::createWithoutDecorations()
1 ✔
186
{
187
  auto& process = m_model;
1 ✔
188

189
  con(process.selection, &Selectable::changed, this, &NodeItem::setSelected);
1 ✔
190
  m_selected = process.selection.get();
1 ✔
191

192
  createContentItem();
1 ✔
193

194
  updateTooltip();
1 ✔
195
}
1 ✔
196

197
void NodeItem::updateTooltip()
1,648 ✔
198
{
199
  if(!m_fx || m_fx->toolTip().isEmpty())
1,648 ✔
200
  {
201
    auto& p = this->m_context.app.interfaces<Process::ProcessFactoryList>();
1,602 ✔
202
    const auto& desc = p.get(m_model.concreteKey())->descriptor(m_model);
1,602 ✔
203

204
    bool has_name = !desc.prettyName.isEmpty();
1,602 ✔
205
    bool has_desc = !desc.description.isEmpty();
1,602 ✔
206
    bool has_link = !desc.documentationLink.isEmpty();
1,602 ✔
207
    QString str;
1,602 ✔
208
    if(has_name)
1,602 ✔
209
    {
210
      str += desc.prettyName;
1,602 ✔
211
      str += "\n";
1,602 ✔
212
    }
1,602 ✔
213
    if(has_desc)
1,602 ✔
214
    {
215
      str += desc.description;
1,602 ✔
216
      str += "\n";
1,602 ✔
217
    }
1,602 ✔
218
    if(has_link)
1,602 ✔
219
    {
220
      str += QStringLiteral("Press F1 to open the docs:\n%1")
3,108 ✔
221
                 .arg(desc.documentationLink.toString());
1,554 ✔
222
    }
1,554 ✔
223
    else
224
    {
225
      str += QStringLiteral("Press F1 to open the docs!");
48 ✔
226
    }
227

228
    this->setToolTip(str);
1,602 ✔
229
  }
1,602 ✔
230
  else if(m_fx)
46 ✔
231
  {
232
    this->setToolTip(m_fx->toolTip());
46 ✔
233
  }
46 ✔
234
}
1,648 ✔
235

236
void NodeItem::resetItem()
8 ✔
237
{
238
  qDeleteAll(m_inlets);
8 ✔
239
  m_inlets.clear();
8 ✔
240

241
  qDeleteAll(m_outlets);
8 ✔
242
  m_outlets.clear();
8 ✔
243

244
  if(m_presenter)
8 ✔
245
  {
246
    QPointer<Process::LayerView> oldView = static_cast<Process::LayerView*>(m_fx);
1 ✔
247
    delete m_presenter;
1 ✔
248
    m_presenter = nullptr;
1 ✔
249
    if(oldView)
1 ✔
250
      delete oldView;
1 ✔
251
    m_fx = nullptr;
1 ✔
252
    QObject::disconnect(&m_model, &Process::ProcessModel::setSize, this, nullptr);
1 ✔
253
  }
1 ✔
254
  else
255
  {
256
    delete m_fx;
7 ✔
257
    m_fx = nullptr;
7 ✔
258
  }
259

260
  m_contentSize = QSizeF{minimalContentWidth(), minimalContentHeight()};
8 ✔
261
}
8 ✔
262

263
void NodeItem::resetInlets()
2,512 ✔
264
{
265
  // if(!m_presenter)
266
  //   return;
267
  qDeleteAll(m_inlets);
2,512 ✔
268
  m_inlets.clear();
2,512 ✔
269

270
  // We don't display ports on the left & right side
271
  // for normal items which are supposed to handle it
272
  if(dynamic_cast<Process::DefaultEffectItem*>(m_fx) && !m_presenter)
2,512 ✔
273
    return updateTitlePos();
872 ✔
274

275
  const qreal x = InletX0;
1,640 ✔
276
  qreal y = m_label ? InletY0 : InletY0 - 10.;
1,640 ✔
277
  auto& portFactory = score::GUIAppContext().interfaces<Process::PortFactoryList>();
1,640 ✔
278
  for(Process::Inlet* port : m_model.inlets())
28,667 ✔
279
  {
280
    if(port->displayHandledExplicitly)
27,027 ✔
281
      continue;
25,313 ✔
282

283
    Process::PortFactory* fact = portFactory.get(port->concreteKey());
1,714 ✔
284
    Dataflow::PortItem* item = fact->makePortItem(*port, m_context, this, this);
1,714 ✔
285
    item->setPos(x, y);
1,714 ✔
286
    item->setZValue(10);
1,714 ✔
287
    m_inlets.push_back(item);
1,714 ✔
288

289
    y += PortSpacing;
1,714 ✔
290
  }
291

292
  updateTitlePos();
1,640 ✔
293
}
2,512 ✔
294

295
void NodeItem::resetOutlets()
2,374 ✔
296
{
297
  // if(!m_presenter)
298
  //   return;
299
  qDeleteAll(m_outlets);
2,374 ✔
300
  m_outlets.clear();
2,374 ✔
301

302
  // We don't display ports on the left & right side
303
  // for normal items which are supposed to handle it
304
  if(dynamic_cast<Process::DefaultEffectItem*>(m_fx) && !m_presenter)
2,374 ✔
305
    return updateTitlePos();
734 ✔
306

307
  const qreal x = m_contentSize.width() + OutletX0;
1,640 ✔
308
  qreal y = m_label ? OutletY0 : OutletY0 - 10.;
1,640 ✔
309

310
  auto& portFactory = score::AppContext().interfaces<Process::PortFactoryList>();
1,640 ✔
311
  for(Process::Outlet* port : m_model.outlets())
5,325 ✔
312
  {
313
    if(port->displayHandledExplicitly)
3,685 ✔
314
      continue;
×
315
    Process::PortFactory* fact = portFactory.get(port->concreteKey());
3,685 ✔
316
    auto item = fact->makePortItem(*port, m_context, this, this);
3,685 ✔
317
    item->setPos(x, y);
3,685 ✔
318
    item->setZValue(10);
3,685 ✔
319
    m_outlets.push_back(item);
3,685 ✔
320

321
    y += PortSpacing;
3,685 ✔
322
  }
323
}
2,374 ✔
324

325
void NodeItem::updateLabel()
1,765 ✔
326
{
327
  if(const auto& name = m_model.metadata().getName(); !name.isEmpty())
1,765 ✔
328
  {
329
    m_label->setText(name);
1,765 ✔
330
  }
1,765 ✔
331
  else if(const auto& label = m_model.metadata().getLabel(); !label.isEmpty())
×
332
  {
333
    m_label->setText(label);
×
334
  }
×
335
  else
336
  {
337
    m_label->setText(m_model.prettyShortName());
×
338
  }
339

340
  if(auto resizeable = dynamic_cast<score::ResizeableItem*>(m_fx))
1,765 ✔
341
  {
342
    resizeable->setMinimumWidth(minimalContentWidth());
100 ✔
343
  }
100 ✔
344
  QTimer::singleShot(2, this, &NodeItem::updateSize);
1,765 ✔
345
}
1,765 ✔
346

347
void NodeItem::updateTitlePos()
16,382 ✔
348
{
349
  if(!m_label)
16,382 ✔
350
    return;
1 ✔
351

352
  double x0 = FoldX0;
16,381 ✔
353
  if(!m_inlets.empty())
16,381 ✔
354
    x0 += InletX0;
6,923 ✔
355

356
  m_fold->setPos({x0, FoldY0});
16,381 ✔
357
  x0 += UiX0 - FoldX0 + 2.;
16,381 ✔
358

359
  if(m_scriptButton)
16,381 ✔
360
  {
361
    m_scriptButton->setPos({x0, UiY0});
3,013 ✔
362
    x0 += UiX0 + SpacingIcon;
3,013 ✔
363
  }
3,013 ✔
364

365
  if(m_uiButton)
16,381 ✔
366
  {
367
    m_uiButton->setPos({x0, UiY0});
415 ✔
368
    x0 += UiX0 + SpacingIcon;
415 ✔
369
  }
415 ✔
370

371
  if(m_presetButton)
16,381 ✔
372
  {
373
    m_presetButton->setPos({x0, UiY0});
16,381 ✔
374
    x0 += UiX0 + SpacingIcon * 2.;
16,381 ✔
375
  }
16,381 ✔
376

377
  m_label->setPos({x0, TitleY0});
16,381 ✔
378
}
16,382 ✔
379

380
QSizeF NodeItem::size() const noexcept
×
381
{
382
  return m_contentSize;
×
383
}
384

385
void NodeItem::setSelected(bool s)
26 ✔
386
{
387
  m_selected = s;
26 ✔
388
  if(s)
26 ✔
389
    setFocus();
22 ✔
390
  else
391
    clearFocus();
4 ✔
392

393
  update();
26 ✔
394
}
26 ✔
395

396
QRectF NodeItem::contentRect() const noexcept
6,774 ✔
397
{
398
  if(!m_label)
6,774 ✔
399
  {
400
    return {
1 ✔
401
        0, 0, m_contentSize.width() + RightSideWidth,
1 ✔
402
        m_contentSize.height() + FooterHeight};
1 ✔
403
  }
404
  else
405
  {
406
    double x = 0;
6,773 ✔
407
    double y = -TitleHeight;
6,773 ✔
408
    double w = m_contentSize.width();
6,773 ✔
409
    const double h = m_contentSize.height() + TitleHeight + FooterHeight;
6,773 ✔
410
    if(!m_inlets.empty())
6,773 ✔
411
    {
412
      x -= LeftSideWidth;
3,673 ✔
413
      w += LeftSideWidth;
3,673 ✔
414
    }
3,673 ✔
415
    if(!m_outlets.empty() || m_presenter)
6,773 ✔
416
    { // FIXME make the redimension handle an item instead
417
      w += RightSideWidth;
4,240 ✔
418
    }
4,240 ✔
419
    return {x, y, w, h};
6,773 ✔
420
  }
421
}
6,774 ✔
422

423
void NodeItem::updateContentRect()
6,772 ✔
424
{
425
  const QRectF r = contentRect().adjusted(-2., -2., 2., 2.);
6,772 ✔
426
  if(r == m_contentRect)
6,772 ✔
427
    return;
4,719 ✔
428
  m_contentRect = r;
2,053 ✔
429
  geometryChanged();
2,053 ✔
430
}
6,772 ✔
431

432
QRectF NodeItem::boundingRect() const
180,132 ✔
433
{
434
  return m_contentRect.adjusted(-2., -2., 2., 2.);
180,132 ✔
435
}
436

437
//! Redraw for a fold state that has already been decided by the model.
438
void NodeItem::applyFold(bool folded)
2 ✔
439
{
440
  if(!m_fold || folded == m_folded)
2 ✔
441
    return;
1 ✔
442

443
  // setState() deliberately does not re-emit toggled(), so this cannot loop
444
  // back into the command that brought us here.
445
  m_fold->setState(!folded);
1 ✔
446

447
  resetItem();
1 ✔
448

449
  m_folded = folded;
1 ✔
450
  if(!m_folded)
1 ✔
451
  {
452
    createContentItem();
×
453
  }
×
454
  else
455
  {
456
    createFoldedItem();
1 ✔
457
  }
458

459
  QTimer::singleShot(1, this, [this] {
2 ✔
460
    resetInlets();
1 ✔
461
    resetOutlets();
1 ✔
462

463
    resizeAsync();
1 ✔
464
  });
1 ✔
465
}
2 ✔
466

467
void NodeItem::createFoldedItem()
114 ✔
468
{
469
  if(m_fx)
114 ✔
470
    return;
×
471

472
  auto& ctx = m_context;
114 ✔
473
  auto& model = m_model;
114 ✔
474
  // Body
475
  score::ResizeableItem* resizeable{};
114 ✔
476
  {
477
    auto fx = new Process::DefaultEffectItem{true, model, ctx, this};
114 ✔
478
    m_fx = fx;
114 ✔
479
    m_contentSize = m_fx->boundingRect().size(); // FIXME async, size is not set yet
114 ✔
480
    resizeable = fx;
114 ✔
481
  }
482
  setupItem(resizeable);
114 ✔
483
}
114 ✔
484

485
void NodeItem::createContentItem()
1,535 ✔
486
{
487
  if(m_fx)
1,535 ✔
488
    return;
×
489

490
  auto& ctx = m_context;
1,535 ✔
491
  auto& model = m_model;
1,535 ✔
492
  // Body
493
  auto& fact = ctx.app.interfaces<Process::LayerFactoryList>();
1,535 ✔
494
  score::ResizeableItem* resizeable{};
1,535 ✔
495
  if(auto factory = fact.findDefaultFactory(model))
1,535 ✔
496
  {
497
    if(auto fx = factory->makeItem(model, ctx, this))
1,226 ✔
498
    {
499
      m_fx = fx;
1,130 ✔
500
      m_contentSize = m_fx->boundingRect().size(); // FIXME async, size is not set yet
1,130 ✔
501
      resizeable = fx;
1,130 ✔
502
    }
1,130 ✔
503
    else if(auto fx = factory->makeLayerView(model, ctx, this))
96 ✔
504
    {
505
      m_fx = fx;
96 ✔
506
      m_presenter = factory->makeLayerPresenter(model, fx, ctx, this);
96 ✔
507
      m_contentSize = m_model.size();
96 ✔
508
      m_presenter->setWidth(m_contentSize.width(), m_contentSize.width());
96 ✔
509
      m_presenter->setHeight(m_contentSize.height());
96 ✔
510

511
      // TODO review the resizing heuristic...
512
      if(m_presenter)
96 ✔
513
      {
514
        ::bind(model, Process::ProcessModel::p_size{}, this, [this](QSizeF s) {
193 ✔
515
          if(s != m_contentSize)
97 ✔
516
            setSize(s);
×
517
        });
97 ✔
518
          connect(m_presenter, &Process::LayerPresenter::contextMenuRequested, this, [this] (QPoint pos, QPointF sp) {
96 ✔
519
              auto menu = new QMenu;
×
520
              auto& reg = score::GUIAppContext()
×
521
                              .applicationPlugin<Process::ApplicationPlugin>()
×
522
                              .layerContextMenuRegistrar();
×
523

524
              m_presenter->fillContextMenu(*menu, pos, sp, reg);
×
525
              if(menu->actions().size() > 0) {
×
526
                menu->exec(pos);
×
527
                menu->close();
×
528
              }
×
529

530
              menu->deleteLater();
×
531
          }, Qt::QueuedConnection);
×
532
      }
96 ✔
533
    }
96 ✔
534
  }
1,226 ✔
535

536
  if(!m_fx)
1,535 ✔
537
  {
538
    auto fx = new Process::DefaultEffectItem{false, model, ctx, this};
309 ✔
539
    m_fx = fx;
309 ✔
540
    m_contentSize = m_fx->boundingRect().size(); // FIXME async, size is not set yet
309 ✔
541
    resizeable = fx;
309 ✔
542
  }
309 ✔
543

544
  setupItem(resizeable);
1,535 ✔
545
}
1,535 ✔
546

547
void NodeItem::resizeAsync()
6,406 ✔
548
{
549
  updateTitlePos();
6,406 ✔
550
  if(auto resizeable = dynamic_cast<score::ResizeableItem*>(m_fx))
6,406 ✔
551
  {
552
    resizeable->setMinimumWidth(minimalContentWidth());
6,144 ✔
553
    // Needed to leave some time for defaulteffectitem
554
    QTimer::singleShot(2, this, [this] {
11,314 ✔
555
      updateSize();
5,170 ✔
556
      updateZoomRatio();
5,170 ✔
557
    });
5,170 ✔
558
  }
6,144 ✔
559
  else
560
  {
561
    QMetaObject::invokeMethod(this, [this] {
524 ✔
562
      updateSize();
262 ✔
563
      updateZoomRatio();
262 ✔
564
    });
262 ✔
565
  }
566
}
6,406 ✔
567

568
void NodeItem::recreate()
7 ✔
569
{
570
  resetItem();
7 ✔
571
  qDeleteAll(this->childItems());
7 ✔
572
  m_scriptButton = nullptr;
7 ✔
573
  m_uiButton = nullptr;
7 ✔
574
  m_presetButton = nullptr;
7 ✔
575
  m_label = nullptr;
7 ✔
576
  m_fold = nullptr;
7 ✔
577
  disconnect(&this->m_model, nullptr, this, nullptr);
7 ✔
578
  disconnect(&this->m_model.selection, nullptr, this, nullptr);
7 ✔
579
  disconnect(&this->m_model.metadata(), nullptr, this, nullptr);
7 ✔
580

581
  if(this->m_model.flags() & Process::ProcessFlags::FullyCustomItem)
7 ✔
582
  {
583
    createWithoutDecorations();
×
584
  }
×
585
  else
586
  {
587
    createWithDecorations();
7 ✔
588
  }
589

590
  initConnections();
7 ✔
591
}
7 ✔
592

593
void NodeItem::setupItem(score::ResizeableItem* resizeable)
1,649 ✔
594
{
595
  // Positions / size
596
  double w = std::max(minimalContentWidth(), m_contentSize.width());
1,649 ✔
597
  double h = std::max(minimalContentHeight(), m_contentSize.height());
1,649 ✔
598
  m_contentSize = QSizeF{w, h};
1,649 ✔
599

600
  resizeAsync();
1,649 ✔
601
  publishSize();
1,649 ✔
602

603
  if(resizeable)
1,649 ✔
604
  {
605
    if(auto lay = dynamic_cast<score::GraphicsLayout*>(resizeable))
1,553 ✔
606
      connect(lay, &score::ResizeableItem::childrenSizeChanged, this, [this, lay] {
952 ✔
607
        lay->layout();
206 ✔
608
        lay->fitChildrenRect();
206 ✔
609
        m_contentSize = lay->rect().size();
206 ✔
610

611
        resizeAsync();
206 ✔
612
      });
206 ✔
613
    connect(resizeable, &score::ResizeableItem::sizeChanged, this, [this](QSizeF sz) {
2,066 ✔
614
      double w = std::max(minimalContentWidth(), sz.width());
513 ✔
615
      double h = std::max(minimalContentHeight(), sz.height());
513 ✔
616
      m_contentSize = QSizeF{w, h};
513 ✔
617

618
      resizeAsync();
513 ✔
619
    });
513 ✔
620
  }
1,553 ✔
621
}
1,649 ✔
622

623
double NodeItem::minimalContentWidth() const noexcept
15,145 ✔
624
{
625
  if(Q_UNLIKELY(!m_label))
15,145 ✔
626
  {
627
    if((m_inlets.size() + m_outlets.size()) <= 1)
2 ✔
628
      return 10.;
2 ✔
629
    else
630
      return 20.;
×
631
  }
632
  else
633
  {
634
    return std::max(75.0, m_label->pos().x() + m_label->boundingRect().width() + 6.);
15,143 ✔
635
  }
636
}
15,145 ✔
637
double NodeItem::minimalContentHeight() const noexcept
8,901 ✔
638
{
639
  if(Q_UNLIKELY(!m_label))
8,901 ✔
640
    if(std::max(m_inlets.size(), m_outlets.size()) <= 1)
2 ✔
641
      return 10.;
2 ✔
642

643
  double h = 22.;
8,899 ✔
644
  if(!m_inlets.empty())
8,899 ✔
645
    h = std::max(h, m_inlets.back()->y() + 10.);
3,673 ✔
646
  if(!m_outlets.empty())
8,899 ✔
647
    h = std::max(h, m_outlets.back()->y() + 10.);
4,048 ✔
648
  return h;
8,899 ✔
649
}
8,901 ✔
650

651
void NodeItem::updateSize()
6,731 ✔
652
{
653
  if(m_model.flags() & Process::ProcessFlags::FullyCustomItem)
6,731 ✔
654
  {
655
    if(m_presenter)
1 ✔
656
      resizePresenter();
1 ✔
657
    // A fully-custom item lays out its own ports, so the node has to be at
658
    // least as wide as that item: keeping the width the title asked for draws
659
    // the border inside the item, and the ports it placed on its own right
660
    // edge end up outside the node. Short titles are where this shows, since
661
    // that is when the title is not what decides the width.
662
    QSizeF sz{minimalContentWidth(), minimalContentHeight()};
1 ✔
663
    if(m_fx)
1 ✔
664
    {
665
      auto fx_sz = m_fx->boundingRect().size();
1 ✔
666
      sz.rwidth() = std::max(sz.width(), fx_sz.width());
1 ✔
667
      sz.rheight() = std::max(sz.height(), fx_sz.height());
1 ✔
668
    }
1 ✔
669
    if(sz != m_contentSize)
1 ✔
670
    {
671
      prepareGeometryChange();
×
672
      m_contentSize = sz;
×
673
      publishSize();
×
674
    }
×
675
    updateContentRect();
1 ✔
676
    update();
1 ✔
677
    if(auto sc = this->scene())
1 ✔
678
      sc->update();
1 ✔
679
    return;
1 ✔
680
  }
681

682
  if(!m_label)
6,730 ✔
683
  {
684
    if(auto sc = this->scene())
×
685
      sc->update();
×
686
    return;
×
687
  }
688
  QSizeF sz{minimalContentWidth(), minimalContentHeight()};
6,730 ✔
689
  if(m_fx)
6,730 ✔
690
  {
691
    auto fx_sz = m_fx->boundingRect().size();
6,730 ✔
692
    sz.rwidth() = std::max(sz.width(), fx_sz.width());
6,730 ✔
693
    sz.rheight() = std::max(sz.height(), fx_sz.height());
6,730 ✔
694
  }
6,730 ✔
695
  //if (sz != m_contentSize || !m_fx)
696
  {
697
    prepareGeometryChange();
6,730 ✔
698
    if(m_fx)
6,730 ✔
699
    {
700
      m_contentSize = sz;
6,730 ✔
701
      if(!m_presenter)
6,730 ✔
702
      {
703
        if(m_model.outlets().size() > 0 && m_model.inlets().size() == 0)
6,381 ✔
704
        {
705
          // Align right for the case where we only have a series of outlets
706
          updateContentRect();
41 ✔
707
          m_fx->setPos(m_contentRect.width() - m_fx->boundingRect().width(), 0);
41 ✔
708
        }
41 ✔
709
        else
710
        {
711
          m_fx->setPos(0, 0);
6,340 ✔
712
        }
713
      }
6,381 ✔
714
    }
6,730 ✔
715

716
    if(m_presenter)
6,730 ✔
717
      resizePresenter();
349 ✔
718

719
    if(m_scriptButton)
6,730 ✔
720
    {
721
      m_scriptButton->setParentItem(nullptr);
1,009 ✔
722
    }
1,009 ✔
723
    if(m_uiButton)
6,730 ✔
724
    {
725
      m_uiButton->setParentItem(nullptr);
183 ✔
726
    }
183 ✔
727

728
    for(auto& outlet : m_outlets)
15,910 ✔
729
    {
730
      outlet->setPos(m_contentSize.width() + OutletX0, outlet->pos().y());
9,180 ✔
731
    }
732

733
    if(m_scriptButton)
6,730 ✔
734
    {
735
      m_scriptButton->setParentItem(this);
1,009 ✔
736
    }
1,009 ✔
737
    if(m_uiButton)
6,730 ✔
738
    {
739
      m_uiButton->setParentItem(this);
183 ✔
740
    }
183 ✔
741
    updateTitlePos();
6,730 ✔
742
    updateContentRect();
6,730 ✔
743
    publishSize();
6,730 ✔
744
    update();
6,730 ✔
745
    if(auto sc = this->scene())
6,730 ✔
746
      sc->update();
6,730 ✔
747
  }
748
}
6,731 ✔
749

750
void NodeItem::publishSize()
8,379 ✔
751
{
752
  // Node placement (e.g. creating a process after another one) reads the size
753
  // off the model: keep it in sync with what is actually drawn. A folded node
754
  // must not overwrite the unfolded size it will go back to.
755
  if(m_folded)
8,379 ✔
756
    return;
732 ✔
757
  if(m_model.flags() & Process::ProcessFlags::FullyCustomItem)
7,647 ✔
758
    return;
1 ✔
759
  if(m_model.size() == m_contentSize)
7,646 ✔
760
    return;
5,904 ✔
761

762
  const_cast<Process::ProcessModel&>(m_model).setSize(m_contentSize);
1,742 ✔
763
}
8,379 ✔
764

765
void NodeItem::setSize(QSizeF sz)
×
766
{
767
  if(m_presenter)
×
768
  {
769
    // TODO: find a way to indicate to a model what will be the size of the
770
    // item
771
    //      - maybe set it without a command in that case ?
772
    prepareGeometryChange();
×
773
    m_contentSize = sz;
×
774

775
    if(m_scriptButton)
×
776
    {
777
      m_scriptButton->setParentItem(nullptr);
×
778
    }
×
779
    if(m_uiButton)
×
780
    {
781
      m_uiButton->setParentItem(nullptr);
×
782
    }
×
783

784
    resizePresenter();
×
785

786
    resetInlets();
×
787
    resetOutlets();
×
788
    auto cur_x = m_contentSize.width() + TopButtonX0;
×
789
    if(m_scriptButton)
×
790
    {
791
      m_scriptButton->setParentItem(this);
×
792
      m_scriptButton->setPos({cur_x, TopButtonY0});
×
793
      cur_x += UiX0 + SpacingIcon;
×
794
    }
×
795
    if(m_uiButton)
×
796
    {
797
      m_uiButton->setParentItem(this);
×
798
      m_uiButton->setPos({cur_x, TopButtonY0});
×
799
    }
×
800
  }
×
801
  if(auto resizeable = dynamic_cast<score::ResizeableItem*>(m_fx))
×
802
  {
803
    resizeable->setMinimumWidth(sz.width());
×
804
  }
×
805
  updateContentRect();
×
806
  update();
×
807
  if(auto sc = this->scene())
×
808
    sc->update();
×
809
}
×
810

811
const Id<Process::ProcessModel>& NodeItem::id() const noexcept
6 ✔
812
{
813
  return m_model.id();
6 ✔
814
}
815

816
NodeItem::~NodeItem()
3,282 ✔
817
{
3,282 ✔
818
  clearDropCableHighlight();
1,641 ✔
819
  delete m_presenter;
1,641 ✔
820
}
3,282 ✔
821

822
void NodeItem::setParentDuration(TimeVal r)
5 ✔
823
{
824
  if(r != m_parentDuration)
5 ✔
825
  {
826
    m_parentDuration = r;
×
827
    updateZoomRatio();
×
828
  }
×
829
}
5 ✔
830

831
void NodeItem::setPlayPercentage(float f, TimeVal parent_dur)
1,106 ✔
832
{
833
  if(this->m_model.flags() & Process::ProcessFlags::FullyCustomItem)
1,106 ✔
834
    return;
×
835

836
  if(m_playPercentage != f)
1,106 ✔
837
  {
838
    // Comes from the interval -> if we are looping we make a small modulo of it
839
    if(m_model.loops() && m_model.loopDuration().impl > 0)
×
840
    {
841
      auto loopDur = m_model.loopDuration().impl;
×
842
      double playdur = double(f) * parent_dur.impl;
×
843
      f = std::fmod(playdur, loopDur) / loopDur;
×
844
      if(m_playPercentage != f)
×
845
      {
846
        m_playPercentage = f;
×
847
        update({12., -1., (m_contentSize.width() - 24.), 3.});
×
848
      }
×
849
    }
×
850
    else
851
    {
852
      f = ossia::clamp(f, 0.f, 1.f);
×
853
      if(m_playPercentage != f)
×
854
      {
855
        m_playPercentage = f;
×
856
        update({12., -1., (m_contentSize.width() - 24.) * f + 1., 3.});
×
857
      }
×
858
    }
859
  }
×
860
}
1,106 ✔
861

862
qreal NodeItem::width() const noexcept
×
863
{
864
  return m_contentSize.width();
×
865
}
866

867
qreal NodeItem::height() const
×
868
{
869
  return TitleHeight + m_contentSize.height() + FooterHeight;
×
870
}
871

872
void NodeItem::initConnections()
1,648 ✔
873
{
874
  auto& process = this->model();
1,648 ✔
875
  ::bind(process, Process::ProcessModel::p_position{}, this, [this](QPointF p) {
3,303 ✔
876
    if(p != pos())
1,655 ✔
877
      setPos(p);
1,645 ✔
878
  });
1,655 ✔
879

880
  auto on_sizeChanged = [this] {
4,072 ✔
881
    m_needResize = true;
2,424 ✔
882
    QTimer::singleShot(1, this, [this] {
4,740 ✔
883
      if(!m_needResize)
2,316 ✔
884
        return;
1,156 ✔
885
      m_needResize = false;
1,160 ✔
886
      resizeAsync();
1,160 ✔
887
    });
2,316 ✔
888
  };
2,424 ✔
889
  connect(&process, &Process::ProcessModel::controlAdded, this, on_sizeChanged);
1,648 ✔
890
  connect(&process, &Process::ProcessModel::controlRemoved, this, on_sizeChanged);
1,648 ✔
891
  connect(&process, &Process::ProcessModel::controlOutletAdded, this, on_sizeChanged);
1,648 ✔
892
  connect(&process, &Process::ProcessModel::controlOutletRemoved, this, on_sizeChanged);
1,648 ✔
893
  connect(&process, &Process::ProcessModel::inletsChanged, this, on_sizeChanged);
1,648 ✔
894
  connect(&process, &Process::ProcessModel::outletsChanged, this, on_sizeChanged);
1,648 ✔
895
  connect(&process, &Process::ProcessModel::flagsChanged, this, &NodeItem::recreate);
1,648 ✔
896
}
1,648 ✔
897

898
const ProcessModel& NodeItem::model() const noexcept
8,682 ✔
899
{
900
  return m_model;
8,682 ✔
901
}
902

903
void NodeItem::resizePresenter()
350 ✔
904
{
905
  m_presenter->setWidth(m_contentSize.width(), m_contentSize.width());
350 ✔
906
  m_presenter->setHeight(m_contentSize.height());
350 ✔
907
  updateZoomRatio();
350 ✔
908
}
350 ✔
909

910
void NodeItem::updateZoomRatio() const noexcept
5,784 ✔
911
{
912
  const auto dur = m_model.loops() ? m_model.loopDuration() : m_parentDuration;
5,784 ✔
913
  if(m_presenter)
5,784 ✔
914
  {
915
    m_presenter->on_zoomRatioChanged(dur.impl / m_contentSize.width());
614 ✔
916
    // TODO investigate why this is necessary for scenario:
917
    m_presenter->parentGeometryChanged();
614 ✔
918
  }
614 ✔
919
}
5,784 ✔
920

921
bool NodeItem::isInSelectionCorner(QPointF p, QRectF r) const
×
922
{
923
  return (p.x() - r.x()) > (r.width() - 10.) && (p.y() - r.y()) > (r.height() - 10.);
×
924
}
925

926
void NodeItem::paint(
8 ✔
927
    QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
928
{
929
  auto& style = Process::Style::instance();
8 ✔
930
  const auto& skin = style.skin;
8 ✔
931
  const auto rect = m_contentRect;
8 ✔
932
  //painter->fillRect(boundingRect(), Qt::red);
933
  //return;
934
  const auto flags = this->m_model.flags();
8 ✔
935

936
  const auto& bset = skin.Emphasis5;
8 ✔
937
  const auto& fillbrush = !(flags & Process::ProcessFlags::NodeHasNoBackground)
8 ✔
938
                              ? skin.Emphasis5
8 ✔
939
                              : skin.TransparentBrush;
×
940
  const auto& brush = m_selected ? skin.Base2.darker
16 ✔
941
                      : m_hover  ? bset.lighter
8 ✔
942
                                 : bset.main;
8 ✔
943
  const auto& pen = m_dropping ? skin.Warn2.main.pen3_solid_round_round
8 ✔
944
                               : brush.pen2_solid_round_round;
8 ✔
945

946
  painter->setRenderHint(QPainter::Antialiasing, true);
8 ✔
947

948
  // Body
949
  painter->setPen(pen);
8 ✔
950

951
#if defined(SCORE_DEBUG_REDRAWS)
952
  {
953
    QColor c;
954
    c.setRedF(0.5 * double(rand()) / RAND_MAX);
955
    c.setGreenF(0.5 * double(rand()) / RAND_MAX);
956
    c.setBlueF(0.5 * double(rand()) / RAND_MAX);
957
    c.setAlphaF(1.);
958
    painter->setBrush(c);
959
  }
960
#else
961
  painter->setBrush(fillbrush);
8 ✔
962
#endif
963

964
  painter->drawRoundedRect(rect, Corner, Corner);
8 ✔
965

966
  painter->setRenderHint(QPainter::Antialiasing, false);
8 ✔
967

968
  // Exec
969
  if(!(flags & Process::ProcessFlags::FullyCustomItem))
8 ✔
970
    if(m_playPercentage > 0.)
8 ✔
971
    {
972
      painter->setPen(style.IntervalPlayFill().main.pen1_solid_flat_miter);
×
973
      painter->drawLine(
×
974
          QPointF{12., 0.}, QPointF{12. + (width() - 24.) * m_playPercentage, 0.});
×
975
    }
×
976

977
  // Resizing handle
978
  if(m_presenter)
8 ✔
979
  {
980
    const auto h = m_contentSize.height();
8 ✔
981
    const auto w = m_contentSize.width()
10 ✔
982
                   + ((!m_outlets.empty() || m_presenter) ? RightSideWidth : 0);
8 ✔
983
    painter->setPen(style.IntervalWarning().main.pen0_solid_round);
8 ✔
984
    double start_x = w - 6.;
8 ✔
985
    double start_y = h - 6.;
8 ✔
986
    double center_x = w - 2.;
8 ✔
987
    double center_y = h - 2.;
8 ✔
988
    painter->drawLine(start_x, center_y, center_x, center_y);
8 ✔
989
    painter->drawLine(center_x, start_y, center_x, center_y);
8 ✔
990
  }
8 ✔
991
}
8 ✔
992

993
namespace
994
{
995
enum Interaction
996
{
997
  None,
998
  Move,
999
  Resize
1000
} nodeItemInteraction{};
1001
QSizeF origNodeSize{};
1002
bool nodeDidMove{};
1003
bool nodeSelectOnRelease{};
1004
bool nodeSelectCumulation{};
1005
}
1006

1007
void NodeItem::mousePressEvent(QGraphicsSceneMouseEvent* event)
4 ✔
1008
{
1009
  nodeItemInteraction = Interaction::None;
4 ✔
1010
  if(event->button() == Qt::LeftButton)
4 ✔
1011
  {
1012
    nodeDidMove = false;
4 ✔
1013
    if(m_presenter && isInSelectionCorner(event->pos(), m_contentRect))
4 ✔
1014
    {
1015
      nodeItemInteraction = Interaction::Resize;
×
1016
      origNodeSize = m_model.size();
×
1017
    }
×
1018
    else
1019
    {
1020
      nodeItemInteraction = Interaction::Move;
4 ✔
1021
    }
1022

1023
    if(m_presenter && m_model.flags() & Process::ProcessFlags::ItemRequiresUniqueFocus)
4 ✔
1024
    {
1025
      m_context.focusDispatcher.focus(m_presenter);
×
1026
    }
×
1027
    {
1028
      const bool cumulation = event->modifiers() & Qt::ControlModifier;
4 ✔
1029

1030
      // Membership of the selection stack, not ProcessModel::selection: the
1031
      // latter is also set on a process that merely *contains* the selection --
1032
      // clicking a port marks its parent node selected so that the node draws
1033
      // its frame, while the stack holds only the port. Deferring on the flag
1034
      // left such a node drawn as selected and yet impossible to drag, since
1035
      // selectedProcesses() below reads the stack and would come back empty.
1036
      const Selection current = m_context.selectionStack.currentSelection();
4 ✔
1037
      if(current.contains(&m_model))
4 ✔
1038
      {
1039
        nodeSelectOnRelease = true;
1 ✔
1040
        nodeSelectCumulation = cumulation;
1 ✔
1041
      }
1 ✔
1042
      else
1043
      {
1044
        nodeSelectOnRelease = false;
3 ✔
1045
        Selection sel;
3 ✔
1046
        if(cumulation)
3 ✔
1047
          sel = current;
×
1048
        sel.append(&m_model);
3 ✔
1049
        score::SelectionDispatcher{m_context.selectionStack}.select(sel);
3 ✔
1050
      }
3 ✔
1051
    }
4 ✔
1052
    event->accept();
4 ✔
1053
  }
4 ✔
1054
  else
1055
  {
1056
    return QGraphicsItem::mousePressEvent(event);
×
1057
  }
1058
}
4 ✔
1059
namespace
1060
{
1061
static std::vector<const Process::ProcessModel*>
1062
selectedProcesses(const score::DocumentContext& ctx)
5 ✔
1063
{
1064
  std::vector<const Process::ProcessModel*> ps;
5 ✔
1065
  auto sel = ctx.selectionStack.currentSelection();
5 ✔
1066
  ps.reserve(sel.size());
5 ✔
1067
  for(auto& obj : sel)
10 ✔
1068
    if(auto p = qobject_cast<Process::ProcessModel*>(obj))
5 ✔
1069
    {
1070
      ps.push_back(p);
5 ✔
1071
    }
5 ✔
1072
  return ps;
5 ✔
1073
}
5 ✔
1074
}
1075
//! The single cable the node was let go on top of, if any: ambiguous drops
1076
//! (more than one cable under the node) do nothing.
1077
static const Process::Cable* cableUnder(const NodeItem& node, QRectF contentRect)
×
1078
{
1079
  auto sc = node.scene();
×
1080
  if(!sc)
×
1081
    return nullptr;
×
1082

1083
  const Process::Cable* res{};
×
1084
  for(auto item : sc->items(node.mapToScene(contentRect.center())))
×
1085
  {
1086
    if(item->type() != Dataflow::CableItem::Type)
×
1087
      continue;
×
1088
    if(res)
×
1089
      return nullptr;
×
1090
    res = &static_cast<Dataflow::CableItem*>(item)->model();
×
1091
  }
1092
  return res;
×
1093
}
×
1094

1095
void NodeItem::updateDropCableHighlight()
5 ✔
1096
{
1097
  Dataflow::CableItem* next{};
5 ✔
1098
  if(canDropOnCableHandler)
5 ✔
1099
  {
1100
    if(auto* cbl = cableUnder(*this, m_contentRect))
×
1101
    {
1102
      if(canDropOnCableHandler(m_model, *cbl))
×
1103
      {
1104
        auto& cables = m_context.dataflow.cables();
×
1105
        if(auto it = cables.find(cbl); it != cables.end())
×
1106
          next = it->second;
×
1107
      }
×
1108
    }
×
1109
  }
×
1110

1111
  if(next == m_dropCable)
5 ✔
1112
    return;
5 ✔
1113
  if(m_dropCable)
×
1114
    m_dropCable->setDropTarget(false);
×
1115
  m_dropCable = next;
×
1116
  if(m_dropCable)
×
1117
    m_dropCable->setDropTarget(true);
×
1118
}
5 ✔
1119

1120
void NodeItem::clearDropCableHighlight()
1,646 ✔
1121
{
1122
  if(m_dropCable)
1,646 ✔
1123
    m_dropCable->setDropTarget(false);
×
1124
  m_dropCable = nullptr;
1,646 ✔
1125
}
1,646 ✔
1126

1127
void NodeItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
6 ✔
1128
{
1129
  if(nodeItemInteraction == Interaction::None)
6 ✔
1130
    return QGraphicsItem::mouseMoveEvent(event);
×
1131

1132
  auto parent = this->parentItem();
6 ✔
1133
  auto origp = parent->mapFromScene(event->buttonDownScenePos(Qt::LeftButton));
6 ✔
1134
  auto p = parent->mapFromScene(event->scenePos());
6 ✔
1135
  if(p != origp)
6 ✔
1136
    nodeDidMove = true;
5 ✔
1137

1138
  if(nodeDidMove)
6 ✔
1139
  {
1140
    switch(nodeItemInteraction)
5 ✔
1141
    {
1142
      case Interaction::Resize: {
1143
        const auto sz = origNodeSize + QSizeF{p.x() - origp.x(), p.y() - origp.y()};
×
1144
        m_dispatcher.submit<Process::ResizeNode>(
×
1145
            m_model, sz.expandedTo({minimalContentWidth(), minimalContentHeight()}));
×
1146
        updateSize();
×
1147
        break;
×
1148
      }
1149
      case Interaction::Move: {
1150
        auto procs = selectedProcesses(m_context);
5 ✔
1151
        // The press put this node in the selection, so it is normally already
1152
        // in here; a selection that somehow does not hold it would turn the
1153
        // whole drag into a silent no-op rather than moving the node under the
1154
        // mouse.
1155
        if(!ossia::contains(procs, &m_model))
5 ✔
1156
          procs.push_back(&m_model);
×
1157
        m_dispatcher.submit<Process::MoveNodes>(std::move(procs), p - origp);
5 ✔
1158
        updateDropCableHighlight();
5 ✔
1159
        break;
1160
      }
5 ✔
1161
      default:
1162
        break;
×
1163
    }
1164
  }
5 ✔
1165
  event->accept();
6 ✔
1166
}
6 ✔
1167

1168

1169
void NodeItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
3 ✔
1170
{
1171
  if(nodeItemInteraction == Interaction::None)
3 ✔
1172
    return QGraphicsItem::mouseReleaseEvent(event);
×
1173

1174
  mouseMoveEvent(event);
3 ✔
1175

1176
  clearDropCableHighlight();
3 ✔
1177

1178
  if(nodeDidMove)
3 ✔
1179
  {
1180
    // Part of the same macro as the move: dropping a node on a cable is a
1181
    // single gesture and must undo as one.
1182
    if(dropOnCableHandler && nodeItemInteraction == Interaction::Move)
2 ✔
1183
    {
1184
      if(auto cbl = cableUnder(*this, m_contentRect);
×
1185
         cbl && (!canDropOnCableHandler || canDropOnCableHandler(m_model, *cbl)))
×
1186
      {
1187
        score::Dispatcher_T<MultiOngoingCommandDispatcher> disp{m_dispatcher};
×
1188
        dropOnCableHandler(m_model, *cbl, disp);
×
1189
      }
×
1190
    }
×
1191
    m_dispatcher.commit<Process::MoveNodesMacro>();
2 ✔
1192
  }
2 ✔
1193
  else if(nodeSelectOnRelease)
1 ✔
1194
  {
1195
    Selection sel = filterSelections(
×
1196
        &m_model, m_context.selectionStack.currentSelection(), nodeSelectCumulation);
×
1197
    score::SelectionDispatcher{m_context.selectionStack}.select(sel);
×
1198
  }
×
1199
  nodeSelectOnRelease = false;
3 ✔
1200
  nodeDidMove = false;
3 ✔
1201
  event->accept();
3 ✔
1202
}
3 ✔
1203

1204
//! QEvent::UngrabMouse: the scene took the implicit grab away and there will be
1205
//! no release to end the drag on -- most visibly when the button was let go
1206
//! outside the window and the pointer then comes back in. Without this the
1207
//! MoveNodes command stays open, and the next drag of this node updates *it*
1208
//! instead of starting fresh, moving the node relative to the previous press.
1209
bool NodeItem::sceneEvent(QEvent* event)
8,997 ✔
1210
{
1211
  if(event->type() == QEvent::UngrabMouse)
8,997 ✔
1212
  {
1213
    if(nodeItemInteraction != Interaction::None)
2 ✔
1214
    {
1215
      clearDropCableHighlight();
2 ✔
1216
      if(nodeDidMove)
2 ✔
1217
        m_dispatcher.commit<Process::MoveNodesMacro>();
1 ✔
1218

1219
      nodeItemInteraction = Interaction::None;
2 ✔
1220
      nodeSelectOnRelease = false;
2 ✔
1221
      nodeDidMove = false;
2 ✔
1222
    }
2 ✔
1223
  }
2 ✔
1224
  return QGraphicsItem::sceneEvent(event);
8,997 ✔
1225
}
1226

1227
void NodeItem::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
×
1228
{
1229
  event->accept();
×
1230
}
×
1231

1232
void NodeItem::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
121 ✔
1233
{
1234
  if(m_presenter && isInSelectionCorner(event->pos(), m_contentRect))
121 ✔
1235
  {
1236
    auto& skin = score::Skin::instance();
×
1237
    setCursor(skin.CursorScaleFDiag);
×
1238
  }
×
1239
  else
1240
  {
1241
    unsetCursor();
121 ✔
1242
  }
1243

1244
  m_hover = true;
121 ✔
1245
  update();
121 ✔
1246
  event->accept();
121 ✔
1247
}
121 ✔
1248

1249
void NodeItem::hoverMoveEvent(QGraphicsSceneHoverEvent* event)
8,744 ✔
1250
{
1251
  if(m_presenter && isInSelectionCorner(event->pos(), m_contentRect))
8,744 ✔
1252
  {
1253
    auto& skin = score::Skin::instance();
×
1254
    setCursor(skin.CursorScaleFDiag);
×
1255
  }
×
1256
  else
1257
  {
1258
    unsetCursor();
8,744 ✔
1259
  }
1260
  event->accept();
8,744 ✔
1261
}
8,744 ✔
1262

1263
void NodeItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
119 ✔
1264
{
1265
  unsetCursor();
119 ✔
1266

1267
  m_hover = false;
119 ✔
1268
  update();
119 ✔
1269
  event->accept();
119 ✔
1270
}
119 ✔
1271

1272
void NodeItem::keyPressEvent(QKeyEvent* event)
×
1273
{
1274
  if(event->key() == Qt::Key_Down)
×
1275
  {
1276
    auto ports = Dataflow::getProcessPorts(this->m_model);
×
1277
    if(!ports.empty())
×
1278
    {
1279
      score::SelectionDispatcher disp{m_context.selectionStack};
×
1280
      disp.select(*ports.front());
×
1281
    }
×
1282
  }
×
1283
  event->accept();
×
1284
}
×
1285

1286
void NodeItem::keyReleaseEvent(QKeyEvent* event)
×
1287
{
1288
  event->accept();
×
1289
}
×
1290
void NodeItem::dragEnterEvent(QGraphicsSceneDragDropEvent* event)
×
1291
{
1292
  m_dropping = true;
×
1293
  event->accept();
×
1294
  update();
×
1295
}
×
1296

1297
void NodeItem::dragMoveEvent(QGraphicsSceneDragDropEvent* event)
×
1298
{
1299
  m_dropping = true;
×
1300
  event->accept();
×
1301
  update();
×
1302
}
×
1303

1304
void NodeItem::dragLeaveEvent(QGraphicsSceneDragDropEvent* event)
×
1305
{
1306
  m_dropping = false;
×
1307
  event->accept();
×
1308
  update();
×
1309
}
×
1310

1311
void NodeItem::dropEvent(QGraphicsSceneDragDropEvent* event)
×
1312
{
1313
  m_dropping = false;
×
1314
  event->accept();
×
1315
  dropReceived(event->pos(), *event->mimeData());
×
1316
  update();
×
1317
}
×
1318
}
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