source: trunk/FACT++/gui/MainWindow.cc@ 10751

Last change on this file since 10751 was 10737, checked in by tbretz, 14 years ago
Fixed a compiler error.
File size: 7.6 KB
Line 
1#include "MainWindow.h"
2
3#include <iostream>
4#include <sstream>
5
6#include <QTimer>
7
8#include "src/Dim.h"
9
10#include "DockWindow.h"
11#include "HtmlDelegate.h"
12#include "CheckBoxDelegate.h"
13
14using namespace std;
15
16MainWindow::MainWindow(QWidget *p) : QMainWindow(p)
17{
18 // setupUi MUST be called before the DimNetwork is initilized
19 // In this way it can be ensured that nothing from the
20 // DimNetwork arrives before all graphical elements are
21 // initialized. This is a simple but very powerfull trick.
22 setupUi(this);
23
24 // Now here we can do further setup which should be done
25 // before the gui is finally displayed.
26 fDimCmdServers->setItemDelegate(new CheckBoxDelegate);
27 fDimCmdCommands->setItemDelegate(new CheckBoxDelegate);
28 fDimCmdDescription->setItemDelegate(new HtmlDelegate);
29
30 fDimSvcServers->setItemDelegate(new CheckBoxDelegate);
31 fDimSvcServices->setItemDelegate(new CheckBoxDelegate);
32 fDimSvcDescription->setItemDelegate(new HtmlDelegate);
33
34 // Set a default string to be displayed in a the status bar at startup
35 fStatusBar->showMessage(PACKAGE_STRING" | "PACKAGE_URL" | report bugs to <"PACKAGE_BUGREPORT">");
36
37 // Initialize the 40 FTU Leds as a copy of the prototype LED
38 fFtuLED[0] = fFtuLEDPrototype;
39 fFtuLED[0]->setToolTip("Crate 0, Board 0, Index 0");
40
41 for (int i=1; i<40; i++)
42 {
43 QPushButton *b = new QPushButton(static_cast<QWidget*>(fFtuLEDPrototype->parent()));
44
45 b->setEnabled(fFtuLEDPrototype->isEnabled());
46 b->setSizePolicy(fFtuLEDPrototype->sizePolicy());
47 b->setMaximumSize(fFtuLEDPrototype->maximumSize());
48 b->setIcon(fFtuLEDPrototype->icon());
49 b->setIconSize(fFtuLEDPrototype->iconSize());
50 b->setCheckable(fFtuLEDPrototype->isCheckable());
51 b->setFlat(fFtuLEDPrototype->isFlat());
52
53 ostringstream str;
54 str << "Crate " << i/10 << ", Board " << i%10 << ", Index " << i;
55 b->setToolTip(str.str().c_str());
56
57 fFtuLedLayout->addWidget(b, i/10+1, i%10+1, 1, 1);
58
59 fFtuLED[i] = b;
60 }
61
62 for (int i=0; i<40; i++)
63 {
64 fFtuLED[i]->setObjectName(QString::fromUtf8("fFtuLED")+QString::number(i));
65 QObject::connect(fFtuLED[i], SIGNAL(clicked()), this, SLOT(slot_fFtuLED_clicked()));
66 }
67
68 // Initialize a timer to update the displayed UTC time
69 QTimer *timer = new QTimer(this);
70 connect(timer, SIGNAL(timeout()), this, SLOT(slot_TimeUpdate()));
71 timer->start(100);
72}
73
74void MainWindow::slot_TimeUpdate()
75{
76 fUTC->setDateTime(QDateTime::currentDateTimeUtc());
77}
78
79void MainWindow::SelectTab(const QString &name)
80{
81 for (int i=0; i<fTabWidget->count(); i++)
82 if (fTabWidget->tabText(i)==name)
83 {
84 fTabWidget->setCurrentIndex(i);
85 break;
86 }
87}
88
89
90void MainWindow::on_fShutdown_clicked()
91{
92 Dim::SendCommand("DIS_DNS/KILL_SERVERS");
93}
94
95
96void MainWindow::on_fShutdownAll_clicked()
97{
98 Dim::SendCommand("DIS_DNS/KILL_SERVERS");
99 Dim::SendCommand("DIS_DNS/EXIT", int(1));
100}
101
102void MainWindow::on_fTabWidget_tabCloseRequested(int which)
103{
104 // To get the correct size we have to switch to this tab
105 // An alternative would be to take the size of the current tab
106 fTabWidget->setCurrentIndex(which);
107
108 QWidget *w = fTabWidget->currentWidget(); //fTabWidget->widget(which);
109 if (!w)
110 {
111 cout << "Weird... the tab requested to be closed doesn't exist!" << endl;
112 return;
113 }
114
115 QDockWidget *d = w->findChild<QDockWidget*>();
116 if (!d)
117 {
118 cout << "Sorry, tab requested to be closed contains no QDockWidget!" << endl;
119 return;
120 }
121
122 new DockWindow(d, fTabWidget->tabText(which));
123 fTabWidget->removeTab(which);
124
125 if (fTabWidget->count()==1)
126 fTabWidget->setTabsClosable(false);
127}
128
129void MainWindow::SetTriggerSequence()
130{
131 const uint8_t d[3] =
132 {
133 uint8_t(fTriggerSeqPed->value()),
134 uint8_t(fTriggerSeqLPext->value()),
135 uint8_t(fTriggerSeqLPint->value())
136 };
137
138 if (!fInHandler)
139 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_SEQUENCE", d);
140}
141
142void on_fEnableTrigger_clicked(bool b)
143{
144 Dim::SendCommand("FTM_CONTROL/ENABLE_TRIGGER", b);
145}
146
147void on_fEnableExt1_clicked(bool b)
148{
149 Dim::SendCommand("FTM_CONTROL/ENABLE_EXT1", b);
150}
151
152void on_fEnableExt2_clicked(bool b)
153{
154 Dim::SendCommand("FTM_CONTROL/ENABLE_EXT2", b);
155}
156
157void on_fEnableVeto_clicked(bool b)
158{
159 Dim::SendCommand("FTM_CONTROL/ENABLE_VETO", b);
160}
161
162void MainWindow::on_fPhysicsCoincidence_valueChanged(int v)
163{
164 if (!fInHandler)
165 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_COINCIDENCE", v);
166}
167
168void MainWindow::on_fPhysicsWindow_valueChanged(int v)
169{
170 if (!fInHandler)
171 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_WINDOW", v/4-2);
172}
173
174void MainWindow::on_fCalibCoincidence_valueChanged(int v)
175{
176 if (!fInHandler)
177 Dim::SendCommand("FTM_CONTROL/SET_CALIBRATION_COINCIDENCE", v);
178}
179
180void MainWindow::on_fCalibWindow_valueChanged(int v)
181{
182 if (!fInHandler)
183 Dim::SendCommand("FTM_CONTROL/SET_CALIBRATION_WINDOW", v/4-2);
184}
185
186void MainWindow::on_fThresholdVal_valueChanged(int v)
187{
188 fThresholdVolt->setValue(2500./4095*v);
189
190 const int32_t d[2] = { fThresholdIdx->value(), v };
191
192 if (!fInHandler)
193 Dim::SendCommand("FTM_CONTROL/SET_THRESHOLD", d);
194}
195
196void MainWindow::on_fTriggerInterval_valueChanged(int val)
197{
198 if (!fInHandler)
199 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_INTERVAL", val);
200}
201
202void MainWindow::on_fTriggerDelay_valueChanged(int val)
203{
204 if (!fInHandler)
205 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_DELAY", val/4-2);
206}
207
208void MainWindow::on_fTimeMarkerDelay_valueChanged(int val)
209{
210 if (!fInHandler)
211 Dim::SendCommand("FTM_CONTROL/SET_TIME_MARKER_DELAY", val/4-2);
212}
213
214void MainWindow::on_fDeadTime_valueChanged(int val)
215{
216 if (!fInHandler)
217 Dim::SendCommand("FTM_CONTROL/SET_DEAD_TIME", val/4-2);
218}
219
220void MainWindow::on_fPrescalingVal_valueChanged(int val)
221{
222 if (!fInHandler)
223 Dim::SendCommand("FTM_CONTROL/SET_PRESCALING", val);
224}
225
226void MainWindow::on_fPixelEnable_stateChanged(bool b)
227{
228 if (fInHandler)
229 return;
230
231 const uint16_t idx = fPixelIdx->value();
232
233 const uint8_t d[3] = { uint8_t(idx&0xff), uint8_t(idx>>8), !b };
234
235 Dim::SendCommand("FTM_CONTROL/DISABLE_PIXEL", d);
236}
237
238void MainWindow::on_fEnableTrigger_stateChanged(bool b)
239{
240 if (!fInHandler)
241 Dim::SendCommand("FTM_CONTROL/ENABLE_TRIGGER", b);
242}
243
244void MainWindow::on_fEnableExt1_stateChanged(bool b)
245{
246 if (!fInHandler)
247 Dim::SendCommand("FTM_CONTROL/ENABLE_EXT1", b);
248}
249
250void MainWindow::on_fEnableExt2_stateChanged(bool b)
251{
252 if (!fInHandler)
253 Dim::SendCommand("FTM_CONTROL/ENABLE_EXT2", b);
254}
255
256void MainWindow::on_fEnableTimeMarker_stateChanged(bool b)
257{
258 if (!fInHandler)
259 Dim::SendCommand("FTM_CONTROL/ENABLE_TIM", b);
260}
261
262void MainWindow::on_fEnableVeto_stateChanged(bool b)
263{
264 if (!fInHandler)
265 Dim::SendCommand("FTM_CONTROL/ENABLE_VETO", b);
266}
267
268void MainWindow::slot_fFtuLED_clicked()
269{
270 for (int32_t i=0; i<40; i++)
271 if (sender()==fFtuLED[i])
272 {
273 Dim::SendCommand("FTM_CONTROL/TOGGLE_FTU", i);
274 break;
275 }
276}
277
278void MainWindow::on_fPing_toggled(bool checked)
279{
280 if (checked)
281 Dim::SendCommand("FTM_CONTROL/PING");
282}
283
284void MainWindow::on_fChatSend_clicked()
285{
286 if (Dim::SendCommand("CHAT/MSG", fChatMessage->displayText().constData()))
287 fChatMessage->clear();
288}
289
290void MainWindow::on_fStatusLoggerLed_clicked()
291{
292 SelectTab("Logger");
293}
294
295void MainWindow::on_fStatusChatLed_clicked()
296{
297 SelectTab("Chat");
298}
299
300void MainWindow::on_fStatusFTMLed_clicked()
301{
302 SelectTab("Trigger");
303}
304
305void MainWindow::on_fStatusFTULed_clicked()
306{
307 SelectTab("FTUs");
308}
Note: See TracBrowser for help on using the repository browser.