gui
Loading...
Searching...
No Matches
topLayout.cc
Go to the documentation of this file.
1// gui
2#include "gui.h"
3
4
5// qt
6#include <QString>
7#include <QCoreApplication>
8
9
10void GemcGUI::createTopButtons(QHBoxLayout* topLayout) {
11 // Build the top run-control row:
12 // - number-of-events field
13 // - run/cycle/stop/exit buttons
14 // - current event counter label
15 topLayout->setContentsMargins(0, 0, 0, 0);
16 topLayout->setSpacing(6);
17
18 auto* nEventsLabel = new QLabel(tr("N. Events:"));
19
20 auto* runButton = new QPushButton(tr("Run"));
21 runButton->setToolTip("Run events");
22 runButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
23
24 // getting the number of events from eventDispenser, which
25 // in turns gets it from options if no grun file is provided
26 auto grunNumberOfEvents = std::to_string(eventDispenser->getTotalNumberOfEvents());
27 nEvents = new QLineEdit(tr(grunNumberOfEvents.c_str()));
28 nEvents->setMaximumWidth(50);
29
30 auto* cycleButton = new QPushButton(tr("Cycle"));
31 cycleButton->setToolTip("Run 1 event every 2 seconds");
32 cycleButton->setIcon(style()->standardIcon(QStyle::SP_BrowserReload));
33
34 auto* stopButton = new QPushButton(tr("Stop"));
35 stopButton->setToolTip("Stops running events");
36 stopButton->setIcon(style()->standardIcon(QStyle::SP_MediaStop));
37
38 auto* closeButton = new QPushButton(tr("Exit"));
39 closeButton->setToolTip("Quit GEMC");
40 closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton));
41
42 // The label stores the cumulative number of processed events (as displayed to the user).
43 eventNumberLabel = new QLabel(tr("Event Number: 0"));
44
45 topLayout->addWidget(nEventsLabel);
46 topLayout->addWidget(nEvents);
47 topLayout->addWidget(runButton);
48 topLayout->addWidget(cycleButton);
49 topLayout->addWidget(stopButton);
50 topLayout->addStretch(1);
51 topLayout->addWidget(eventNumberLabel);
52 topLayout->addStretch(40);
53 topLayout->addWidget(closeButton);
54
55 // Wire UI events to slots:
56 // - text edits update the backend event count
57 // - buttons trigger run/cycle/stop/quit behavior
58 connect(nEvents, &QLineEdit::textChanged, this, &GemcGUI::neventsChanged);
59 connect(closeButton, &QPushButton::clicked, this, &GemcGUI::gquit);
60 connect(runButton, &QPushButton::clicked, this, &GemcGUI::beamOn);
61 connect(cycleButton, &QPushButton::clicked, this, &GemcGUI::cycleBeamOn);
62 connect(stopButton, &QPushButton::clicked, this, &GemcGUI::stopCycleBeamOn);
63}
64
65
66void GemcGUI::gquit() {
67 // Request application shutdown through Qt's application object.
68 qApp->quit();
69}
70
71
72void GemcGUI::neventsChanged() {
73 // Push the new event count into the backend so the next run uses the updated value.
74 int newNevents = nEvents->text().toInt();
75 eventDispenser->setNumberOfEvents(newNevents);
76}
77
78void GemcGUI::beamOn() {
79 // Run a batch once, then update the GUI counter label.
80 prepareGeometryForBeamOn();
81 eventDispenser->processEvents();
82 updateGui();
83}
84
85
86void GemcGUI::cycleBeamOn() {
87 // Enable periodic processing (2 seconds interval) and process events for this cycle.
88 if (!gtimer->isActive()) {
89 gtimer->start(2000);
90 }
91 prepareGeometryForBeamOn();
92 eventDispenser->processEvents();
93}
94
95
96void GemcGUI::stopCycleBeamOn() { gtimer->stop(); }