COPASI API  4.16.103
CQAnimationControls.cpp
Go to the documentation of this file.
1 // Copyright (C) 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 #include <QtCore/QTimer>
7 
10 
12  : QWidget(parent)
13  , mNumSteps(100)
14  , mCurrentStep(0)
15  , mShouldLoop(true)
16  , mpTimer(new QTimer(this))
17 {
18 
19  setupUi(this);
20 
23  cmdStepBack->setIcon(CQIconResource::icon(CQIconResource::backward));
24  cmdStepForward->setIcon(CQIconResource::icon(CQIconResource::forward));
25  cmdPlayPause->setIcon(CQIconResource::icon(CQIconResource::play));
26  cmdStop->setIcon(CQIconResource::icon(CQIconResource::stop));
27 
28  mpTimer->setInterval(1000 / 10); // 10fps default
29  lblDuration->setText(QString::number(mNumSteps));
30  connect(mpTimer, SIGNAL(timeout()), this, SLOT(slotStepForward()));
31 }
32 
34 {
35  mpTimer->setInterval(interval);
36 }
37 
38 void CQAnimationControls::setNumSteps(size_t numSteps)
39 {
40  if (mNumSteps == numSteps) return;
41 
42  mNumSteps = numSteps;
43  sldPosition->setMaximum(numSteps - 1);
44  lblCurrent->setText(QString::number(sldPosition->minimum() + 1));
45  lblDuration->setText(QString::number(numSteps));
46 }
47 
48 void CQAnimationControls::setCurrentStep(size_t currentStep)
49 {
50  if (currentStep < mNumSteps)
51  {
52  mCurrentStep = currentStep;
53  }
54  else if (mNumSteps > 0)
55  {
56  mCurrentStep = mNumSteps - 1;
57  }
58  else
59  {
60  mCurrentStep = 0;
61  }
62 
63  updateButtons();
64  updateActions();
65 }
66 
68 {
69  return mpTimer->isActive();
70 }
71 
73 {
74 }
75 
77 {
78  emit backward();
79  sldPosition->setValue(0);
80 }
81 
83 {
84  emit forward();
85  sldPosition->setValue(mNumSteps - 1);
86 }
87 
89 {
90  bool playing = isPlaying();
91 
92  if (playing)
93  {
94  mpTimer->stop();
95  emit pause();
96  cmdPlayPause->setIcon(CQIconResource::icon(CQIconResource::play));
97  }
98  else
99  {
100  mpTimer->start();
101  emit play();
102  cmdPlayPause->setIcon(CQIconResource::icon(CQIconResource::pause));
103  }
104 }
105 
107 {
108  emit step_backward();
109  sldPosition->setValue(mCurrentStep < 2 ? 0 : --mCurrentStep);
110 }
111 
113 {
114  emit step_forward();
115 
116  int next;
117 
118  if (mCurrentStep >= mNumSteps - 1)
119  {
120  if (mShouldLoop)
121  {
122  next = 0;
123  }
124  else
125  {
126  slotStop();
127  return;
128  }
129  }
130  else
131  {
132  next = ++mCurrentStep;
133  }
134 
135  sldPosition->setValue(next);
136 }
137 
139 {
140  mpTimer->stop();
141  cmdPlayPause->setIcon(CQIconResource::icon(CQIconResource::play));
142  emit stop();
143  sldPosition->setValue(0);
144 }
145 
147 {
148  mCurrentStep = step;
149  lblCurrent->setText(QString::number(step + 1));
150  updateButtons();
151  updateActions();
152  emit showStep(step);
153 }
154 
156 {
157 }
159 {
160 }
static const QIcon & icon(const IconID &id)
void setNumSteps(size_t numSteps)
CQAnimationControls(QWidget *parent=NULL)
void setCurrentStep(size_t currentStep)