source: pacpusframework/branches/0.1.x/src/DBITEPlayerLib/DbtPlyUserInterface.cpp@ 356

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

changement de tooltip du player

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