• 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

82.35
/src/lib/score/graphics/GraphicsLayout.cpp
1
#include "GraphicsLayout.hpp"
2

3
#include <score/graphics/layouts/Constants.hpp>
4
#include <score/model/Skin.hpp>
5
#include <score/widgets/Pixmap.hpp>
6

7
#include <QPainter>
8

9
#include <vector>
10
namespace score
11
{
12

13
GraphicsLayout::GraphicsLayout(QGraphicsItem* parent)
25,380 ✔
14
    : score::BackgroundItem{parent}
25,380 ✔
15
    , m_bg{nullptr}
25,380 ✔
16
    , m_margin{default_margin}
17
    , m_padding{default_padding}
18
{
25,380 ✔
19
}
20

21
GraphicsLayout::~GraphicsLayout()
25,391 ✔
22
{
25,391 ✔
23
  delete m_pix;
25,380 ✔
24
}
25,391 ✔
25

26
void GraphicsLayout::layout()
11 ✔
27
{
28
  //fitChildrenRect();
29
}
11 ✔
30

31
void GraphicsLayout::centerContent() { }
3,408 ✔
32

33
void GraphicsLayout::setBrush(score::BrushSet& b)
7,064 ✔
34
{
35
  m_bg = &b;
7,064 ✔
36
}
7,064 ✔
37

38
void GraphicsLayout::setBackground(const QString& b)
×
39
{
40
  m_pix = new QPixmap{score::get_pixmap(":/plugins/" + b)};
×
41
}
×
42

43
void GraphicsLayout::setPadding(qreal p)
2,897 ✔
44
{
45
  m_padding = p;
2,897 ✔
46
}
2,897 ✔
47

48
void GraphicsLayout::setSpacing(qreal s)
2,894 ✔
49
{
50
  m_spacing = s;
2,894 ✔
51
}
2,894 ✔
52

53
qreal GraphicsLayout::spacing() const noexcept
28,041 ✔
54
{
55
  return m_spacing >= 0. ? m_spacing : 2. * m_padding;
28,041 ✔
56
}
57

58
void GraphicsLayout::setAlignment(Qt::Alignment a)
13 ✔
59
{
60
  m_alignment = a & Qt::AlignHorizontal_Mask;
13 ✔
61
}
13 ✔
62

63
qreal alignedOffset(Qt::Alignment a, qreal avail, qreal w) noexcept
70 ✔
64
{
65
  if(a & Qt::AlignHCenter)
70 ✔
66
    return (avail - w) / 2.;
10 ✔
67
  if(a & Qt::AlignRight)
60 ✔
68
    return avail - w;
8 ✔
69
  return 0.;
52 ✔
70
}
70 ✔
71

72
void GraphicsLayout::updateChildrenRects(const QList<QGraphicsItem*>& items)
26,218 ✔
73
{
74
  for(int i = 0; i < items.size(); i++)
89,280 ✔
75
  {
76
    // Empty: a spacer, keep its size
77
    if(auto rect = dynamic_cast<score::EmptyRectItem*>(items[i]);
126,124 ✔
78
       rect && !rect->childItems().isEmpty())
63,062 ✔
79
    {
80
      rect->fitChildrenRect();
37,961 ✔
81
    }
37,961 ✔
82
  }
63,062 ✔
83
}
26,218 ✔
84

85
void GraphicsLayout::setFitMargins(qreal right, qreal bottom)
20,648 ✔
86
{
87
  m_fitRight = right;
20,648 ✔
88
  m_fitBottom = bottom;
20,648 ✔
89
}
20,648 ✔
90

91
void GraphicsLayout::relayoutAround(QGraphicsItem* item)
161 ✔
92
{
93
  std::vector<GraphicsLayout*> layouts;
161 ✔
94
  for(auto* p = item->parentItem(); p; p = p->parentItem())
583 ✔
95
  {
96
    if(auto* lay = dynamic_cast<GraphicsLayout*>(p))
522 ✔
97
    {
98
      lay->layout();
311 ✔
99
      if(lay->m_fitRight >= 0.)
311 ✔
100
      {
101
        const auto& cld = lay->childrenBoundingRect();
301 ✔
102
        lay->setRect(
602 ✔
103
            QRectF{0., 0., cld.right() + lay->m_fitRight, cld.bottom() + lay->m_fitBottom});
301 ✔
104
      }
301 ✔
105
      layouts.push_back(lay);
311 ✔
106
    }
311 ✔
107
    else if(auto* rect = dynamic_cast<EmptyRectItem*>(p))
211 ✔
108
    {
109
      // A control's box: label, port and widget
110
      rect->fitChildrenRect();
111 ✔
111
    }
111 ✔
112
    else
113
    {
114
      break;
100 ✔
115
    }
116
  }
422 ✔
117

118
  for(auto* lay : layouts)
472 ✔
119
    lay->centerContent();
311 ✔
120
  if(!layouts.empty())
161 ✔
121
    layouts.back()->childrenSizeChanged();
111 ✔
122
}
161 ✔
123

124
void GraphicsLayout::setMargin(qreal p)
×
125
{
126
  m_margin = p;
×
127
}
×
128

129
void GraphicsLayout::paint(
25 ✔
130
    QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
131
{
132
  // painter->fillRect(boundingRect(), QColor(qRgb(127, 127, 160)));
133
  if(m_bg)
25 ✔
134
  {
135
    auto& style = score::Skin::instance();
×
136
    painter->setRenderHint(QPainter::Antialiasing, true);
×
137
    painter->setPen(style.NoPen);
×
138
    painter->setBrush(m_bg->brush);
×
139
    painter->drawRoundedRect(rect().adjusted(2., 2., -2., -2.), 3, 3);
×
140
    painter->setRenderHint(QPainter::Antialiasing, false);
×
141
  }
×
142
  else if(m_pix)
25 ✔
143
  {
144
    painter->drawPixmap(QPointF{}, *m_pix);
×
145
  }
×
146

147
  //painter->setBrush(Qt::transparent);
148
  //painter->setPen(Qt::red);
149
  //painter->drawRect(boundingRect());
150
  //painter->setPen(Qt::blue);
151
  //painter->drawRect(childrenBoundingRect());
152
}
25 ✔
153
}
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