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

ossia / score / 34039060546

06 Sep 2026 02:24PM UTC coverage: 26.369% (+1.8%) from 24.579%
34039060546

push

github

jcelerier
3rdparty: updat libossia

60871 of 230846 relevant lines covered (26.37%)

63602.32 hits per line

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

86.96
/src/plugins/score-lib-process/Process/Script/ScriptWidget.cpp
1
#include <Process/Script/ScriptWidget.hpp>
2

3
#include <score/application/GUIApplicationContext.hpp>
4
#include <score/tools/File.hpp>
5

6
#include <QCXXHighlighter>
7
#include <QCodeEditor>
8
#include <QFaustCompleter>
9
#include <QFaustHighlighter>
10
#include <QFile>
11
#include <QGLSLCompleter>
12
#include <QGLSLHighlighter>
13
#include <QJSCompleter>
14
#include <QJSHighlighter>
15
#include <QMainWindow>
16
#include <QRegularExpression>
17
#include <QSyntaxStyle>
18

19
namespace Process
20
{
21
namespace
22
{
23
void setTabWidth(QTextEdit& edit, int spaceCount)
132✔
24
{
25
  const QString spaces(spaceCount, QChar(' '));
132✔
26
  const QFontMetrics metrics(edit.font());
132✔
27
  edit.setTabStopDistance(metrics.horizontalAdvance(spaces));
132✔
28
}
132✔
29

30
std::pair<QStyleSyntaxHighlighter*, QCompleter*>
31
getLanguageStyle(const std::string_view language)
132✔
32
{
33
  if(language == "glsl" || language == "Glsl" || language == "GLSL")
132✔
34
  {
35
    return {new QGLSLHighlighter, new QGLSLCompleter};
×
36
  }
37
  else if(language == "js" || language == "Js" || language == "JS")
132✔
38
  {
39
    return {new QJSHighlighter, new QJSCompleter};
×
40
  }
41
  else if(language == "qml" || language == "Qml" || language == "QML")
132✔
42
  {
43
    return {new QJSHighlighter, new QJSCompleter};
132✔
44
  }
45
  else if(language == "faust" || language == "Faust")
×
46
  {
47
    return {new QFaustHighlighter, new QFaustCompleter};
×
48
  }
49
  else // C, C++, ...
50
  {
51
    return {new QCXXHighlighter, nullptr};
×
52
  }
53
}
132✔
54

55
}
56

57
static QByteArray themeSource()
2✔
58
{
59
  // A copy, not a mapping: the file is closed when this returns
60
  QFile fl(":/drakula.xml");
2✔
61
  if(fl.open(QIODevice::ReadOnly))
2✔
62
    return fl.readAll();
2✔
63
  qDebug() << "Could not load style:" << fl.fileName();
×
64
  return {};
×
65
}
2✔
66

67
QSyntaxStyle* scriptStyle()
148✔
68
{
69
  static bool tried_to_load = false;
70
  static QSyntaxStyle style;
148✔
71
  if(!tried_to_load)
148✔
72
  {
73
    if(const auto src = themeSource(); !src.isEmpty())
2✔
74
      style.load(src);
1✔
75
    tried_to_load = true;
1✔
76
  }
1✔
77
  return &style;
148✔
78
}
×
79

80
QSyntaxStyle* overlayScriptStyle()
20✔
81
{
82
  static bool tried_to_load = false;
83
  static QSyntaxStyle style;
20✔
84
  if(!tried_to_load)
20✔
85
  {
86
    if(auto src = QString::fromUtf8(themeSource()); !src.isEmpty())
2✔
87
    {
88
      // QColor reads #AARRGGBB: alpha 0 for the text background, which also
89
      // fills the line number area; 10% for the current line.
90
      static const QRegularExpression text{
2✔
91
          QStringLiteral(R"((name="Text"[^/>]*background=")#([0-9a-fA-F]{6}"))")};
1✔
92
      static const QRegularExpression currentLine{
2✔
93
          QStringLiteral(R"((name="CurrentLine"[^/>]*background=")#([0-9a-fA-F]{6}"))")};
1✔
94
      src.replace(text, QStringLiteral("\\1#00\\2"));
1✔
95
      src.replace(currentLine, QStringLiteral("\\1#1a\\2"));
1✔
96
      style.load(src);
1✔
97
    }
1✔
98
    tried_to_load = true;
1✔
99
  }
1✔
100
  return &style;
20✔
101
}
×
102

103
QTextEdit* createScriptWidget(const std::string_view language)
132✔
104
{
105
  auto edit = new QCodeEditor{};
132✔
106
  // px, not pt: pt would shrink on macOS' 72 DPI.
107
  auto font = QFont("IBM Plex Mono");
132✔
108
  font.setPixelSize(13);
132✔
109
  font.setFixedPitch(true);
132✔
110
  font.setStyleStrategy(QFont::PreferAntialias);
132✔
111
  font.setHintingPreference(QFont::HintingPreference::PreferVerticalHinting);
132✔
112

113
  edit->setFont(font);
132✔
114

115
  auto [highlight, complete] = getLanguageStyle(language);
264✔
116

117
  if(highlight)
132✔
118
  {
119
    edit->setHighlighter(highlight);
264✔
120
    highlight->setParent(edit);
132✔
121
  }
132✔
122
  if(complete)
132✔
123
  {
124
    edit->setCompleter(complete);
264✔
125
    complete->setParent(edit);
132✔
126
  }
132✔
127

128
  edit->setSyntaxStyle(scriptStyle());
132✔
129

130
  setTabWidth(*edit, 4);
132✔
131

132
  return edit;
132✔
133
}
132✔
134
}
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