gtree
Loading...
Searching...
No Matches
right_widget.cc
Go to the documentation of this file.
1// Right-side properties panel construction for GTree.
2// Doxygen documentation is authoritative in the header; this file provides a
3// short implementation-focused description and inline comments.
4
5#include <QLabel>
6#include <QTextEdit>
7#include <QVBoxLayout>
8
9#include "gtree.h"
10
11// Build the right-side panel that shows properties and controls for the selected item.
12QWidget* GTree::right_widget() {
13 // Container is parented to the GTree widget so Qt manages lifetime.
14 auto* container = new QWidget(this);
15 auto* vlayout = new QVBoxLayout(container);
16 vlayout->setContentsMargins(0, 0, 0, 0);
17 vlayout->setSpacing(4);
18
19 // Representation buttons live at the very top, always visible.
20 std::vector<std::string> bicons;
21 bicons.push_back(":/gtree/images/wireframe");
22 bicons.push_back(":/gtree/images/surface");
23 bicons.push_back(":/gtree/images/cloud");
24 bicons.push_back(":/gtree/images/centre");
25 styleButtons = new GQTButtonsWidget(96, 96, bicons, false);
26 styleButtons->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
27 vlayout->addWidget(styleButtons);
28
29 // Bottom panel: only visible when a tree item is selected.
30 bottomPanel = new QWidget(container);
31 auto* blayout = new QVBoxLayout(bottomPanel);
32 blayout->setContentsMargins(0, 0, 0, 0);
33 blayout->setSpacing(2);
34
35 // Opacity controls: label + slider + numeric value.
36 auto* opacityContainer = new QWidget(bottomPanel);
37 auto* opacityLayout = new QHBoxLayout(opacityContainer);
38 opacityLayout->setContentsMargins(0, 0, 0, 0);
39
40 auto* label = new QLabel(tr("Opacity:"), opacityContainer);
41 opacityLabel = new QLabel(tr("1.00"), opacityContainer);
42
43 opacitySlider = new QSlider(Qt::Horizontal, opacityContainer);
44 opacitySlider->setRange(0, 100);
45 opacitySlider->setValue(100);
46 opacitySlider->setSingleStep(5);
47 opacitySlider->setPageStep(10);
48
49 opacityLayout->addWidget(label);
50 opacityLayout->addWidget(opacitySlider);
51 opacityLayout->addWidget(opacityLabel);
52
53 blayout->addWidget(opacityContainer);
54 blayout->addSpacing(4);
55
56 // Info labels — all added directly, no scroll bar.
57 typeLabel = new QLabel(bottomPanel);
58 daughtersLabel = new QLabel(bottomPanel);
59 nameLabel = new QLabel(bottomPanel);
60 materialLabel = new QLabel(bottomPanel);
61 massLabel = new QLabel(bottomPanel);
62 volumeLabel = new QLabel(bottomPanel);
63 densityLabel = new QLabel(bottomPanel);
64 solidTypeLabel = new QLabel(bottomPanel);
65 positionLabel = new QLabel(bottomPanel);
66 rotationLabel = new QLabel(bottomPanel);
67 motherLabel = new QLabel(bottomPanel);
68 descriptionLabel = new QLabel(bottomPanel);
69 descriptionLabel->setWordWrap(true);
70
71 // parametersLabel as a read-only QTextEdit: owns its own vertical scrollbar,
72 // expands to show all content, scrolls only when the panel is too short.
73 parametersLabel = new QTextEdit(bottomPanel);
74 parametersLabel->setReadOnly(true);
75 parametersLabel->setFrameShape(QFrame::NoFrame);
76 parametersLabel->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
77 parametersLabel->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
78 parametersLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
79 parametersLabel->setStyleSheet(
80 "QTextEdit { background-color: rgba(255,255,255,30); border: 1px solid black; border-radius: 4px; padding: 3px; }");
81
82 blayout->addWidget(typeLabel);
83 blayout->addWidget(daughtersLabel);
84 blayout->addWidget(nameLabel);
85 blayout->addWidget(materialLabel);
86 blayout->addWidget(massLabel);
87 blayout->addWidget(volumeLabel);
88 blayout->addWidget(densityLabel);
89 blayout->addSpacing(6);
90 blayout->addWidget(solidTypeLabel);
91 blayout->addWidget(parametersLabel, 1);
92 blayout->addWidget(positionLabel);
93 blayout->addWidget(rotationLabel);
94 blayout->addWidget(motherLabel);
95 blayout->addWidget(descriptionLabel);
96 blayout->addStretch();
97
98 // Inspect button: opens the selected volume in a dedicated viewer window.
99 blayout->addSpacing(10);
100 inspectButton = new QPushButton(bottomPanel);
101 inspectButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
102 inspectButton->setStyleSheet(
103 "QPushButton { border: 2px solid black; border-radius: 4px; padding: 4px 8px; }"
104 "QPushButton:hover { background-color: palette(highlight); color: palette(highlighted-text); }"
105 );
106 connect(inspectButton, &QPushButton::clicked, this, &GTree::inspectVolume);
107 blayout->addWidget(inspectButton);
108
109 // Draw Logical Overlaps button: not yet functional — blocked by Geant4 11.4.2 TOOLSSG bug.
110 blayout->addSpacing(4);
111 drawOverlapsButton = new QPushButton(bottomPanel);
112 drawOverlapsButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
113 drawOverlapsButton->setStyleSheet(
114 "QPushButton { border: 2px solid black; border-radius: 4px; padding: 4px 8px; }"
115 "QPushButton:hover { background-color: palette(highlight); color: palette(highlighted-text); }"
116 );
117 connect(drawOverlapsButton, &QPushButton::clicked, this, &GTree::drawOverlapsWarning);
118 blayout->addWidget(drawOverlapsButton);
119
120 // Hidden until a volume or system is selected in the tree.
121 bottomPanel->setVisible(false);
122
123 vlayout->addWidget(bottomPanel, 1);
124
125 return container;
126}