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

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