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

Last change on this file since 10560 was 10557, checked in by tbretz, 14 years ago
Implemented sending SET_TRIGGER_DELAY, SET_TRIGGER_INTERVAL, SET_DEAD_TIME and SET_TIME_MARKER_DELAY
File size: 4.7 KB
Line 
1#include "MainWindow.h"
2
3#include <iostream>
4
5#include "dic.hxx"
6
7#include "DockWindow.h"
8#include "HtmlDelegate.h"
9#include "CheckBoxDelegate.h"
10
11using namespace std;
12
13namespace Dim
14{
15static bool SendCommand(const char *command)
16{
17 return DimClient::sendCommand(command, NULL, 0);
18}
19
20template<typename T>
21static bool SendCommand(const char *command, const T &t)
22{
23 return DimClient::sendCommand(command, (void*)&t, sizeof(t));
24}
25}
26
27MainWindow::MainWindow(QWidget *p) : QMainWindow(p)
28{
29 // setupUi MUST be called before the DimNetwork is initilized
30 // In this way it can be ensured that nothing from the
31 // DimNetwork arrives before all graphical elements are
32 // initialized. This is a simple but very powerfull trick.
33 setupUi(this);
34
35 // Now here we can do further setup which should be done
36 // before the gui is finally displayed.
37 fDimCmdServers->setItemDelegate(new CheckBoxDelegate);
38 fDimCmdCommands->setItemDelegate(new CheckBoxDelegate);
39 fDimCmdDescription->setItemDelegate(new HtmlDelegate);
40
41 fDimSvcServers->setItemDelegate(new CheckBoxDelegate);
42 fDimSvcServices->setItemDelegate(new CheckBoxDelegate);
43 fDimSvcDescription->setItemDelegate(new HtmlDelegate);
44
45 fStatusBar->showMessage(PACKAGE_STRING" | "PACKAGE_URL" | report bugs to <"PACKAGE_BUGREPORT">");
46
47 fFtuLED[0] = fFtuLEDPrototype;
48
49 for (int i=1; i<40; i++)
50 {
51 QPushButton *b = new QPushButton(static_cast<QWidget*>(fFtuLEDPrototype->parent()));
52
53 b->setEnabled(fFtuLEDPrototype->isEnabled());
54 b->setSizePolicy(fFtuLEDPrototype->sizePolicy());
55 b->setMaximumSize(fFtuLEDPrototype->maximumSize());
56 b->setIcon(fFtuLEDPrototype->icon());
57 b->setIconSize(fFtuLEDPrototype->iconSize());
58 b->setCheckable(fFtuLEDPrototype->isCheckable());
59 b->setFlat(fFtuLEDPrototype->isFlat());
60
61 fFtuLedLayout->addWidget(b, i/10+1, i%10+1, 1, 1);
62
63 fFtuLED[i] = b;
64 }
65
66 for (int i=0; i<40; i++)
67 {
68 fFtuLED[i]->setObjectName(QString::fromUtf8("fFtuLED")+QString::number(i));
69 QObject::connect(fFtuLED[i], SIGNAL(clicked()), this, SLOT(slot_fFtuLED_clicked()));
70 }
71}
72
73void MainWindow::SelectTab(const QString &name)
74{
75 for (int i=0; i<fTabWidget->count(); i++)
76 if (fTabWidget->tabText(i)==name)
77 {
78 fTabWidget->setCurrentIndex(i);
79 break;
80 }
81}
82
83
84void MainWindow::on_fShutdown_clicked()
85{
86 Dim::SendCommand("DIS_DNS/KILL_SERVERS");
87}
88
89
90void MainWindow::on_fShutdownAll_clicked()
91{
92 Dim::SendCommand("DIS_DNS/KILL_SERVERS");
93 Dim::SendCommand("DIS_DNS/EXIT", int(1));
94}
95
96void MainWindow::on_fTabWidget_tabCloseRequested(int which)
97{
98 // To get the correct size we have to switch to this tab
99 // An alternative would be to take the size of the current tab
100 fTabWidget->setCurrentIndex(which);
101
102 QWidget *w = fTabWidget->currentWidget(); //fTabWidget->widget(which);
103 if (!w)
104 {
105 cout << "Weird... the tab requested to be closed doesn't exist!" << endl;
106 return;
107 }
108
109 QDockWidget *d = w->findChild<QDockWidget*>();
110 if (!d)
111 {
112 cout << "Sorry, tab requested to be closed contains no QDockWidget!" << endl;
113 return;
114 }
115
116 new DockWindow(d, fTabWidget->tabText(which));
117 fTabWidget->removeTab(which);
118
119 if (fTabWidget->count()==1)
120 fTabWidget->setTabsClosable(false);
121}
122
123void MainWindow::on_fThresholdVal_valueChanged(int v)
124{
125 fThresholdVolt->setValue(2500./4095*v);
126
127 const int32_t d[2] = { fThresholdIdx->value(), v };
128 Dim::SendCommand("FTM_CONTROL/SET_THRESHOLD", d);
129}
130
131void on_fTriggerInterval_valueChanged(int val)
132{
133 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_INTERVAL", val);
134}
135
136void on_fTriggerDelay_valueChanged(int val)
137{
138 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_DELAY", val);
139}
140
141void on_fTimeMarkerDelay_valueChanged(int val)
142{
143 Dim::SendCommand("FTM_CONTROL/SET_TIME_MARKER_DELAY", val);
144}
145
146void on_fDeadTime_valueChanged(int val)
147{
148 Dim::SendCommand("FTM_CONTROL/SET_DEAD_TIME", val);
149}
150
151void MainWindow::slot_fFtuLED_clicked()
152{
153 for (int32_t i=0; i<40; i++)
154 if (sender()==fFtuLED[i])
155 {
156 Dim::SendCommand("FTM_CONTROL/TOGGLE_FTU", i);
157 break;
158 }
159}
160
161void MainWindow::on_fPing_toggled(bool checked)
162{
163 if (checked)
164 Dim::SendCommand("FTM_CONTROL/PING");
165}
166
167void MainWindow::on_fChatSend_clicked()
168{
169 if (Dim::SendCommand("CHAT/MSG", fChatMessage->displayText().constData()))
170 fChatMessage->clear();
171}
172
173void MainWindow::on_fStatusLoggerLed_clicked()
174{
175 SelectTab("Logger");
176}
177
178void MainWindow::on_fStatusChatLed_clicked()
179{
180 SelectTab("Chat");
181}
182
183void MainWindow::on_fStatusFTMLed_clicked()
184{
185 SelectTab("Trigger");
186}
187
188void MainWindow::on_fStatusFTULed_clicked()
189{
190 SelectTab("FTU");
191}
192
Note: See TracBrowser for help on using the repository browser.