Skip to content

Commit 3afbc90

Browse files
committed
GPU Display GUI: Get rid of Qt ui file, since all elements are created dynamically
1 parent 73dcdd6 commit 3afbc90

4 files changed

Lines changed: 33 additions & 69 deletions

File tree

‎GPU/GPUTracking/display/CMakeLists.txt‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,10 @@ if(GLFW_FOUND)
186186
endif()
187187

188188
if(GPUCA_EVENT_DISPLAY_QT)
189-
qt_wrap_cpp(GPUCA_QT_MOC_SRCS frontend/GPUDisplayGUI.h) # Explicit moc / uic instead of AUTOMOC / AUTOUIC: rerun only if these files change; add new Q_OBJECT headers / .ui files here
190-
qt_wrap_ui(GPUCA_QT_UI_HDRS frontend/GPUDisplayGUI.ui)
189+
qt_wrap_cpp(GPUCA_QT_MOC_SRCS frontend/GPUDisplayGUI.h) # Explicit moc instead of AUTOMOC: rerun only if these files change; add new Q_OBJECT headers here
191190

192191
set(SRCS ${SRCS} frontend/GPUDisplayGUI.cxx frontend/GPUDisplayGUIWrapper.cxx)
193-
set(SRCS_NO_H ${SRCS_NO_H} ${GPUCA_QT_MOC_SRCS} ${GPUCA_QT_UI_HDRS})
192+
set(SRCS_NO_H ${SRCS_NO_H} ${GPUCA_QT_MOC_SRCS})
194193
set(HDRS_INSTALL ${HDRS_INSTALL} frontend/GPUDisplayGUIChannel.h)
195194
endif()
196195

@@ -315,7 +314,6 @@ endif()
315314
if(GPUCA_EVENT_DISPLAY_QT)
316315
target_compile_definitions(${targetName} PRIVATE GPUCA_BUILD_EVENT_DISPLAY_QT)
317316
target_link_libraries(${targetName} PRIVATE Qt6::Widgets)
318-
target_include_directories(${targetName} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) # ui_*.h
319317
endif()
320318

321319
target_link_libraries(${targetName} PRIVATE TBB::tbb)

‎GPU/GPUTracking/display/frontend/GPUDisplayGUI.cxx‎

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#include "GPUDisplayGUI.h"
1616
#include "GPUDisplayFrontend.h"
17-
#include "ui_GPUDisplayGUI.h"
1817

1918
#include <QButtonGroup>
2019
#include <QCheckBox>
@@ -40,6 +39,7 @@
4039
#include <QSlider>
4140
#include <QStyle>
4241
#include <QStyleHints>
42+
#include <QStatusBar>
4343
#include <QStyleOptionSizeGrip>
4444
#include <QStylePainter>
4545
#include <QVBoxLayout>
@@ -338,45 +338,41 @@ static bool sameValue(const GPUDisplayGUIValue& a, const GPUDisplayGUIValue& b)
338338
return aString || bString ? a == b : toDouble(a) == toDouble(b);
339339
}
340340

341-
GPUDisplayGUI::GPUDisplayGUI(GPUDisplayGUIChannel& channel, QWidget* parent) : QMainWindow(parent), mUi(std::make_unique<Ui::GPUDisplayGUI>()), mChannel(channel)
341+
GPUDisplayGUI::GPUDisplayGUI(GPUDisplayGUIChannel& channel, QWidget* parent) : QMainWindow(parent), mChannel(channel)
342342
{
343343
qApp->setStyle(new GUIStyle); // Owned by the application
344-
mUi->setupUi(this);
345-
auto* scroll = new QScrollArea; // Vertical scroll bar if the frames do not fit into the window, they wrap to the window width
346-
scroll->setWidgetResizable(true);
347-
scroll->setFrameShape(QFrame::NoFrame);
348-
scroll->setWidget(takeCentralWidget());
349-
auto* central = new QWidget;
350-
auto* centralLayout = new QVBoxLayout(central);
351-
centralLayout->setContentsMargins(0, 0, 0, 0);
352-
centralLayout->setSpacing(0);
353-
centralLayout->addWidget(scroll, 1);
344+
resize(1370, 1210);
345+
setMinimumSize(500, 500);
354346
mStatusLabel = new QLabel;
355347
mStatusLabel->setWordWrap(true);
356348
mStatusLabel->hide();
357-
mStatusLabel->setStyleSheet("background-color: rgba(0, 0, 0, 25); padding: 2px 4px;"); // Slightly darker than the window, in light and dark mode
358-
centralLayout->addWidget(mStatusLabel);
349+
statusBar()->addWidget(mStatusLabel, 1);
359350
mDarkMode = darkPalette(); // System scheme, until the display tells otherwise
360351
connect(QGuiApplication::styleHints(), &QStyleHints::colorSchemeChanged, this, &GPUDisplayGUI::colorSchemeChanged, Qt::QueuedConnection); // Queued: after the palette was updated
361352
mInfoTextTimer.setSingleShot(true);
362353
connect(&mInfoTextTimer, &QTimer::timeout, this, &GPUDisplayGUI::updateInfoLabels);
363-
setCentralWidget(central);
364354
std::vector<GPUDisplayGUIChannel::Frame> layout;
365355
{
366356
std::lock_guard lock(mChannel.mutex);
367357
setWindowTitle(QString::fromStdString(mChannel.windowName + " GUI"));
368358
layout = mChannel.layout;
369359
}
370360
mBaseFontSize = font().pointSizeF() > 0 ? font().pointSizeF() : 10.f; // Fonts with pixel size have no point size
371-
buildElements(layout);
361+
auto* content = new QWidget;
362+
auto* contentLayout = new QVBoxLayout(content);
363+
contentLayout->addWidget(buildElements(layout));
364+
contentLayout->addStretch();
365+
auto* scroll = new QScrollArea; // Vertical scroll bar if the frames do not fit into the window, they wrap to the window width
366+
scroll->setWidgetResizable(true);
367+
scroll->setFrameShape(QFrame::NoFrame);
368+
scroll->setWidget(content);
369+
setCentralWidget(scroll);
372370
colorSchemeChanged(); // Style sheets, with the GUI scale, which comes from the display with the first state
373371
qApp->installEventFilter(this); // Sliders / dropdowns would consume Ctrl + mouse wheel themselves
374372
connect(&mTimer, &QTimer::timeout, this, &GPUDisplayGUI::timerTick);
375373
mTimer.start(std::chrono::milliseconds(10));
376374
}
377375

378-
GPUDisplayGUI::~GPUDisplayGUI() = default;
379-
380376
void GPUDisplayGUI::timerTick()
381377
{
382378
std::unique_lock lock(mChannel.mutex);
@@ -472,6 +468,12 @@ void GPUDisplayGUI::resizeEvent(QResizeEvent* event)
472468
updateInfoLabels(); // Shows the GUI size
473469
}
474470

471+
void GPUDisplayGUI::fitStatusLabel()
472+
{
473+
mStatusLabel->setMinimumHeight(0); // heightForWidth of QLabel does not return less than the minimum height
474+
mStatusLabel->setFixedHeight(mStatusLabel->heightForWidth(mStatusLabel->width()));
475+
}
476+
475477
void GPUDisplayGUI::updateInfoLabels()
476478
{
477479
const QString status = QString::fromStdString(mState.infoStatus) + QString(" GUI %1x%2").arg(width()).arg(height());
@@ -484,6 +486,7 @@ void GPUDisplayGUI::updateInfoLabels()
484486
mStatusLabel->setText(status);
485487
}
486488
mStatusLabel->setVisible(!mState.infoStatus.empty());
489+
fitStatusLabel();
487490
}
488491

489492
void GPUDisplayGUI::applySettings()
@@ -680,13 +683,12 @@ GPUDisplayGUI::ElementWidget GPUDisplayGUI::createDropdown(const GPUDisplayGUICh
680683
}};
681684
}
682685

683-
void GPUDisplayGUI::buildElements(const std::vector<GPUDisplayGUIChannel::Frame>& layout)
686+
QWidget* GPUDisplayGUI::buildElements(const std::vector<GPUDisplayGUIChannel::Frame>& layout)
684687
{
685688
using Type = GPUDisplayGUIChannel::ElementType;
686689
auto* frames = new QWidget; // Frames with their natural width, next to each other while they fit into the window
687690
auto* framesLayout = new FlowLayout(frames, 1, true);
688691
framesLayout->setContentsMargins(0, 0, 0, 0);
689-
mUi->mainLayout->insertWidget(mUi->mainLayout->count() - 1, frames); // Before the vertical spacer
690692
for (const auto& frame : layout) {
691693
auto* box = new QGroupBox(QString::fromStdString(frame.description));
692694
if (frame.description.empty()) {
@@ -761,6 +763,7 @@ void GPUDisplayGUI::buildElements(const std::vector<GPUDisplayGUIChannel::Frame>
761763
}
762764
}
763765
mScaleSetters.emplace_back([framesLayout](float) { framesLayout->invalidate(); });
766+
return frames;
764767
}
765768

766769
void GPUDisplayGUI::setScale(float scale)
@@ -784,6 +787,10 @@ bool GPUDisplayGUI::eventFilter(QObject* watched, QEvent* event)
784787
if (!w || w->window() != this) {
785788
return false;
786789
}
790+
if (watched == mStatusLabel && event->type() == QEvent::Resize) {
791+
fitStatusLabel();
792+
return false;
793+
}
787794
if (event->type() == QEvent::Wheel && (static_cast<QWheelEvent*>(event)->modifiers() & Qt::ControlModifier)) {
788795
const int delta = static_cast<QWheelEvent*>(event)->angleDelta().y(); // 120 per notch
789796
if (delta) {

‎GPU/GPUTracking/display/frontend/GPUDisplayGUI.h‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,13 @@
1919
#include <QMainWindow>
2020
#include <QTimer>
2121
#include <functional>
22-
#include <memory>
2322
#include <optional>
2423
#include <utility>
2524
#include <vector>
2625

2726
class QKeyEvent;
2827
class QLabel;
2928

30-
QT_BEGIN_NAMESPACE
31-
namespace Ui
32-
{
33-
class GPUDisplayGUI;
34-
}
35-
QT_END_NAMESPACE
36-
3729
namespace o2::gpu
3830
{
3931
class GPUDisplayGUI : public QMainWindow
@@ -42,7 +34,6 @@ class GPUDisplayGUI : public QMainWindow
4234

4335
public:
4436
explicit GPUDisplayGUI(GPUDisplayGUIChannel& channel, QWidget* parent = nullptr);
45-
~GPUDisplayGUI() override;
4637
void bringToFront();
4738

4839
protected:
@@ -68,10 +59,11 @@ class GPUDisplayGUI : public QMainWindow
6859
void applySettings();
6960
void applyElement(GUIElement& element); // Set the element from mState.cfg if the value changed
7061
void updateInfoLabels();
62+
void fitStatusLabel(); // Height needed for the wrapped text, otherwise the size hint of the label makes the status bar too high
7163
bool darkPalette() const;
72-
void setDarkMode(bool dark); // Requests the color scheme from the platform theme
73-
void colorSchemeChanged(); // Style sheets and colors depending on the color scheme
74-
void buildElements(const std::vector<GPUDisplayGUIChannel::Frame>& layout); // One frame per add_gui_binding call, with a labeled element per option
64+
void setDarkMode(bool dark); // Requests the color scheme from the platform theme
65+
void colorSchemeChanged(); // Style sheets and colors depending on the color scheme
66+
QWidget* buildElements(const std::vector<GPUDisplayGUIChannel::Frame>& layout); // One frame per add_gui_binding call, with a labeled element per option
7567
ElementWidget createCheckbox(const GPUDisplayGUIChannel::Element& el);
7668
ElementWidget createTextbox(const GPUDisplayGUIChannel::Element& el);
7769
ElementWidget createSlider(const GPUDisplayGUIChannel::Element& el);
@@ -83,7 +75,6 @@ class GPUDisplayGUI : public QMainWindow
8375
void setScale(float scale); // Font size, fixed element sizes, and check / radio indicators (not sent to the display)
8476
static int32_t translateKey(const QKeyEvent* event); // Qt key → display key code, -1 if not forwarded
8577

86-
std::unique_ptr<Ui::GPUDisplayGUI> mUi;
8778
QTimer mTimer;
8879
GPUDisplayGUIChannel& mChannel;
8980
GPUDisplayGUIChannel::Update mUpdate; // Changes collected since the last tick

‎GPU/GPUTracking/display/frontend/GPUDisplayGUI.ui‎

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)