Project
Loading...
Searching...
No Matches
GPUDisplayGUI.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#include "GPUDisplayGUI.h"
17
18#include <QButtonGroup>
19#include <QCheckBox>
20#include <QComboBox>
21#include <QFormLayout>
22#include <QGroupBox>
23#include <QGuiApplication>
24#include <QHash>
25#include <QHBoxLayout>
26#include <QApplication>
27#include <QKeyEvent>
28#include <QLabel>
29#include <QLayout>
30#include <QLineEdit>
31#include <QMouseEvent>
32#include <QPainter>
33#include <QPlainTextEdit>
34#include <QProxyStyle>
35#include <QPushButton>
36#include <QRadioButton>
37#include <QScrollArea>
38#include <QScreen>
39#include <QSignalBlocker>
40#include <QSlider>
41#include <QStyle>
42#include <QStyleHints>
43#include <QStatusBar>
44#include <QStyleOptionSizeGrip>
45#include <QStylePainter>
46#include <QVBoxLayout>
47#include <QWheelEvent>
48
49#include <algorithm>
50#include <chrono>
51#include <cmath>
52#include <functional>
53#include <memory>
54#include <numeric>
55#include <optional>
56#include <string>
57#include <variant>
58#include <vector>
59
60using namespace o2::gpu;
61
62namespace
63{
64class FlowLayout : public QLayout // Places the items in a row with their preferred width, and wraps into further rows at the right border (Qt has no such layout)
65{
66 public:
67 FlowLayout(QWidget* parent, int hSpacingFactor, bool equalRowHeight) : QLayout(parent), mHSpacingFactor(hSpacingFactor), mEqualRowHeight(equalRowHeight) {}
68 ~FlowLayout() override
69 {
70 while (QLayoutItem* item = takeAt(0)) {
71 delete item;
72 }
73 }
74 void addItem(QLayoutItem* item) override { mItems.append(item); }
75 int count() const override { return mItems.size(); }
76 QLayoutItem* itemAt(int index) const override { return mItems.value(index); }
77 QLayoutItem* takeAt(int index) override { return index >= 0 && index < mItems.size() ? mItems.takeAt(index) : nullptr; }
78 Qt::Orientations expandingDirections() const override { return {}; }
79 bool hasHeightForWidth() const override { return true; }
80 int heightForWidth(int width) const override { return doLayout(QRect(0, 0, width, 0), true); }
81 void setGeometry(const QRect& rect) override
82 {
83 QLayout::setGeometry(rect);
84 doLayout(rect, false);
85 }
86 QSize sizeHint() const override // All items in one row
87 {
88 QSize size(0, 0);
89 for (const QLayoutItem* item : mItems) {
90 size = QSize(size.width() + (size.width() ? hSpacing() : 0) + itemWidth(item), std::max(size.height(), item->sizeHint().height()));
91 }
92 const QMargins m = contentsMargins();
93 return size + QSize(m.left() + m.right(), m.top() + m.bottom());
94 }
95 QSize minimumSize() const override // Widest item, height for that width is given by heightForWidth
96 {
97 QSize size;
98 for (const QLayoutItem* item : mItems) {
99 size = size.expandedTo(item->minimumSize());
100 }
101 const QMargins m = contentsMargins();
102 return size + QSize(m.left() + m.right(), m.top() + m.bottom());
103 }
104 void setPreferredWidth(QWidget* widget, int width) { mPreferredWidth[widget] = width; } // Instead of the size hint of the widget
105
106 private:
107 int hSpacing() const { return mHSpacingFactor * spacing(); }
108 int itemWidth(const QLayoutItem* item) const { return mPreferredWidth.value(item->widget(), item->sizeHint().width()); }
109 int doLayout(const QRect& rect, bool testOnly) const // Returns the height needed
110 {
111 const QRect r = rect.marginsRemoved(contentsMargins());
112 int x = r.x(), y = r.y(), lineHeight = 0;
113 std::vector<std::pair<QLayoutItem*, QRect>> line; // Items of the current row, placed when the row is complete (height of the row known)
114 auto placeLine = [&]() {
115 if (!testOnly) {
116 for (auto& [item, geometry] : line) {
117 item->setGeometry(mEqualRowHeight ? QRect(geometry.x(), geometry.y(), geometry.width(), lineHeight) : geometry.translated(0, (lineHeight - geometry.height()) / 2)); // Otherwise vertically centered in the row
118 }
119 }
120 line.clear();
121 };
122 for (QLayoutItem* item : mItems) {
123 const int width = std::max(std::min(itemWidth(item), r.width()), item->minimumSize().width()); // Items wider than the layout get its width (at least their minimum), and wrap internally if they can
124 const int height = item->hasHeightForWidth() ? item->heightForWidth(width) : item->sizeHint().height();
125 if (x > r.x() && x + width > r.right() + 1) {
126 placeLine();
127 x = r.x();
128 y += lineHeight + spacing();
129 lineHeight = 0;
130 }
131 line.emplace_back(item, QRect(x, y, width, height));
132 x += width + hSpacing();
133 lineHeight = std::max(lineHeight, height);
134 }
135 placeLine();
136 return y + lineHeight - rect.y() + contentsMargins().bottom();
137 }
138 QList<QLayoutItem*> mItems;
139 QHash<const QWidget*, int> mPreferredWidth;
140 int mHSpacingFactor; // Horizontal spacing in units of spacing()
141 bool mEqualRowHeight; // All items of a row get the height of the highest one
142};
143class GUIStyle : public QProxyStyle // Tooltips only after hovering for 1.5 seconds, also directly after another tooltip
144{
145 public:
146 int styleHint(StyleHint hint, const QStyleOption* option, const QWidget* widget, QStyleHintReturn* returnData) const override
147 {
148 return hint == SH_ToolTip_WakeUpDelay ? 1500 : (hint == SH_ToolTip_FallAsleepDelay ? 0 : QProxyStyle::styleHint(hint, option, widget, returnData));
149 }
150};
151
152class ResizeGrip : public QWidget // Size grip in the bottom right corner of its parent, reports the new size while dragged (QSizeGrip resizes only windows)
153{
154 public:
155 ResizeGrip(QWidget* parent, std::function<void(QSize)> resize) : QWidget(parent), mResize(std::move(resize))
156 {
157 setCursor(Qt::SizeFDiagCursor);
158 setFixedSize(16, 16);
159 }
160
161 protected:
162 void paintEvent(QPaintEvent*) override
163 {
164 QStylePainter painter(this);
165 QStyleOptionSizeGrip opt;
166 opt.initFrom(this);
167 opt.corner = Qt::BottomRightCorner;
168 painter.drawControl(QStyle::CE_SizeGrip, opt);
169 }
170 void mousePressEvent(QMouseEvent* e) override
171 {
172 mStartPos = e->globalPosition().toPoint();
173 mStartSize = parentWidget()->size();
174 }
175 void mouseMoveEvent(QMouseEvent* e) override
176 {
177 if (e->buttons() & Qt::LeftButton) {
178 const QPoint d = e->globalPosition().toPoint() - mStartPos;
179 mResize(mStartSize + QSize(d.x(), d.y()));
180 }
181 }
182
183 private:
184 std::function<void(QSize)> mResize;
185 QPoint mStartPos;
186 QSize mStartSize;
187};
188
189class TextEdit : public QPlainTextEdit // Text edit with a resize grip, reports a changed text when it loses the focus
190{
191 public:
192 TextEdit(uint32_t lines, std::function<void(const QString&)> changed) : mChanged(std::move(changed)), mGrip(new ResizeGrip(this, [this](QSize size) {
193 mUnscaledSize = size.expandedTo(QSize(60, 30) * mScale) / mScale;
194 setScale(mScale);
195 }))
196 {
197 const int margins = 2 * (frameWidth() + std::lround(document()->documentMargin())) + 6; // Few more pixels, otherwise a scroll bar appears
198 mUnscaledSize = QSize(400, std::max<uint32_t>(lines, 1) * fontMetrics().lineSpacing() + margins);
199 }
200 QSize sizeHint() const override { return mPreferredSize; }
201 void setScale(float scale) // Fixed height, but narrower than preferred if the window is too small, so that it does not determine the width of the other elements
202 {
203 mScale = scale;
204 mPreferredSize = mUnscaledSize * scale;
205 setFixedHeight(mPreferredSize.height());
206 setMinimumWidth(std::min(mPreferredSize.width(), 100));
207 setMaximumWidth(mPreferredSize.width());
208 updateGeometry();
209 }
210 void showText(const QString& text) // Text from the display, not shown while the user edits
211 {
212 mCurrent = text;
213 if (!hasFocus() && toPlainText() != text) {
214 setPlainText(text);
215 document()->setModified(false);
216 }
217 }
218
219 protected:
220 void focusOutEvent(QFocusEvent* e) override
221 {
222 QPlainTextEdit::focusOutEvent(e);
223 if (document()->isModified()) {
224 document()->setModified(false);
225 mCurrent = toPlainText();
226 mChanged(mCurrent);
227 } else {
228 showText(mCurrent);
229 }
230 }
231 void resizeEvent(QResizeEvent* e) override
232 {
233 QPlainTextEdit::resizeEvent(e);
234 mGrip->move(width() - mGrip->width(), height() - mGrip->height());
235 mGrip->raise();
236 }
237
238 private:
239 std::function<void(const QString&)> mChanged;
240 QString mCurrent;
241 QSize mUnscaledSize; // At GUI scale 1, changed by the resize grip
242 QSize mPreferredSize;
243 float mScale = 1.f;
244 ResizeGrip* mGrip;
245};
246
247struct ValueEdit { // Text box for a value from the display, copied into the lambdas of the element
248 QLineEdit* edit = new QLineEdit;
249 std::shared_ptr<QString> current = std::make_shared<QString>(); // Restored when the text box is left without a valid new value
250
251 void show(const QString& text) const // Value from the display, not shown while the user edits
252 {
253 *current = text;
254 if (!edit->hasFocus()) {
255 edit->setText(text);
256 }
257 }
258 void commit(const QString& text) const // New value entered by the user, possibly corrected
259 {
260 *current = text;
261 edit->setText(text);
262 }
263 std::optional<QString> entered() const // Text if changed by the user, otherwise restores the current value
264 {
265 if (edit->isModified()) {
266 return edit->text();
267 }
268 edit->setText(*current);
269 return std::nullopt;
270 }
271 std::optional<double> number() const // Number if entered by the user, otherwise restores the current value
272 {
273 bool ok = false;
274 const double v = edit->text().toDouble(&ok);
275 if (edit->isModified() && ok && std::isfinite(v)) {
276 return v;
277 }
278 edit->setText(*current);
279 return std::nullopt;
280 }
281};
282
283class MultiSlider : public QWidget // Handles on one range [0, value.max] with ticks below: dragged with the mouse (multiples of step, never onto another handle), a click without moving (de)selects
284{
285 public:
286 explicit MultiSlider(double step) : mStep(step)
287 {
288 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
289 setFocusPolicy(Qt::ClickFocus); // A click finishes the editing in the text box first, for the previously focused handle
290 }
291 std::function<void()> changed; // Positions or selection changed by the user, value in the order received from the display
292 std::function<void()> focusChanged; // Other focused handle or its position, for the text box
293 GPUDisplayMultiSliderValue value; // Positions in the order of the display, selected handle
294 int32_t focused = -1; // Last clicked / dragged handle, shown in the text box
295
296 void setFromDisplay(const GPUDisplayMultiSliderValue& v)
297 {
298 value = v;
299 mDragging = -1; // A drag is cancelled by changes from the display
300 focused = focused < (int32_t)value.values.size() ? focused : -1;
301 update();
302 focusChanged();
303 }
304 void setPosition(int32_t i, double v) // From the text box, rounded to the step, ignored if the position does not change or another handle is there
305 {
306 v = snap(v);
307 if (isFree(v, -1)) { // Also the own position
308 value.values[i] = v;
309 sendAndNormalize();
310 }
311 }
312 QSize sizeHint() const override { return {300, handleHeight() + 6 + fontMetrics().height() + 8}; }
313 QSize minimumSizeHint() const override { return {100, sizeHint().height()}; }
314
315 protected:
316 void paintEvent(QPaintEvent*) override
317 {
318 QPainter p(this);
319 p.setRenderHint(QPainter::Antialiasing);
320 const QPalette& pal = palette();
321 const int32_t trackY = handleHeight() / 2 + 1, tickY = handleHeight() + 3;
322 p.setPen(QPen(pal.color(QPalette::Mid), 2));
323 p.drawLine(margin(), trackY, width() - margin(), trackY);
324 if (value.progress && value.values.size()) { // Up to the progress of the last position, e.g. the running animation
325 p.setPen(QPen(pal.color(QPalette::Highlight), 4));
326 p.drawLine(margin(), trackY, toX(value.progress / 65535. * value.values.back()), trackY);
327 }
328 p.setPen(pal.color(QPalette::WindowText));
329 const double tick = tickStep();
330 for (int32_t k = 0; k * tick <= maxValue() * (1 + 1e-9); k++) {
331 const int32_t x = toX(k * tick);
332 p.drawLine(x, tickY, x, tickY + 4);
333 p.drawText(QRect(x - 50, tickY + 5, 100, fontMetrics().height()), Qt::AlignHCenter | Qt::AlignTop, QString::number(k * tick));
334 }
335 for (uint32_t i = 0; i < value.values.size(); i++) {
336 const QRect r(toX(value.values[i]) - handleWidth() / 2, 1, handleWidth(), handleHeight());
337 p.setBrush((int32_t)i == value.selected ? pal.color(QPalette::Highlight) : pal.color(QPalette::Button));
338 p.setPen(QPen((int32_t)i == focused ? pal.color(QPalette::WindowText) : pal.color(QPalette::Mid), (int32_t)i == focused ? 2 : 1));
339 p.drawRoundedRect(r, 2, 2);
340 }
341 }
342 void mousePressEvent(QMouseEvent* e) override
343 {
344 if (e->button() != Qt::LeftButton) {
345 return;
346 }
347 int32_t best = -1, bestDistance = handleWidth();
348 for (uint32_t i = 0; i < value.values.size(); i++) { // Nearest handle under the mouse
349 if (const int32_t d = std::abs(toX(value.values[i]) - (int32_t)e->position().x()); d <= bestDistance) {
350 best = i;
351 bestDistance = d;
352 }
353 }
354 if (best >= 0) {
355 mDragging = focused = best;
356 mMoved = false;
357 update();
358 focusChanged();
359 }
360 }
361 void mouseMoveEvent(QMouseEvent* e) override
362 {
363 if (mDragging < 0) {
364 return;
365 }
366 const float v = snap(toValue(e->position().x())); // Compared to the stored float
367 if (isFree(v, mDragging) && v != value.values[mDragging]) { // Never onto another handle, it can be passed
368 value.values[mDragging] = v;
369 mMoved = true;
370 update();
371 focusChanged();
372 }
373 }
374 void mouseReleaseEvent(QMouseEvent* e) override
375 {
376 if (e->button() != Qt::LeftButton || mDragging < 0) {
377 return;
378 }
379 if (!mMoved) {
380 value.selected = value.selected == mDragging ? -1 : mDragging;
381 }
382 mDragging = -1;
383 sendAndNormalize();
384 }
385
386 private:
387 void sendAndNormalize() // Sends the value in the order of the display, then sorts it as the display does (first position 0), until its reply arrives
388 {
389 changed();
390 std::vector<uint32_t> order(value.values.size());
391 std::iota(order.begin(), order.end(), 0);
392 std::stable_sort(order.begin(), order.end(), [this](uint32_t a, uint32_t b) { return value.values[a] < value.values[b]; });
394 int32_t newFocused = -1;
395 for (uint32_t i = 0; i < order.size(); i++) {
396 sorted.values[i] = value.values[order[i]] - value.values[order[0]];
397 sorted.selected = (int32_t)order[i] == value.selected ? i : sorted.selected;
398 newFocused = (int32_t)order[i] == focused ? i : newFocused;
399 }
400 value = std::move(sorted);
401 focused = newFocused;
402 update();
403 focusChanged();
404 }
405 double maxValue() const { return std::max<double>(value.max, mStep); }
406 double snap(double v) const { return std::clamp(std::round(v / mStep) * mStep, 0., maxValue()); } // Positions are multiples of the step
407 bool isFree(double v, int32_t except) const // No handle other than except at v (positions are snapped: closer than half a step is the same position)
408 {
409 return std::none_of(value.values.begin(), value.values.end(), [&](const float& x) { return &x - value.values.data() != except && std::abs(x - v) < mStep / 2; });
410 }
411 int32_t handleHeight() const { return fontMetrics().height(); }
412 int32_t handleWidth() const { return std::max(6, fontMetrics().height() / 2); }
413 int32_t margin() const { return std::max(handleWidth() / 2 + 1, fontMetrics().horizontalAdvance("00.00") / 2); } // Room for the handles and tick labels at the ends
414 int32_t toX(double v) const { return margin() + std::lround(v / maxValue() * (width() - 2 * margin())); }
415 double toValue(double x) const { return (x - margin()) / std::max(1, width() - 2 * margin()) * maxValue(); }
416 double tickStep() const // 1, 2, 5 times a power of 10, labels not overlapping
417 {
418 const double minStep = maxValue() * 2 * fontMetrics().horizontalAdvance("00.00") / std::max(1, width() - 2 * margin());
419 const double base = std::pow(10., std::floor(std::log10(std::max(minStep, 1e-9))));
420 for (double m : {1., 2., 5.}) {
421 if (m * base >= minStep) {
422 return std::max(m * base, mStep);
423 }
424 }
425 return std::max(10 * base, mStep);
426 }
427
428 double mStep;
429 int32_t mDragging = -1;
430 bool mMoved = false;
431};
432
433struct SliderRange { // Slider positions of a range of values
434 static constexpr int32_t FLOAT_STEPS = 1000; // Resolution of sliders for floating point options
435 double min, step;
436 int32_t steps;
437 SliderRange(double minValue, double maxValue, bool isInteger, double fixedStep = 0) : min(minValue), step(fixedStep > 0 ? fixedStep : (isInteger ? 1. : (maxValue - minValue) / FLOAT_STEPS)), steps(fixedStep > 0 || isInteger ? std::max<int32_t>(std::lround((maxValue - minValue) / step), 0) : FLOAT_STEPS) {} // fixedStep: Element::step
438 double value(int32_t position) const { return min + position * step; }
439 int32_t position(double v) const { return step ? std::lround((v - min) / step) : 0; }
440};
441} // namespace
442
443static float clampScale(float scale) { return std::clamp(scale, 0.25f, 4.f); }
444
445static bool fixedLengthSlider(const GPUDisplayGUIChannel::Element& el) // Discrete / integer sliders with few steps, others stretch to the frame border
446{
447 static constexpr double MAX_FIXED_LENGTH_STEPS = 16;
448 return !el.dynamicOptions && (el.choices.size() || (el.isInteger && el.max - el.min <= MAX_FIXED_LENGTH_STEPS)); // Dynamic range: number of steps may change
449}
450
451static double toDouble(const GPUDisplayGUIValue& v)
452{
453 return std::visit([](const auto& x) -> double {
454 if constexpr (std::is_same_v<std::remove_cvref_t<decltype(x)>, std::string>) {
455 return QString::fromStdString(x).toDouble();
456 } else if constexpr (std::is_same_v<std::remove_cvref_t<decltype(x)>, GPUDisplayMultiSliderValue>) {
457 return 0.;
458 } else {
459 return x;
460 }
461 },
462 v);
463}
464
465static QString toQString(const GPUDisplayGUIValue& v)
466{
467 return std::visit([](const auto& x) {
468 if constexpr (std::is_same_v<std::remove_cvref_t<decltype(x)>, std::string>) {
469 return QString::fromStdString(x);
470 } else if constexpr (std::is_same_v<std::remove_cvref_t<decltype(x)>, GPUDisplayMultiSliderValue>) {
471 return QString();
472 } else {
473 return QString::number(x);
474 }
475 },
476 v);
477}
478
479static GPUDisplayGUIValue toValue(double v, bool isInteger) { return isInteger ? GPUDisplayGUIValue((int64_t)std::llround(v)) : GPUDisplayGUIValue(v); }
480
481static uint32_t nearestChoice(const std::vector<std::pair<std::string, GPUDisplayGUIValue>>& choices, double value) // For values not in the list
482{
483 uint32_t best = 0;
484 for (uint32_t i = 1; i < choices.size(); i++) {
485 if (std::abs(toDouble(choices[i].second) - value) < std::abs(toDouble(choices[best].second) - value)) {
486 best = i;
487 }
488 }
489 return best;
490}
491
492static bool sameValue(const GPUDisplayGUIValue& a, const GPUDisplayGUIValue& b) // Numbers compared by value, independent of int64_t / double
493{
494 const bool aNumber = std::holds_alternative<int64_t>(a) || std::holds_alternative<double>(a), bNumber = std::holds_alternative<int64_t>(b) || std::holds_alternative<double>(b);
495 return aNumber && bNumber ? toDouble(a) == toDouble(b) : a == b;
496}
497
498GPUDisplayGUI::GPUDisplayGUI(GPUDisplayGUIChannel& channel, QWidget* parent) : QMainWindow(parent), mChannel(channel)
499{
500 qApp->setStyle(new GUIStyle); // Owned by the application
501 resize(1370, 1210);
502 setMinimumSize(500, 500);
503 mStatusLabel = new QLabel;
504 mStatusLabel->setWordWrap(true);
505 mStatusLabel->hide();
506 statusBar()->addWidget(mStatusLabel, 1);
507 mDarkMode = darkPalette(); // System scheme, until the display tells otherwise
508 connect(QGuiApplication::styleHints(), &QStyleHints::colorSchemeChanged, this, &GPUDisplayGUI::colorSchemeChanged, Qt::QueuedConnection); // Queued: after the palette was updated
509 mInfoTextTimer.setSingleShot(true);
510 connect(&mInfoTextTimer, &QTimer::timeout, this, &GPUDisplayGUI::updateInfoLabels);
511 std::vector<GPUDisplayGUIChannel::Frame> layout;
512 {
513 std::lock_guard lock(mChannel.mutex);
514 setWindowTitle(QString::fromStdString(mChannel.windowName + " GUI"));
515 layout = mChannel.layout;
516 }
517 mBaseFontSize = font().pointSizeF() > 0 ? font().pointSizeF() : 10.f; // Fonts with pixel size have no point size
518 auto* content = new QWidget;
519 auto* contentLayout = new QVBoxLayout(content);
520 contentLayout->addWidget(buildElements(layout));
521 contentLayout->addStretch();
522 auto* scroll = new QScrollArea; // Vertical scroll bar if the frames do not fit into the window, they wrap to the window width
523 scroll->setWidgetResizable(true);
524 scroll->setFrameShape(QFrame::NoFrame);
525 scroll->setWidget(content);
526 setCentralWidget(scroll);
527 colorSchemeChanged(); // Style sheets, with the GUI scale, which comes from the display with the first state
528 qApp->installEventFilter(this); // Sliders / dropdowns would consume Ctrl + mouse wheel themselves
529 connect(&mTimer, &QTimer::timeout, this, &GPUDisplayGUI::timerTick);
530 mTimer.start(std::chrono::milliseconds(10));
531}
532
533void GPUDisplayGUI::timerTick()
534{
535 std::unique_lock lock(mChannel.mutex);
536 mChannel.guiSleeping = false;
537 if (mUpdate.empty()) { // Display processes the update we went to sleep with, wait for the reply (with new changes we would not apply it anyway)
538 mChannel.stateUpdated.wait_for(lock, mChannel.replyTimeout, [this] { return !mChannel.displayProcessingCurrentUpdate || mChannel.stop; });
539 }
540 if (!mUpdate.empty() && mLastSentId - mLastAppliedId >= mChannel.maxUpdatesAhead) { // Too far ahead of the display, wait for the reply to the last update
541 mChannel.stateUpdated.wait_for(lock, mChannel.replyTimeout, [this] { return mChannel.state.appliedUpdate == mLastSentId || mChannel.stop; });
542 }
543 if (mChannel.stop) {
544 lock.unlock();
545 close();
546 return;
547 }
548
549 const bool newState = mChannel.state.counter != mState.counter;
550 if (newState) {
551 mState = mChannel.state;
552 if (mState.appliedUpdate == mLastSentId) {
553 mLastAppliedId = mLastSentId;
554 }
555 }
556 std::vector<std::pair<uint32_t, GPUDisplayGUIChannel::Options>> options; // Read while the display waits, applied to the widgets after unlocking
557 if (mChannel.displayWaitingForOptions && mChannel.state.optionsRevision != mOptionsRevision) {
558 for (uint32_t id = 0; id < mElements.size(); id++) {
559 if (mElements[id].getOptions) {
560 options.emplace_back(id, mElements[id].getOptions());
561 }
562 }
563 mOptionsRevision = mChannel.optionsReadRevision = mChannel.state.optionsRevision;
564 mChannel.optionsRead.notify_all();
565 }
566 const bool apply = newState && mUpdate.empty() && mState.appliedUpdate == mLastSentId; // State contains all our updates, and we have no unsent changes
567 const bool post = !mUpdate.empty() && mLastSentId - mLastAppliedId < mChannel.maxUpdatesAhead;
568 if (post) {
569 if (mChannel.update) { // Previous update not yet picked up by the display, merge
570 mChannel.update->merge(mUpdate);
571 } else {
572 mChannel.update = std::move(mUpdate);
573 }
574 mChannel.update->id = ++mLastSentId;
575 mChannel.guiSleeping = true;
576 mUpdate = {};
577 }
578 lock.unlock();
579
580 if (post) {
581 mChannel.updatePosted();
582 }
583 if (newState) {
584 if (mState.cfg.mCfgO.guiDarkMode < 0) {
585 mUpdate.guiDarkMode = mDarkMode; // Report the system scheme, also shows up in the DarkMode checkbox
586 } else if ((mState.cfg.mCfgO.guiDarkMode != 0) != mDarkMode) {
587 setDarkMode(mState.cfg.mCfgO.guiDarkMode != 0);
588 }
589 if (mState.infoTextCounter != mInfoTextCounter) {
590 mInfoTextCounter = mState.infoTextCounter;
591 mInfoTextTimer.start(mChannel.infoTextTime);
592 }
593 updateInfoLabels();
594 }
595 for (const auto& [id, o] : options) { // New range / choices, then the current value again
596 mElements[id].setOptions(o);
597 mElements[id].applied.reset();
598 applyElement(mElements[id]);
599 }
600 if (apply) {
601 applySettings();
602 }
603}
604
605bool GPUDisplayGUI::darkPalette() const { return palette().window().color().lightness() < 128; }
606
607void GPUDisplayGUI::setDarkMode(bool dark)
608{
609#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
610 QGuiApplication::styleHints()->setColorScheme(dark ? Qt::ColorScheme::Dark : Qt::ColorScheme::Light); // No effect if the platform theme does not support it
611#endif
612 mDarkMode = dark;
613}
614
615void GPUDisplayGUI::colorSchemeChanged()
616{
617 setStyleSheet(QString()); // Otherwise the widgets keep their old palette
618 setScale(mScale); // Sets the style sheet again
619 updateInfoLabels();
620}
621
623{
624 QMainWindow::resizeEvent(event);
625 updateInfoLabels(); // Shows the GUI size
626}
627
628void GPUDisplayGUI::fitStatusLabel()
629{
630 mStatusLabel->setMinimumHeight(0); // heightForWidth of QLabel does not return less than the minimum height
631 mStatusLabel->setFixedHeight(mStatusLabel->heightForWidth(mStatusLabel->width()));
632}
633
634void GPUDisplayGUI::updateInfoLabels()
635{
636 const QString status = QString::fromStdString(mState.infoStatus) + QString(" GUI %1x%2").arg(width()).arg(height());
637 if (mInfoTextTimer.isActive() && !mState.infoText.empty()) { // Info message for some seconds, in bold and color, in the same line
638 const char* color = darkPalette() ? "lightblue" : "darkblue";
639 mStatusLabel->setTextFormat(Qt::RichText);
640 mStatusLabel->setText("<span style=\"white-space: pre-wrap;\">" + status.toHtmlEscaped() + QString("</span> - <span style=\"font-weight: bold; color: %1;\">%2</span>").arg(color, QString::fromStdString(mState.infoText).toHtmlEscaped()));
641 } else {
642 mStatusLabel->setTextFormat(Qt::PlainText);
643 mStatusLabel->setText(status);
644 }
645 mStatusLabel->setVisible(!mState.infoStatus.empty());
646 fitStatusLabel();
647}
648
649void GPUDisplayGUI::applySettings()
650{
651 if (clampScale(mState.cfg.mCfgO.guiScale) != mScale) { // Changed by the display (Reset GUI button, console) or from a previous GUI session, clamped as by setScale
652 setScale(mState.cfg.mCfgO.guiScale);
653 }
654 for (auto& element : mElements) {
655 applyElement(element);
656 }
657}
658
659void GPUDisplayGUI::applyElement(GUIElement& element)
660{
661 if (!element.set) {
662 return;
663 }
664 GPUDisplayGUIValue value = element.get(mState.cfg);
665 if (element.applied != value) {
666 element.set(value);
667 element.applied = std::move(value);
668 }
669}
670
671void GPUDisplayGUI::setValue(uint32_t id, GPUDisplayGUIValue value)
672{
673 mUpdate.setValue(id, std::move(value));
674 mElements[id].applied.reset();
675}
676
677GPUDisplayGUI::ElementWidget GPUDisplayGUI::createCheckbox(const GPUDisplayGUIChannel::Element& el)
678{
679 auto* w = new QCheckBox(QString::fromStdString(el.name)); // Own text instead of a label
680 connect(w, &QCheckBox::toggled, this, [this, id = el.id](bool v) { setValue(id, (int64_t)v); });
681 return {w, [w](const GPUDisplayGUIValue& v) { const QSignalBlocker blocker(w); w->setChecked(toDouble(v) != 0.); }, {}};
682}
683
684GPUDisplayGUI::ElementWidget GPUDisplayGUI::createTextbox(const GPUDisplayGUIChannel::Element& el)
685{
686 ValueEdit text;
687 connect(text.edit, &QLineEdit::editingFinished, this, [this, text, id = el.id, isInteger = el.isInteger, isString = el.isString, hasRange = el.hasRange, min = el.min, max = el.max]() {
688 if (isString) {
689 if (const auto str = text.entered()) {
690 text.commit(*str);
691 setValue(id, str->toStdString());
692 }
693 } else if (const auto entered = text.number()) {
694 const GPUDisplayGUIValue v = toValue(hasRange ? std::clamp(*entered, min, max) : *entered, isInteger);
695 text.commit(toQString(v)); // Show the value actually set, the display state does not overwrite the focused field
696 setValue(id, v);
697 }
698 });
699 return {text.edit, [text](const GPUDisplayGUIValue& v) { text.show(toQString(v)); }, {}};
700}
701
702QHBoxLayout* GPUDisplayGUI::createSliderRow(ElementWidget& retVal, QWidget* slider, QLineEdit* edit, Qt::Alignment editAlignment)
703{
704 retVal.widget = new QWidget;
705 auto* row = new QHBoxLayout(retVal.widget);
706 row->setContentsMargins(0, 0, 0, 0);
707 mScaleSetters.emplace_back([edit](float scale) { edit->setFixedWidth(std::lround(60 * scale)); });
708 row->addWidget(slider);
709 row->addWidget(edit, 0, editAlignment);
710 return row;
711}
712
713GPUDisplayGUI::ElementWidget GPUDisplayGUI::createSlider(const GPUDisplayGUIChannel::Element& el)
714{
715 ElementWidget retVal;
716 auto* slider = new QSlider(Qt::Horizontal);
717 ValueEdit text;
718 auto* row = createSliderRow(retVal, slider, text.edit);
719 const bool fixedLength = fixedLengthSlider(el);
720 const int32_t length = fixedLength ? (el.choices.size() ? el.choices.size() - 1 : std::lround(el.max - el.min)) * 2 * style()->pixelMetric(QStyle::PM_IndicatorWidth) : 150; // Fixed: about twice a checkbox indicator per step
721 mScaleSetters.emplace_back([slider, length, fixedLength](float scale) {
722 if (fixedLength) {
723 slider->setFixedWidth(std::lround(length * scale));
724 } else {
725 slider->setMinimumWidth(std::lround(length * scale));
726 }
727 });
728 if (fixedLength) {
729 row->addStretch(); // Left-aligned, otherwise the free space is distributed around the fixed-size widgets
730 }
731 if (el.choices.size()) { // Positions are the indices of the choices
732 auto choices = std::make_shared<const std::vector<std::pair<std::string, GPUDisplayGUIValue>>>(el.choices);
733 slider->setRange(0, choices->size() - 1);
734 connect(slider, &QSlider::valueChanged, this, [this, text, id = el.id, choices](int32_t pos) {
735 text.show(QString::fromStdString((*choices)[pos].first));
736 setValue(id, (*choices)[pos].second);
737 });
738 connect(text.edit, &QLineEdit::editingFinished, this, [this, text, slider, id = el.id, choices]() {
739 if (const auto entered = text.number()) {
740 const uint32_t pos = nearestChoice(*choices, *entered);
741 text.commit(QString::fromStdString((*choices)[pos].first));
742 const QSignalBlocker blocker(slider);
743 slider->setValue(pos);
744 setValue(id, (*choices)[pos].second);
745 }
746 });
747 retVal.set = [slider, text, choices](const GPUDisplayGUIValue& value) {
748 const uint32_t best = nearestChoice(*choices, toDouble(value));
749 const QSignalBlocker blocker(slider);
750 slider->setValue(best);
751 text.show(sameValue((*choices)[best].second, value) ? QString::fromStdString((*choices)[best].first) : toQString(value));
752 };
753 } else {
754 auto range = std::make_shared<SliderRange>(el.min, el.max, el.isInteger, el.step); // Changed by dynamic options
755 slider->setRange(0, range->steps);
756 connect(slider, &QSlider::valueChanged, this, [this, text, id = el.id, range, isInteger = el.isInteger](int32_t pos) {
757 const GPUDisplayGUIValue v = toValue(range->value(pos), isInteger);
758 text.show(toQString(v));
759 setValue(id, v);
760 });
761 connect(text.edit, &QLineEdit::editingFinished, this, [this, text, slider, id = el.id, range, isInteger = el.isInteger, step = el.step]() {
762 if (const auto entered = text.number()) {
763 const double clamped = std::clamp(*entered, range->min, range->value(range->steps));
764 const GPUDisplayGUIValue v = toValue(step > 0 ? range->value(range->position(clamped)) : clamped, isInteger); // Rounded to the step if set, otherwise floating point values need not be on a slider step
765 text.commit(toQString(v));
766 const QSignalBlocker blocker(slider);
767 slider->setValue(range->position(toDouble(v)));
768 setValue(id, v);
769 }
770 });
771 retVal.set = [slider, text, range](const GPUDisplayGUIValue& value) {
772 const QSignalBlocker blocker(slider);
773 slider->setValue(range->position(toDouble(value)));
774 text.show(toQString(value));
775 };
776 retVal.setOptions = [slider, range, isInteger = el.isInteger, step = el.step](const GPUDisplayGUIChannel::Options& o) {
777 *range = SliderRange(o.min, o.max, isInteger, step);
778 const QSignalBlocker blocker(slider);
779 slider->setRange(0, range->steps);
780 };
781 }
782 return retVal;
783}
784
785GPUDisplayGUI::ElementWidget GPUDisplayGUI::createMultiSlider(const GPUDisplayGUIChannel::Element& el)
786{
787 ElementWidget retVal;
788 auto* slider = new MultiSlider(el.step);
789 ValueEdit text;
790 createSliderRow(retVal, slider, text.edit, Qt::AlignTop);
791 mScaleSetters.emplace_back([slider](float scale) { slider->setMinimumWidth(std::lround(300 * scale)); });
792 slider->changed = [this, slider, id = el.id]() { setValue(id, slider->value); };
793 auto focusedText = [slider]() { return slider->focused >= 0 ? QString::number(slider->value.values[slider->focused]) : QString(); };
794 slider->focusChanged = [text, focusedText]() { text.show(focusedText()); };
795 connect(text.edit, &QLineEdit::editingFinished, this, [slider, text, focusedText]() {
796 if (const auto entered = text.number(); entered && slider->focused >= 0) {
797 slider->setPosition(slider->focused, *entered);
798 }
799 text.commit(focusedText()); // The position actually set, also after the normalization
800 });
801 retVal.set = [slider](const GPUDisplayGUIValue& v) { slider->setFromDisplay(std::get<GPUDisplayMultiSliderValue>(v)); };
802 return retVal;
803}
804
805GPUDisplayGUI::ElementWidget GPUDisplayGUI::createRadioButtons(const GPUDisplayGUIChannel::Element& el)
806{
807 auto* widget = new QWidget;
808 auto* row = new QHBoxLayout(widget);
809 row->setContentsMargins(0, 0, 0, 0);
810 auto* group = new QButtonGroup(widget);
811 for (uint32_t i = 0; i < el.choices.size(); i++) {
812 auto* button = new QRadioButton(QString::fromStdString(el.choices[i].first));
813 group->addButton(button, i);
814 row->addWidget(button);
815 }
816 connect(group, &QButtonGroup::idClicked, this, [this, id = el.id, choices = el.choices](int32_t i) { setValue(id, choices[i].second); }); // idClicked only on user clicks
817 return {widget, [group, choices = el.choices](const GPUDisplayGUIValue& v) {
818 for (uint32_t i = 0; i < choices.size(); i++) {
819 if (sameValue(choices[i].second, v)) {
820 group->button(i)->setChecked(true);
821 }
822 }
823 },
824 {}};
825}
826
827GPUDisplayGUI::ElementWidget GPUDisplayGUI::createTextEdit(const GPUDisplayGUIChannel::Element& el)
828{
829 auto* w = new TextEdit(el.lines, [this, id = el.id](const QString& text) { setValue(id, text.toStdString()); });
830 mScaleSetters.emplace_back([w](float scale) { w->setScale(scale); });
831 return {w, [w](const GPUDisplayGUIValue& v) { w->showText(toQString(v)); }, {}};
832}
833
834GPUDisplayGUI::ElementWidget GPUDisplayGUI::createButton(const GPUDisplayGUIChannel::Element& el) // No value from the display
835{
836 auto* w = new QPushButton(QString::fromStdString(el.name));
837 connect(w, &QPushButton::clicked, this, [this, id = el.id]() { setValue(id, (int64_t)1); });
838 return {w, {}, {}};
839}
840
841GPUDisplayGUI::ElementWidget GPUDisplayGUI::createDropdown(const GPUDisplayGUIChannel::Element& el)
842{
843 auto* w = new QComboBox;
844 auto choices = std::make_shared<std::vector<std::pair<std::string, GPUDisplayGUIValue>>>(el.choices); // Changed by dynamic options
845 for (const auto& choice : *choices) {
846 w->addItem(QString::fromStdString(choice.first));
847 }
848 connect(w, &QComboBox::currentIndexChanged, this, [this, id = el.id, choices](int32_t i) {
849 if (i >= 0 && i < (int32_t)choices->size()) {
850 setValue(id, (*choices)[i].second);
851 }
852 });
853 return {w, [w, choices](const GPUDisplayGUIValue& v) {
854 const QSignalBlocker blocker(w);
855 for (uint32_t i = 0; i < choices->size(); i++) {
856 if (sameValue((*choices)[i].second, v)) {
857 w->setCurrentIndex(i);
858 }
859 } },
860 [w, choices](const GPUDisplayGUIChannel::Options& o) {
861 *choices = o.choices;
862 const QSignalBlocker blocker(w);
863 w->clear();
864 for (const auto& choice : *choices) {
865 w->addItem(QString::fromStdString(choice.first));
866 }
867 }};
868}
869
870QWidget* GPUDisplayGUI::buildElements(const std::vector<GPUDisplayGUIChannel::Frame>& layout)
871{
873 auto* frames = new QWidget; // Frames with their natural width, next to each other while they fit into the window
874 auto* framesLayout = new FlowLayout(frames, 1, true);
875 framesLayout->setContentsMargins(0, 0, 0, 0);
876 for (const auto& frame : layout) {
877 auto* box = new QGroupBox(QString::fromStdString(frame.description));
878 if (frame.description.empty()) {
879 box->setStyleSheet("QGroupBox { margin-top: 0; }"); // No space for a title
880 }
881 auto* boxLayout = new QVBoxLayout(box);
882 QLayout* section = nullptr; // Consecutive elements with the same alignment
883 bool sectionHorizontal = false;
884 for (const auto& el : frame.elements) {
885 ElementWidget created;
886 switch (el.type) {
887 case Type::CHECKBOX:
888 created = createCheckbox(el);
889 break;
890 case Type::TEXTBOX:
891 created = createTextbox(el);
892 break;
893 case Type::SLIDER:
894 created = createSlider(el);
895 break;
896 case Type::RADIO_BUTTONS:
897 created = createRadioButtons(el);
898 break;
899 case Type::TEXTEDIT:
900 created = createTextEdit(el);
901 break;
902 case Type::BUTTON:
903 created = createButton(el);
904 break;
905 case Type::DROPDOWN:
906 created = createDropdown(el);
907 break;
908 case Type::MULTI_SLIDER:
909 created = createMultiSlider(el);
910 break;
911 }
912 QWidget* widget = created.widget;
913 QLabel* name = el.type == Type::CHECKBOX || el.type == Type::BUTTON || el.name.empty() ? nullptr : new QLabel(QString::fromStdString(el.name)); // Checkboxes and buttons show their own text, an empty name means no caption
914 widget->setToolTip(QString::fromStdString(el.description));
915 if (name) {
916 name->setToolTip(widget->toolTip());
917 }
918 if (!section || el.horizontal != sectionHorizontal) {
919 sectionHorizontal = el.horizontal;
920 if (sectionHorizontal) {
921 section = new FlowLayout(nullptr, 3, false); // More space between the elements than between the rows
922 } else {
923 auto* form = new QFormLayout;
924 form->setLabelAlignment(Qt::AlignLeft | Qt::AlignVCenter); // Set explicitly, the defaults depend on the style: e.g. Breeze centers the form and aligns labels right
925 form->setFormAlignment(Qt::AlignLeft | Qt::AlignTop);
926 form->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
927 form->setRowWrapPolicy(QFormLayout::DontWrapRows);
928 section = form;
929 }
930 section->setContentsMargins(0, 0, 0, 0);
931 boxLayout->addLayout(section);
932 }
933 if (!sectionHorizontal) {
934 name ? ((QFormLayout*)section)->addRow(name, widget) : ((QFormLayout*)section)->addRow(widget);
935 } else if (name) { // Label and element as one item of the flow layout
936 auto* item = new QWidget;
937 auto* row = new QHBoxLayout(item);
938 row->setContentsMargins(0, 0, 0, 0);
939 row->addWidget(name);
940 row->addWidget(widget);
941 section->addWidget(item);
942 } else {
943 section->addWidget(widget);
944 }
945 mElements.push_back({std::move(created.set), std::move(created.setOptions), el.get, el.dynamicOptions, std::nullopt}); // Element ids are sequential
946 }
947 framesLayout->addWidget(box);
948 if (std::any_of(frame.elements.begin(), frame.elements.end(), [](const auto& el) { return (el.type == Type::SLIDER && !fixedLengthSlider(el)) || el.type == Type::MULTI_SLIDER; })) { // Sliders range to the frame border, frame limited to the window width by the layout
949 mScaleSetters.emplace_back([this, framesLayout, box](float scale) { framesLayout->setPreferredWidth(box, std::lround(screen()->availableGeometry().width() / 3 * scale)); });
950 }
951 }
952 mScaleSetters.emplace_back([framesLayout](float) { framesLayout->invalidate(); });
953 return frames;
954}
955
956void GPUDisplayGUI::setScale(float scale)
957{
958 mScale = clampScale(scale);
959 for (const auto& setter : mScaleSetters) {
960 setter(mScale);
961 }
962 const int indicator = std::lround(style()->pixelMetric(QStyle::PM_IndicatorWidth) * mScale);
963 setStyleSheet(QString("QGroupBox { border: 1px solid palette(mid); border-radius: 3px; margin-top: 0.6em; padding-top: 0.3em; }"
964 "QGroupBox::title { subcontrol-origin: margin; left: 8px; padding: 0 3px; }" // Title on the frame border instead of in an extra line above
965 "QCheckBox::indicator, QRadioButton::indicator { width: %1px; height: %1px; }"
966 "QWidget { font-size: %2pt; }") // Style sheet, since setFont() does not override the fonts the platform theme sets for some classes (QLabel, QPushButton), sizes derived from the text follow
967 .arg(indicator)
968 .arg(mBaseFontSize * mScale, 0, 'f', 1));
969}
970
971bool GPUDisplayGUI::eventFilter(QObject* watched, QEvent* event)
972{
973 const auto* w = qobject_cast<QWidget*>(watched);
974 if (!w || w->window() != this) {
975 return false;
976 }
977 if (watched == mStatusLabel && event->type() == QEvent::Resize) {
978 fitStatusLabel();
979 return false;
980 }
981 if (event->type() == QEvent::Wheel && (static_cast<QWheelEvent*>(event)->modifiers() & Qt::ControlModifier)) {
982 const int delta = static_cast<QWheelEvent*>(event)->angleDelta().y(); // 120 per notch
983 if (delta) {
984 setScale(mScale * std::pow(1.1f, delta / 120.f));
985 mUpdate.guiScale = mScale;
986 }
987 return true;
988 }
989 if (event->type() == QEvent::KeyPress && static_cast<QKeyEvent*>(event)->key() == Qt::Key_0 && (static_cast<QKeyEvent*>(event)->modifiers() & Qt::ControlModifier)) {
990 setScale(1.f);
991 mUpdate.guiScale = mScale;
992 return true;
993 }
994 return false;
995}
996
998{
999 setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
1000 show();
1001 raise();
1002 activateWindow();
1003}
1004
1006{
1007 const int32_t key = translateKey(event);
1008 if (key < 0) {
1009 QMainWindow::keyPressEvent(event);
1010 return;
1011 }
1012 mUpdate.keys.emplace_back(key);
1013}
1014
1015int32_t GPUDisplayGUI::translateKey(const QKeyEvent* event)
1016{
1017#ifdef Q_OS_WIN
1018 if (event->nativeScanCode() == 0x29) { // Key left of 1: console key (^), independent of the layout
1019#else
1020 if (event->nativeScanCode() == 49) { // Key left of 1 (XKB keycode): console key (^), independent of the layout
1021#endif
1022 return '^';
1023 }
1024 switch (event->key()) {
1025 case Qt::Key_Up:
1026 return GPUDisplayFrontendKeyVars::KEY_UP;
1027 case Qt::Key_Down:
1028 return GPUDisplayFrontendKeyVars::KEY_DOWN;
1029 case Qt::Key_Left:
1030 return GPUDisplayFrontendKeyVars::KEY_LEFT;
1031 case Qt::Key_Right:
1032 return GPUDisplayFrontendKeyVars::KEY_RIGHT;
1033 case Qt::Key_PageUp:
1034 return GPUDisplayFrontendKeyVars::KEY_PAGEUP;
1035 case Qt::Key_PageDown:
1036 return GPUDisplayFrontendKeyVars::KEY_PAGEDOWN;
1037 case Qt::Key_Home:
1038 return GPUDisplayFrontendKeyVars::KEY_HOME;
1039 case Qt::Key_End:
1040 return GPUDisplayFrontendKeyVars::KEY_END;
1041 case Qt::Key_Insert:
1042 return GPUDisplayFrontendKeyVars::KEY_INSERT;
1043 case Qt::Key_Escape:
1044 return GPUDisplayFrontendKeyVars::KEY_ESCAPE;
1045 case Qt::Key_Backspace:
1046 return GPUDisplayFrontendKeyVars::KEY_BACKSPACE;
1047 case Qt::Key_Delete:
1048 return GPUDisplayFrontendKeyVars::KEY_DELETE;
1049 case Qt::Key_Return:
1050 case Qt::Key_Enter:
1051 return GPUDisplayFrontendKeyVars::KEY_ENTER;
1052 default:
1053 break;
1054 }
1055 if (event->key() >= Qt::Key_F1 && event->key() <= Qt::Key_F12) {
1056 static_assert(GPUDisplayFrontendKeyVars::KEY_F12 - GPUDisplayFrontendKeyVars::KEY_F1 == Qt::Key_F12 - Qt::Key_F1);
1057 return GPUDisplayFrontendKeyVars::KEY_F1 + (event->key() - Qt::Key_F1);
1058 }
1059 const QString text = event->text();
1060 if (text.size() == 1 && text[0].unicode() >= 32 && text[0].unicode() < 127) { // Printable ASCII, with shift applied
1061 return text[0].unicode();
1062 }
1063 return -1;
1064}
bool isString(TDataMember const &dm)
atype::type element
int32_t i
int32_t retVal
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time frames(excluding borders)") AddOption(eventStride
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events d
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc Replace constant variables static by constexpr expressions Compile RTC in deterministic with NO_FAST_MATH flags and GPUCA_DETERMINISTIC_MODE define Use RTC to optimize GPU code h configStandalone Processing proc_rtctech Use a file lock to serialize access to the cache folder int32_t
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc Replace constant variables static by constexpr expressions Compile RTC in deterministic with NO_FAST_MATH flags and GPUCA_DETERMINISTIC_MODE define Use RTC to optimize GPU code h configStandalone Processing proc_rtctech Use a file lock to serialize access to the cache folder Print launch bounds used for RTC code as debugging option
uint16_t pos
Definition RawData.h:3
Acts::Vector3 position
StringRef key
void keyPressEvent(QKeyEvent *event) override
void resizeEvent(QResizeEvent *event) override
bool eventFilter(QObject *watched, QEvent *event) override
GPUDisplayGUI(GPUDisplayGUIChannel &channel, QWidget *parent=nullptr)
struct _cl_event * event
Definition glcorearb.h:2982
GLint GLenum GLint x
Definition glcorearb.h:403
const GLfloat * m
Definition glcorearb.h:4066
GLint GLsizei count
Definition glcorearb.h:399
GLsizeiptr size
Definition glcorearb.h:659
const GLdouble * v
Definition glcorearb.h:832
GLuint const GLchar * name
Definition glcorearb.h:781
GLintptr GLsizeiptr GLboolean commit
Definition glcorearb.h:3613
GLint GLsizei GLsizei height
Definition glcorearb.h:270
GLint first
Definition glcorearb.h:399
GLint GLsizei width
Definition glcorearb.h:270
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLenum GLint * range
Definition glcorearb.h:1899
GLint y
Definition glcorearb.h:270
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLboolean GLuint group
Definition glcorearb.h:3991
GLuint GLsizei GLsizei * length
Definition glcorearb.h:790
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLboolean r
Definition glcorearb.h:1233
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
GLubyte GLubyte GLubyte GLubyte w
Definition glcorearb.h:852
GLuint id
Definition glcorearb.h:650
GLsizei const GLint * box
Definition glcorearb.h:4697
std::string show(const DeliveryType type)
int32_t const char int32_t line
std::variant< int64_t, double, std::string, GPUDisplayMultiSliderValue > GPUDisplayGUIValue
const bool const bool const int FollowDirection BestTrial TrackITSInternal< NLayers > & best
if(!okForPhiMin(phi0, phi1))
return * this
value_T step
Definition TrackUtils.h:42
Drawing helper functions.
std::function< GPUDisplayGUIValue(const Settings &)> get
std::vector< std::pair< std::string, GPUDisplayGUIValue > > choices
std::function< void()> updatePosted
std::chrono::milliseconds replyTimeout
std::chrono::milliseconds infoTextTime
std::condition_variable stateUpdated
std::condition_variable optionsRead
std::optional< float > guiScale
void setValue(uint32_t element, GPUDisplayGUIValue value)
std::optional< int8_t > guiDarkMode
constexpr size_t min
constexpr size_t max
std::vector< int > row
pedsdata resize(norbits)