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