source: pacpusframework/trunk/src/DBITEPlayerLib/DbtPlyUserInterface.cpp@ 364

Last change on this file since 364 was 341, checked in by phudelai, 10 years ago

changement de tooltip du player

  • Property svn:executable set to *
File size: 11.3 KB
Line 
1// %pacpus:license{
2// This file is part of the PACPUS framework distributed under the
3// CECILL-C License, Version 1.0.
4// %pacpus:license}
5/// @version $Id: DbtPlyUserInterface.cpp 76 2013-01-10 17:05:10Z kurdejma $
6
7#include <Pacpus/DbitePlayer/DbtPlyUserInterface.h>
8
9#include <Pacpus/kernel/ComponentManager.h>
10#include <Pacpus/kernel/Log.h>
11
12#include <cassert>
13#include <cmath> // fabs
14#include <qapplication.h> // quit()
15#include <qboxlayout.h>
16#include <qbuttongroup.h>
17#include <qcheckbox.h>
18#include <qgroupbox.h>
19#include <qlabel.h>
20#include <qpushbutton.h>
21#include <qslider.h>
22#include <qtablewidget.h>
23
24namespace pacpus {
25
26class DbtPlyEngineState;
27
28DECLARE_STATIC_LOGGER("pacpus.core.DbtPlyUserInterface");
29
30//static ComponentFactory<DbtPlyUserInterface> factory("DbtPlyUserInterface");
31
32////////////////////////////////////////////////////////////////////////////////
33DbtPlyUserInterface::DbtPlyUserInterface(QString name)
34 : ComponentBase(name)
35 , componentTableWidget(NULL)
36{
37 relTime_ = absTime_ = tMin_ = tMax_ = 0;
38
39 setLayout(createMainLayout());
40
41 show();
42}
43
44////////////////////////////////////////////////////////////////////////////////
45DbtPlyUserInterface::~DbtPlyUserInterface()
46{
47}
48
49void DbtPlyUserInterface::addInputs()
50{
51 // empty: no inputs
52}
53
54void DbtPlyUserInterface::addOutputs()
55{
56 // empty: no outputs
57}
58
59////////////////////////////////////////////////////////////////////////////////
60ComponentBase::COMPONENT_CONFIGURATION DbtPlyUserInterface::configureComponent(XmlComponentConfig /*config*/)
61{
62 using boost::dynamic_pointer_cast;
63
64 ComponentManager * mgr = ComponentManager::getInstance();
65 mEngine = dynamic_pointer_cast<DbtPlyEngine>(mgr->getComponent("dbiteEngine"));
66 if (!mEngine) {
67 LOG_FATAL("cannot get a pointer of the 'dbiteEngine' component");
68 return CONFIGURED_FAILED;
69 }
70
71 connectButtons();
72 connectDisplay();
73 connectSlider();
74
75 updateComponentList();
76
77 return ComponentBase::CONFIGURED_OK;
78}
79
80////////////////////////////////////////////////////////////////////////////////
81/// Starts activity.
82void DbtPlyUserInterface::startActivity()
83{
84}
85
86////////////////////////////////////////////////////////////////////////////////
87/// Stops activity.
88void DbtPlyUserInterface::stopActivity()
89{
90}
91
92////////////////////////////////////////////////////////////////////////////////
93/// Overloaded.
94/// Invoked on close event.
95void DbtPlyUserInterface::closeEvent(QCloseEvent * /*event*/)
96{
97 qApp->quit();
98}
99
100void DbtPlyUserInterface::displayStateSlot(DbtPlyEngineState * state, float speed)
101{
102 LOG_DEBUG("displayStateSlot, state = " << state->toString() << ", speed = " << speed);
103
104 QString speedString;
105 if (fabs(speed) >= 1) {
106 speedString = speedString.setNum((int)speed);
107 } else {
108 speedString = "1/" + speedString.setNum((int)(1.0 / speed));
109 }
110
111 QString stateAndSpeedText;
112 stateAndSpeedText = state->toString() + " - speed : " + speedString;
113
114 lab->setText(stateAndSpeedText);
115 lab->adjustSize();
116}
117
118void DbtPlyUserInterface::displayMinMaxTime(road_time_t min, road_time_t max)
119{
120 timeMinValue->setText(QString::number(min));
121 tMin_ = min;
122 timeMaxValue->setText(QString::number(max));
123 tMax_ = max;
124 timeSlider->setMaximum(tMax_-tMin_);
125}
126
127void DbtPlyUserInterface::displayTime(road_time_t time)
128{
129 absTime_ = time;
130 if ((time - tMin_ - relTime_) > 40000 )
131 {
132 // refresh at 25Hz rate
133 relTime_ = (int)(time - tMin_);
134 timeCurValue->setText(QString::number(relTime_/1e6) + " - " + QString::number(absTime_));
135 timeSlider->setValue(relTime_);
136 }
137}
138
139int DbtPlyUserInterface::getTime()
140{
141 return timeSlider->value();
142}
143
144void DbtPlyUserInterface::resetTime()
145{
146 timeSlider->setValue(0);
147}
148
149QLayout * DbtPlyUserInterface::createMainLayout()
150{
151 QGroupBox * mainGroupBox = createControlGroupBox();
152 QGroupBox * componentListGroupBox = createComponentListGroupBox();
153
154 QGridLayout * generalLayout = new QGridLayout(this);
155 generalLayout->addWidget(mainGroupBox, /* row = */ 0, /* column = */ 0, /* rowSpan = */ 1, /* columnSpan = */ 3);
156 generalLayout->addWidget(componentListGroupBox, /* row = */ 1, /* column = */ 0, /* rowSpan = */ 1, /* columnSpan = */ 1);
157
158 return generalLayout;
159}
160
161QGroupBox * DbtPlyUserInterface::createControlGroupBox()
162{
163 const int kButtonWidthInPixels = 20;
164 const int kButtonHeightInPixels = 20;
165
166 QGridLayout * mainLayout = new QGridLayout(this);
167
168 butGroup = new QButtonGroup(this);
169 playBut = new QPushButton (style()->standardIcon(QStyle::SP_MediaPlay), "Play", this);
170 playBut->resize(kButtonWidthInPixels, kButtonHeightInPixels);
171 butGroup->addButton(playBut,1);
172 mainLayout->addWidget(playBut,0,0);
173
174 pauseBut = new QPushButton (style()->standardIcon(QStyle::SP_MediaPause), "Pause", this);
175 pauseBut->resize(kButtonWidthInPixels, kButtonHeightInPixels);
176 butGroup->addButton(pauseBut,2);
177 mainLayout->addWidget(pauseBut,0,1);
178
179 stopBut = new QPushButton (style()->standardIcon(QStyle::SP_MediaStop), "Stop", this);
180 stopBut->resize(kButtonWidthInPixels, kButtonHeightInPixels);
181 butGroup->addButton(stopBut,3);
182 mainLayout->addWidget(stopBut,0,2);
183
184 speedUpBut = new QPushButton (style()->standardIcon(QStyle::SP_MediaSeekForward), "", this);
185 speedUpBut->resize(kButtonWidthInPixels, kButtonHeightInPixels);
186 speedUpBut->setToolTip("Increase speed");
187 butGroup->addButton(speedUpBut,4);
188 mainLayout->addWidget(speedUpBut,1,1);
189
190 speedDownBut = new QPushButton (style()->standardIcon(QStyle::SP_MediaSeekBackward), "", this);
191 speedDownBut->resize(kButtonWidthInPixels, kButtonHeightInPixels);
192 speedDownBut->setToolTip("Decrease speed");
193 butGroup->addButton(speedDownBut,5);
194 mainLayout->addWidget(speedDownBut,1,0);
195
196 rev = new QCheckBox(tr("Reverse"), this);
197 mainLayout->addWidget(rev,1,2);
198
199 mainLayout->columnMinimumWidth(1);
200
201 lab = new QLabel (this);
202 lab->setText(tr("Player State"));
203 lab->adjustSize();
204 mainLayout->addWidget(lab,2,0,1,3);
205
206 timeMinTitle = new QLabel(this);
207 timeMinTitle->setText(tr("Min time"));
208 timeMinTitle->adjustSize();
209 mainLayout->addWidget(timeMinTitle,3,0);
210
211 timeMinValue = new QLabel(this);
212 timeMinValue->setText("0");
213 timeMinValue->adjustSize();
214 timeMinValue->setFrameStyle(QFrame::Panel | QFrame::Sunken);
215 mainLayout->addWidget(timeMinValue,3,1,1,2);
216
217 timeMaxTitle = new QLabel(this);
218 timeMaxTitle->setText(tr("Max time"));
219 timeMaxTitle->adjustSize();
220 mainLayout->addWidget(timeMaxTitle,4,0);
221
222 timeMaxValue = new QLabel(this);
223 timeMaxValue->setText("0");
224 timeMaxValue->adjustSize();
225 timeMaxValue->setFrameStyle(QFrame::Panel | QFrame::Sunken);
226 mainLayout->addWidget(timeMaxValue,4,1,1,2);
227
228 timeCurTitle = new QLabel(this);
229 timeCurTitle->setText(tr("Current time"));
230 timeCurTitle->adjustSize();
231 mainLayout->addWidget(timeCurTitle,5,0);
232
233 timeCurValue = new QLabel(this);
234 timeCurValue->setText("0 - 0");
235 timeCurValue->adjustSize();
236 timeCurValue->setFrameStyle(QFrame::Panel | QFrame::Sunken);
237 mainLayout->addWidget(timeCurValue,5,1,1,2);
238
239 timeSlider = new QSlider(Qt::Horizontal, this);
240 timeSlider->setMinimum(0);
241 timeSlider->adjustSize();
242 mainLayout->addWidget(timeSlider, /* row = */ 6, /* column = */ 0, /* rowSpan = */ 1, /* columnSpan = */ 3);
243
244 QGroupBox * mainGroupBox = new QGroupBox(tr("Control"));
245 mainGroupBox->setLayout(mainLayout);
246
247 return mainGroupBox;
248}
249
250QGroupBox * DbtPlyUserInterface::createComponentListGroupBox()
251{
252 QGroupBox * componentListGroupBox = new QGroupBox(tr("Component list"));
253
254 QBoxLayout * componentListLayout = new QBoxLayout(QBoxLayout::TopToBottom, this);
255 componentListGroupBox->setLayout(componentListLayout);
256
257 componentTableWidget = new QTableWidget(this);
258 componentListLayout->addWidget(componentTableWidget);
259
260 return componentListGroupBox;
261}
262
263void DbtPlyUserInterface::updateComponentList()
264{
265 ComponentManager * mgr = ComponentManager::getInstance();
266 QStringList componentNames = mgr->getAllComponentsName();
267
268 componentTableWidget->setRowCount(componentNames.size());
269 componentTableWidget->setColumnCount(2);
270 QStringList labels;
271 labels << tr("Name") << tr("State") << tr("Details");
272 componentTableWidget->setHorizontalHeaderLabels(labels);
273
274 int idx = 0;
275 for (QStringList::const_iterator it = componentNames.constBegin(), itend = componentNames.constEnd(); it != itend; ++it, ++idx) {
276 QString componentName = *it;
277 LOG_DEBUG("adding to component list: " << componentName);
278 componentTableWidget->setItem(idx, 0, new QTableWidgetItem(componentName));
279
280 ComponentSharedPointer component = mgr->getComponent(componentName);
281 if (!component) {
282 continue;
283 }
284
285 COMPONENT_STATE state = component->getState();
286
287 QString stateString;
288 switch (state) {
289 case STOPPED:
290 stateString = tr("Stopped");
291 break;
292 case NOT_MONITORED:
293 stateString = tr("Not monitored");
294 break;
295 case MONITOR_OK:
296 stateString = tr("Monitor OK");
297 break;
298 case MONITOR_NOK:
299 stateString = tr("Monitor wrong");
300 break;
301
302 default:
303 stateString = tr("UNKNOWN");
304 break;
305 }
306 componentTableWidget->setItem(idx, 1, new QTableWidgetItem(stateString));
307
308 // TODO: ADD component type and some detailed information (e.g. parameters)
309 //QString componentInfo = component->getDetails();
310 //componentTableWidget->setItem(idx, 2, new QTableWidgetItem(componentInfo));
311 }
312}
313
314void DbtPlyUserInterface::connectButtons()
315{
316 // FIXME: use Qt5 connect style
317 QObject::connect(playBut, SIGNAL(clicked()),
318 mEngine.get(), SLOT(playEvent()));
319 QObject::connect(pauseBut, SIGNAL(clicked()),
320 mEngine.get(), SLOT(pauseEvent()));
321 QObject::connect(stopBut, SIGNAL(clicked()),
322 mEngine.get(), SLOT(stopEvent()));
323 QObject::connect(speedUpBut, SIGNAL(clicked()),
324 mEngine.get(), SLOT(speedUpEvent()));
325 QObject::connect(speedDownBut, SIGNAL(clicked()),
326 mEngine.get(), SLOT(speedDownEvent()));
327}
328
329void DbtPlyUserInterface::connectDisplay()
330{
331 QObject::connect(mEngine.get(), SIGNAL(displayStateSig(DbtPlyEngineState *, float)),
332 this, SLOT(displayStateSlot(DbtPlyEngineState *, float)));
333 QObject::connect(mEngine.get(), SIGNAL(timeMinMax(road_time_t, road_time_t)),
334 this, SLOT(displayMinMaxTime(road_time_t , road_time_t)));
335 QObject::connect(mEngine.get(), SIGNAL(curReplayTime(road_time_t)),
336 this, SLOT(displayTime(road_time_t)));
337 QObject::connect(rev, SIGNAL(toggled(bool)),
338 mEngine.get(), SLOT(changeDirection(bool)));
339}
340
341void DbtPlyUserInterface::connectSlider()
342{
343 QObject::connect(timeSlider, SIGNAL(sliderPressed()),
344 mEngine.get(), SLOT(pauseEvent()));
345 QObject::connect(timeSlider, SIGNAL(sliderReleased()),
346 mEngine.get(), SLOT(playEvent()));
347}
348
349} // namespace pacpus
Note: See TracBrowser for help on using the repository browser.