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

Last change on this file since 10644 was 10644, checked in by tbretz, 9 years ago
Moved some Dim code to new Dim.h/Dim.cc
File size: 6.0 KB
Line 
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
13using namespace std;
14
15MainWindow::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
65void MainWindow::slot_TimeUpdate()
66{
67    fUTC->setDateTime(QDateTime::currentDateTimeUtc());
68}
69
70void 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
81void MainWindow::on_fShutdown_clicked()
82{
83    Dim::SendCommand("DIS_DNS/KILL_SERVERS");
84}
85
86
87void MainWindow::on_fShutdownAll_clicked()
88{
89    Dim::SendCommand("DIS_DNS/KILL_SERVERS");
90    Dim::SendCommand("DIS_DNS/EXIT", int(1));
91}
92
93void 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
120void 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
132void on_fEnableTrigger_clicked(bool b)
133{
134    Dim::SendCommand("FTM_CONTROL/ENABLE_TRIGGER", b);
135}
136
137void on_fEnableExt1_clicked(bool b)
138{
139    Dim::SendCommand("FTM_CONTROL/ENABLE_EXT1", b);
140}
141
142void on_fEnableExt2_clicked(bool b)
143{
144    Dim::SendCommand("FTM_CONTROL/ENABLE_EXT2", b);
145}
146
147void on_fEnableVeto_clicked(bool b)
148{
149    Dim::SendCommand("FTM_CONTROL/ENABLE_VETO", b);
150}
151
152void 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
163void 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
174void 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
182void MainWindow::on_fTriggerInterval_valueChanged(int val)
183{
184    Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_INTERVAL", val);
185}
186
187void MainWindow::on_fTriggerDelay_valueChanged(int val)
188{
189    Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_DELAY", val/4-2);
190}
191
192void MainWindow::on_fTimeMarkerDelay_valueChanged(int val)
193{
194    Dim::SendCommand("FTM_CONTROL/SET_TIME_MARKER_DELAY", val/4-2);
195}
196
197void MainWindow::on_fDeadTime_valueChanged(int val)
198{
199    Dim::SendCommand("FTM_CONTROL/SET_DEAD_TIME", val/4-2);
200}
201
202void MainWindow::on_fPrescalingVal_valueChanged(int val)
203{
204    Dim::SendCommand("FTM_CONTROL/SET_PRESCALING", val);
205}
206
207void 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
217void MainWindow::on_fPing_toggled(bool checked)
218{
219    if (checked)
220        Dim::SendCommand("FTM_CONTROL/PING");
221}
222
223void MainWindow::on_fChatSend_clicked()
224{
225    if (Dim::SendCommand("CHAT/MSG", fChatMessage->displayText().constData()))
226        fChatMessage->clear();
227}
228
229void MainWindow::on_fStatusLoggerLed_clicked()
230{
231    SelectTab("Logger");
232}
233
234void MainWindow::on_fStatusChatLed_clicked()
235{
236    SelectTab("Chat");
237}
238
239void MainWindow::on_fStatusFTMLed_clicked()
240{
241    SelectTab("Trigger");
242}
243
244void MainWindow::on_fStatusFTULed_clicked()
245{
246    SelectTab("FTUs");
247}
Note: See TracBrowser for help on using the repository browser.