gui
Loading...
Searching...
No Matches
gui.cc
Go to the documentation of this file.
1// gui
2#include "gui.h"
3
4
5
6GemcGUI::GemcGUI(std::shared_ptr<GOptions> gopts,
7 std::shared_ptr<EventDispenser> ed,
9 QWidget* parent) :
10 QWidget(parent),
11 eventDispenser(ed) {
12
13 // Create the left navigation pane first; right content initialization uses it to sync selection state.
14 createLeftButtons(); // instantiates leftButtons
15
16 // The board is a long-lived widget attached to this GUI; it is used by other pages (e.g. dialog).
17 auto* gboard = new GBoard(gopts, this);
18
19 // Session object ties together options and the board; it is kept alive for the GUI lifetime.
20 guiSession = std::make_unique<GUI_Session>(gopts, gboard);
21
22 // Create the right stacked content pages (display, dialog, setup, tree) and synchronize default selection.
23 createRightContent(gopts, dc, gboard); // instantiates rightContent: g4control, g4dialog, etc
24
25 // Top row control buttons (run controls and counters).
26 auto* topLayout = new QHBoxLayout;
27 createTopButtons(topLayout);
28
29 // Bottom row contains left navigation and right content; stretch factor favors the content area.
30 auto* bottomLayout = new QHBoxLayout;
31 // second argument is stretch factor. Right content can have 10 times more space.
32 bottomLayout->addWidget(leftButtons, 1);
33 bottomLayout->addWidget(rightContent, 10);
34
35 // Main layout: top controls, bottom panes, and board.
36 auto* mainLayout = new QVBoxLayout;
37 mainLayout->addLayout(topLayout);
38 mainLayout->addLayout(bottomLayout);
39 mainLayout->addWidget(gboard);
40
41 setLayout(mainLayout);
42 setWindowTitle(tr("GEMC: Geant4 Monte-Carlo"));
43 setFixedWidth(1000);
44
45 // Timer used for cycle mode; timeouts are connected to cycleBeamOn().
46 gtimer = new QTimer(this);
47 connect(gtimer, SIGNAL(timeout()), this, SLOT(cycleBeamOn()));
48
49 // Page switching: left button selection drives the stacked widget page index.
50 connect(leftButtons->buttonsWidget,
51 SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem*)),
52 this, SLOT(change_page(QListWidgetItem *, QListWidgetItem*)));
53}
54
55
56void GemcGUI::updateGui() {
57 // Parse the current label text and increment by the amount run in the most recent batch.
58 std::vector<std::string> sBefore = gutilities::getStringVectorFromString(eventNumberLabel->text().toStdString());
59
60 int nThatWasRun = nEvents->text().toInt();
61 int nBefore = stoi(sBefore[2]);
62
63 QString newNEvents("Event Number: ");
64 newNEvents.append(std::to_string(nBefore + nThatWasRun).c_str());
65
66 eventNumberLabel->setText(newNEvents);
67}
68
69
71 // All widgets are owned via Qt parent/child relationships once placed into the layout hierarchy.
72 // Rely on Qt to destroy children when GemcGUI is destroyed.
73}
74
75
76void GemcGUI::change_page(QListWidgetItem* current, QListWidgetItem* previous) {
77
78 // Qt may emit selection changes with a null current item; fall back to the previous selection.
79 if (!current)
80 current = previous;
81
82 // The left button widget provides the active page index; apply it to the stacked widget.
83 int thisIndex = leftButtons->button_pressed();
84 rightContent->setCurrentIndex(thisIndex);
85}
QListWidget * buttonsWidget
int button_pressed() const
GemcGUI(std::shared_ptr< GOptions > gopts, std::shared_ptr< EventDispenser > ed, GDetectorConstruction *dc, QWidget *parent=nullptr)
Construct the main GUI widget.
Definition gui.cc:6
~GemcGUI() override
Destroy the GUI widget and release explicitly owned resources.
Definition gui.cc:70
vector< std::string > getStringVectorFromString(const std::string &input)