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