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

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

changement de tooltip du player

  • Property svn:executable set to *
File size: 11.3 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{
37 relTime_ = absTime_ = tMin_ = tMax_ = 0;
38
39 setLayout(createMainLayout());
40
41 show();
42}
43
44////////////////////////////////////////////////////////////////////////////////
45DbtPlyUserInterface::~DbtPlyUserInterface()
46{
47}
48
[152]49void DbtPlyUserInterface::addInputs()
50{
51 // empty: no inputs
52}
53
54void DbtPlyUserInterface::addOutputs()
55{
56 // empty: no outputs
57}
58
[89]59////////////////////////////////////////////////////////////////////////////////
60ComponentBase::COMPONENT_CONFIGURATION DbtPlyUserInterface::configureComponent(XmlComponentConfig /*config*/)
61{
[288]62 using boost::dynamic_pointer_cast;
63
[89]64 ComponentManager * mgr = ComponentManager::getInstance();
[288]65 mEngine = dynamic_pointer_cast<DbtPlyEngine>(mgr->getComponent("dbiteEngine"));
66 if (!mEngine) {
[89]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
[290]168 butGroup = new QButtonGroup(this);
[340]169 playBut = new QPushButton (style()->standardIcon(QStyle::SP_MediaPlay), "Play", this);
[89]170 playBut->resize(kButtonWidthInPixels, kButtonHeightInPixels);
171 butGroup->addButton(playBut,1);
172 mainLayout->addWidget(playBut,0,0);
173
[340]174 pauseBut = new QPushButton (style()->standardIcon(QStyle::SP_MediaPause), "Pause", this);
[89]175 pauseBut->resize(kButtonWidthInPixels, kButtonHeightInPixels);
176 butGroup->addButton(pauseBut,2);
177 mainLayout->addWidget(pauseBut,0,1);
178
[340]179 stopBut = new QPushButton (style()->standardIcon(QStyle::SP_MediaStop), "Stop", this);
[89]180 stopBut->resize(kButtonWidthInPixels, kButtonHeightInPixels);
181 butGroup->addButton(stopBut,3);
182 mainLayout->addWidget(stopBut,0,2);
183
[340]184 speedUpBut = new QPushButton (style()->standardIcon(QStyle::SP_MediaSeekForward), "", this);
[89]185 speedUpBut->resize(kButtonWidthInPixels, kButtonHeightInPixels);
[341]186 speedUpBut->setToolTip("Increase speed");
[89]187 butGroup->addButton(speedUpBut,4);
[340]188 mainLayout->addWidget(speedUpBut,1,1);
[89]189
[340]190 speedDownBut = new QPushButton (style()->standardIcon(QStyle::SP_MediaSeekBackward), "", this);
[89]191 speedDownBut->resize(kButtonWidthInPixels, kButtonHeightInPixels);
[341]192 speedDownBut->setToolTip("Decrease speed");
[89]193 butGroup->addButton(speedDownBut,5);
[340]194 mainLayout->addWidget(speedDownBut,1,0);
[89]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
[288]280 ComponentSharedPointer component = mgr->getComponent(componentName);
281 if (!component) {
282 continue;
283 }
[89]284
[288]285 COMPONENT_STATE state = component->getState();
[89]286
[288]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;
[89]301
[288]302 default:
303 stateString = tr("UNKNOWN");
304 break;
[89]305 }
[288]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));
[89]311 }
312}
313
314void DbtPlyUserInterface::connectButtons()
315{
[288]316 // FIXME: use Qt5 connect style
[290]317 QObject::connect(playBut, SIGNAL(clicked()),
[288]318 mEngine.get(), SLOT(playEvent()));
[290]319 QObject::connect(pauseBut, SIGNAL(clicked()),
[288]320 mEngine.get(), SLOT(pauseEvent()));
[290]321 QObject::connect(stopBut, SIGNAL(clicked()),
[288]322 mEngine.get(), SLOT(stopEvent()));
[290]323 QObject::connect(speedUpBut, SIGNAL(clicked()),
[288]324 mEngine.get(), SLOT(speedUpEvent()));
[290]325 QObject::connect(speedDownBut, SIGNAL(clicked()),
[288]326 mEngine.get(), SLOT(speedDownEvent()));
[89]327}
328
329void DbtPlyUserInterface::connectDisplay()
330{
[290]331 QObject::connect(mEngine.get(), SIGNAL(displayStateSig(DbtPlyEngineState *, float)),
[89]332 this, SLOT(displayStateSlot(DbtPlyEngineState *, float)));
[290]333 QObject::connect(mEngine.get(), SIGNAL(timeMinMax(road_time_t, road_time_t)),
[89]334 this, SLOT(displayMinMaxTime(road_time_t , road_time_t)));
[290]335 QObject::connect(mEngine.get(), SIGNAL(curReplayTime(road_time_t)),
[89]336 this, SLOT(displayTime(road_time_t)));
[290]337 QObject::connect(rev, SIGNAL(toggled(bool)),
[288]338 mEngine.get(), SLOT(changeDirection(bool)));
[89]339}
340
341void DbtPlyUserInterface::connectSlider()
342{
[290]343 QObject::connect(timeSlider, SIGNAL(sliderPressed()),
[288]344 mEngine.get(), SLOT(pauseEvent()));
[290]345 QObject::connect(timeSlider, SIGNAL(sliderReleased()),
[288]346 mEngine.get(), SLOT(playEvent()));
[89]347}
348
349} // namespace pacpus
Note: See TracBrowser for help on using the repository browser.