COPASI API  4.16.103
CQPlayerControlWidget.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 #include "CQPlayerControlWidget.h"
12 
13 #include <QtGui/QAction>
14 #include <QtGui/QGridLayout>
15 #include <QtGui/QIcon>
16 #include <QtGui/QLayout>
17 #include <QtGui/QPixmap>
18 #include <QtGui/QPushButton>
19 
21 
22 QPushButton* createControl(const CQIconResource::IconID& iconId, int size = 32)
23 {
24  QPushButton* button = new QPushButton;
25  button->setFlat(true);
26  button->setMinimumSize(size, size);
27  button->setMaximumSize(size, size);
28  button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
29  QIcon icon(CQIconResource::icon(iconId));
30  button->setIcon(icon);
31  button->setIconSize(QSize(size, size));
32  return button;
33 }
34 
36  QWidget(pParent),
37  mNumSteps(0),
38  mCurrentStep(0),
39  mPlaying(false),
40  mpPlayButton(NULL),
41  mpStopButton(NULL),
42  mpForwardButton(NULL),
43  mpBackwardButton(NULL),
44  mpStepForwardButton(NULL),
45  mpStepBackwardButton(NULL),
46  mpPlayAction(NULL),
47  mpPauseAction(NULL),
48  mpStopAction(NULL),
49  mpForwardAction(NULL),
50  mpBackwardAction(NULL),
51  mpStepForwardAction(NULL),
52  mpStepBackwardAction(NULL)
53 {
54  QGridLayout* pLayout = new QGridLayout;
55 
57  pLayout->addWidget(this->mpStepBackwardButton, 0, 0, 1, 1);
58 
60  pLayout->addWidget(this->mpPlayButton, 0, 1, 1, 1);
61 
63  pLayout->addWidget(this->mpStepForwardButton, 0, 2, 1, 1);
64 
66  pLayout->addWidget(this->mpBackwardButton, 1, 0, 1, 1);
67 
69  pLayout->addWidget(this->mpStopButton, 1, 1, 1, 1);
70 
72  pLayout->addWidget(this->mpForwardButton, 1, 2, 1, 1);
73 
74  this->setLayout(pLayout);
75 
76  pLayout->setSizeConstraint(QLayout::SetFixedSize);
77 
78  this->createActions();
79 
80  this->updateButtons();
81  this->updateActions();
82  this->setTabOrder(this->mpPlayButton, this->mpStopButton);
83  this->setTabOrder(this->mpStopButton, this->mpStepForwardButton);
84  this->setTabOrder(this->mpStepForwardButton, this->mpStepBackwardButton);
85  this->setTabOrder(this->mpStepBackwardButton, this->mpForwardButton);
86  this->setTabOrder(this->mpForwardButton, this->mpBackwardButton);
87  connect(this->mpPlayButton, SIGNAL(clicked()), this, SLOT(slot_play_clicked()));
88  connect(this->mpStopButton, SIGNAL(clicked()), this, SLOT(slot_stop_clicked()));
89  connect(this->mpForwardButton, SIGNAL(clicked()), this, SLOT(slot_forward_clicked()));
90  connect(this->mpBackwardButton, SIGNAL(clicked()), this, SLOT(slot_backward_clicked()));
91  connect(this->mpStepForwardButton, SIGNAL(clicked()), this, SLOT(slot_step_forward_clicked()));
92  connect(this->mpStepBackwardButton, SIGNAL(clicked()), this, SLOT(slot_step_backward_clicked()));
93 }
94 
96 {
97  this->mpPlayAction = new QAction(CQIconResource::icon(CQIconResource::play), "Play", this);
98  connect(this->mpPlayAction, SIGNAL(triggered()), this, SLOT(slot_play_clicked()));
99  this->mpPauseAction = new QAction(CQIconResource::icon(CQIconResource::pause), "Pause", this);
100  connect(this->mpPauseAction, SIGNAL(triggered()), this, SLOT(slot_pause_clicked()));
101  this->mpStopAction = new QAction(CQIconResource::icon(CQIconResource::stop), "Stop", this);
102  connect(this->mpStopAction, SIGNAL(triggered()), this, SLOT(slot_stop_clicked()));
103  this->mpForwardAction = new QAction(CQIconResource::icon(CQIconResource::skipForward), "Forward", this);
104  connect(this->mpForwardAction, SIGNAL(triggered()), this, SLOT(slot_forward_clicked()));
105  this->mpBackwardAction = new QAction(CQIconResource::icon(CQIconResource::skipBackward), "Backward", this);
106  connect(this->mpBackwardAction, SIGNAL(triggered()), this, SLOT(slot_backward_clicked()));
107  this->mpStepForwardAction = new QAction(CQIconResource::icon(CQIconResource::forward), "Step Forward", this);
108  connect(this->mpStepForwardAction, SIGNAL(triggered()), this, SLOT(slot_step_forward_clicked()));
109  this->mpStepBackwardAction = new QAction(CQIconResource::icon(CQIconResource::backward), "Step Backward", this);
110  connect(this->mpStepBackwardAction, SIGNAL(triggered()), this, SLOT(slot_step_backward_clicked()));
111 }
112 
114 {
115  this->mNumSteps = numSteps;
116  this->updateButtons();
117  this->updateActions();
118 }
119 
121 {
122  if (currentStep < this->mNumSteps)
123  {
124  this->mCurrentStep = currentStep;
125  }
126  else
127  {
128  this->mCurrentStep = this->mNumSteps - 1;
129  }
130 
131  this->updateButtons();
132  this->updateActions();
133 }
134 
136 {
138  this->mPlaying = !this->mPlaying;
139  this->mpPauseAction->setEnabled(FALSE);
140  emit pause();
141 }
142 
144 {
145  if (this->mPlaying)
146  {
147  this->slot_pause_clicked();
148  }
149  else
150  {
152  this->mPlaying = !this->mPlaying;
153  this->mpPauseAction->setEnabled(TRUE);
154  emit play();
155  }
156 }
157 
159 {
160  this->mCurrentStep = 0;
161  this->mPlaying = false;
162  this->updateButtons();
163  this->updateActions();
164  emit stop();
165 }
166 
168 {
169  this->mCurrentStep = this->mNumSteps - 1;
170  this->updateButtons();
171  this->updateActions();
172  emit forward();
173 }
174 
176 {
177  if (this->mNumSteps < 2)
178  {
179  // disable all actionsw
180  if (this->mpPlayAction->isEnabled())
181  {
182  this->mpPlayAction->setEnabled(FALSE);
183  }
184 
185  if (this->mpPauseAction->isEnabled())
186  {
187  this->mpPauseAction->setEnabled(FALSE);
188  }
189 
190  if (this->mpStopAction->isEnabled())
191  {
192  this->mpStopAction->setEnabled(FALSE);
193  }
194 
195  if (this->mpForwardAction->isEnabled())
196  {
197  this->mpForwardAction->setEnabled(FALSE);
198  }
199 
200  if (this->mpStepForwardAction->isEnabled())
201  {
202  this->mpStepForwardAction->setEnabled(FALSE);
203  }
204 
205  if (this->mpBackwardAction->isEnabled())
206  {
207  this->mpBackwardAction->setEnabled(FALSE);
208  }
209 
210  if (this->mpStepBackwardAction->isEnabled())
211  {
212  this->mpStepBackwardAction->setEnabled(FALSE);
213  }
214  }
215  else
216  {
217  if (this->mCurrentStep == 0)
218  {
219  // make sure backward and step_backward are disabled and all other
220  // actions are enabled
221  if (!this->mPlaying)
222  {
223  this->mpPauseAction->setEnabled(FALSE);
224  }
225  else
226  {
227  this->mpPauseAction->setEnabled(TRUE);
228  }
229 
230  if (this->mpBackwardAction->isEnabled())
231  {
232  this->mpBackwardAction->setEnabled(FALSE);
233  }
234 
235  if (this->mpStepBackwardAction->isEnabled())
236  {
237  this->mpStepBackwardAction->setEnabled(FALSE);
238  }
239 
240  if (this->mpPlayAction->isEnabled() == FALSE)
241  {
242  this->mpPlayAction->setEnabled(TRUE);
243  }
244 
245  if (this->mpStopAction->isEnabled() == FALSE)
246  {
247  this->mpStopAction->setEnabled(TRUE);
248  }
249 
250  if (this->mpForwardAction->isEnabled() == FALSE)
251  {
252  this->mpForwardAction->setEnabled(TRUE);
253  }
254 
255  if (this->mpStepForwardAction->isEnabled() == FALSE)
256  {
257  this->mpStepForwardAction->setEnabled(TRUE);
258  }
259  }
260  else if (this->mCurrentStep == this->mNumSteps - 1)
261  {
262  // make sure play, forward and step_forward are disabled and all other
263  // actions are enabled
264  // reset the icon on the play button
265  if (this->mpForwardAction->isEnabled())
266  {
267  this->mpForwardAction->setEnabled(FALSE);
268  }
269 
270  if (this->mpStepForwardAction->isEnabled())
271  {
272  this->mpStepForwardAction->setEnabled(FALSE);
273  }
274 
275  if (this->mpPlayAction->isEnabled())
276  {
277  this->mpPlayAction->setEnabled(FALSE);
278  }
279 
280  if (this->mpPauseAction->isEnabled())
281  {
282  this->mpPauseAction->setEnabled(FALSE);
283  }
284 
285  if (this->mpBackwardAction->isEnabled() == FALSE)
286  {
287  this->mpBackwardAction->setEnabled(TRUE);
288  }
289 
290  if (this->mpStepBackwardAction->isEnabled() == FALSE)
291  {
292  this->mpStepBackwardAction->setEnabled(TRUE);
293  }
294 
295  if (this->mpStopAction->isEnabled() == FALSE)
296  {
297  this->mpStopAction->setEnabled(TRUE);
298  }
299  }
300  else
301  {
302  // make sure all buttons are enabled
303  if (this->mpPlayAction->isEnabled() == FALSE)
304  {
305  this->mpPlayAction->setEnabled(TRUE);
306  }
307 
308  if (this->mpStopAction->isEnabled() == FALSE)
309  {
310  this->mpStopAction->setEnabled(TRUE);
311  }
312 
313  if (this->mpForwardAction->isEnabled() == FALSE)
314  {
315  this->mpForwardAction->setEnabled(TRUE);
316  }
317 
318  if (this->mpBackwardAction->isEnabled() == FALSE)
319  {
320  this->mpBackwardAction->setEnabled(TRUE);
321  }
322 
323  if (this->mpStepBackwardAction->isEnabled() == FALSE)
324  {
325  this->mpStepBackwardAction->setEnabled(TRUE);
326  }
327 
328  if (this->mpStepForwardAction->isEnabled() == FALSE)
329  {
330  this->mpStepForwardAction->setEnabled(TRUE);
331  }
332  }
333  }
334 }
335 
337 {
338  if (this->mNumSteps < 2)
339  {
340  // disable all buttons
341  if (this->mpPlayButton->isEnabled())
342  {
343  this->mpPlayButton->setEnabled(FALSE);
344 
345  if (this->mPlaying)
346  {
347  // reset the icon
349  }
350  }
351 
352  if (this->mpStopButton->isEnabled())
353  {
354  this->mpStopButton->setEnabled(FALSE);
355  }
356 
357  if (this->mpForwardButton->isEnabled())
358  {
359  this->mpForwardButton->setEnabled(FALSE);
360  }
361 
362  if (this->mpStepForwardButton->isEnabled())
363  {
364  this->mpStepForwardButton->setEnabled(FALSE);
365  }
366 
367  if (this->mpBackwardButton->isEnabled())
368  {
369  this->mpBackwardButton->setEnabled(FALSE);
370  }
371 
372  if (this->mpStepBackwardButton->isEnabled())
373  {
374  this->mpStepBackwardButton->setEnabled(FALSE);
375  }
376  }
377  else
378  {
379  if (this->mCurrentStep == 0)
380  {
381  // make sure backward and step_backward are disabled and all other
382  // buttons are enabled
383  if (!this->mPlaying)
384  {
386  }
387  else
388  {
390  }
391 
392  if (this->mpBackwardButton->isEnabled())
393  {
394  this->mpBackwardButton->setEnabled(FALSE);
395  }
396 
397  if (this->mpStepBackwardButton->isEnabled())
398  {
399  this->mpStepBackwardButton->setEnabled(FALSE);
400  }
401 
402  if (this->mpPlayButton->isEnabled() == FALSE)
403  {
404  this->mpPlayButton->setEnabled(TRUE);
405  }
406 
407  if (this->mpStopButton->isEnabled() == FALSE)
408  {
409  this->mpStopButton->setEnabled(TRUE);
410  }
411 
412  if (this->mpForwardButton->isEnabled() == FALSE)
413  {
414  this->mpForwardButton->setEnabled(TRUE);
415  }
416 
417  if (this->mpStepForwardButton->isEnabled() == FALSE)
418  {
419  this->mpStepForwardButton->setEnabled(TRUE);
420  }
421  }
422  else if (this->mCurrentStep == this->mNumSteps - 1)
423  {
424  // make sure play, forward and step_forward are disabled and all other
425  // buttons are enabled
426  // reset the icon on the play button
427  if (this->mpForwardButton->isEnabled())
428  {
429  this->mpForwardButton->setEnabled(FALSE);
430  }
431 
432  if (this->mpStepForwardButton->isEnabled())
433  {
434  this->mpStepForwardButton->setEnabled(FALSE);
435  }
436 
437  if (this->mpPlayButton->isEnabled())
438  {
440  this->mpPlayButton->setEnabled(FALSE);
441  }
442 
443  if (this->mpBackwardButton->isEnabled() == FALSE)
444  {
445  this->mpBackwardButton->setEnabled(TRUE);
446  }
447 
448  if (this->mpStepBackwardButton->isEnabled() == FALSE)
449  {
450  this->mpStepBackwardButton->setEnabled(TRUE);
451  }
452 
453  if (this->mpStopButton->isEnabled() == FALSE)
454  {
455  this->mpStopButton->setEnabled(TRUE);
456  }
457  }
458  else
459  {
460  // make sure all buttons are enabled
461  if (this->mpPlayButton->isEnabled() == FALSE)
462  {
463  this->mpPlayButton->setEnabled(TRUE);
464  }
465 
466  if (this->mpStopButton->isEnabled() == FALSE)
467  {
468  this->mpStopButton->setEnabled(TRUE);
469  }
470 
471  if (this->mpForwardButton->isEnabled() == FALSE)
472  {
473  this->mpForwardButton->setEnabled(TRUE);
474  }
475 
476  if (this->mpBackwardButton->isEnabled() == FALSE)
477  {
478  this->mpBackwardButton->setEnabled(TRUE);
479  }
480 
481  if (this->mpStepBackwardButton->isEnabled() == FALSE)
482  {
483  this->mpStepBackwardButton->setEnabled(TRUE);
484  }
485 
486  if (this->mpStepForwardButton->isEnabled() == FALSE)
487  {
488  this->mpStepForwardButton->setEnabled(TRUE);
489  }
490  }
491  }
492 }
493 
495 {
496  this->mCurrentStep = 0;
497  this->updateButtons();
498  this->updateActions();
499  emit backward();
500 }
501 
503 {
504  if (this->mCurrentStep != this->mNumSteps - 1)
505  {
506  ++this->mCurrentStep;
507  }
508 
509  this->updateButtons();
510  this->updateActions();
511  emit step_forward();
512 }
513 
515 {
516  if (this->mCurrentStep != 0)
517  {
518  --this->mCurrentStep;
519  }
520 
521  this->updateButtons();
522  this->updateActions();
523  emit step_backward();
524 }
525 
527 {
528  return this->mPlaying;
529 }
530 
532 {
533  return this->mpPlayAction;
534 }
535 
537 {
538  return this->mpPauseAction;
539 }
540 
542 {
543  return this->mpStopAction;
544 }
545 
547 {
548  return this->mpForwardAction;
549 }
550 
552 {
553  return this->mpBackwardAction;
554 }
555 
557 {
558  return this->mpStepForwardAction;
559 }
560 
562 {
563  return this->mpStepBackwardAction;
564 }
#define TRUE
Definition: CGA.h:25
QPushButton * createControl(const CQIconResource::IconID &iconId, int size=32)
void setNumSteps(size_t numSteps)
#define FALSE
Definition: CGA.h:26
void setCurrentStep(size_t currentStep)
static const QIcon & icon(const IconID &id)
CQPlayerControlWidget(QWidget *pParent=NULL)
QPushButton * mpStepBackwardButton