ParaView
pqAnimationModel.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ParaView
4  Module: pqAnimationModel.h
5 
6  Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
7  All rights reserved.
8 
9  ParaView is a free software; you can redistribute it and/or modify it
10  under the terms of the ParaView license version 1.2.
11 
12  See License_v1.2.txt for the full ParaView license.
13  A copy of this license can be obtained by contacting
14  Kitware Inc.
15  28 Corporate Drive
16  Clifton Park, NY 12065
17  USA
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
23 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 =========================================================================*/
32 
33 #ifndef pqAnimationModel_h
34 #define pqAnimationModel_h
35 
36 #include "pqWidgetsModule.h"
37 
38 #include <QGraphicsScene>
39 #include <QObject>
40 #include <QPolygonF>
41 #include <QStandardItemModel>
42 
43 class pqAnimationTrack;
45 class QGraphicsView;
46 class pqCheckBoxPixMaps;
47 
48 // a model that represents a collection of animation tracks
49 class PQWIDGETS_EXPORT pqAnimationModel : public QGraphicsScene
50 {
51  Q_OBJECT
52  Q_ENUMS(ModeType)
53  Q_PROPERTY(ModeType mode READ mode WRITE setMode)
54  Q_PROPERTY(int ticks READ ticks WRITE setTicks)
55  Q_PROPERTY(double currentTime READ currentTime WRITE setCurrentTime)
56  Q_PROPERTY(double startTime READ startTime WRITE setStartTime)
57  Q_PROPERTY(double endTime READ endTime WRITE setEndTime)
58  Q_PROPERTY(bool interactive READ interactive WRITE setInteractive)
59 public:
67  enum ModeType
68  {
71  Custom
72  };
73 
74  pqAnimationModel(QGraphicsView* p = 0);
76 
80  int count();
84  pqAnimationTrack* track(int);
85 
90  pqAnimationTrack* addTrack(pqAnimationTrack* trackToAdd = NULL);
94  void removeTrack(pqAnimationTrack* track);
95 
99  ModeType mode() const;
103  int ticks() const;
107  double currentTime() const;
111  double startTime() const;
115  double endTime() const;
119  bool interactive() const;
120 
121  QAbstractItemModel* header();
122  QAbstractItemModel* enabledHeader();
123 
124  void setRowHeight(int);
125  int rowHeight() const;
126 
131  const QList<double>& customTicks() const { return this->CustomTicks; }
132 
137  void setEnabledHeaderToolTip(const QString& val);
138  const QString& enabledHeaderToolTip() const { return this->EnabledHeaderToolTip; }
139 
140 public slots:
141 
145  void setMode(ModeType);
149  void setTicks(int);
153  void setCurrentTime(double);
157  void setStartTime(double);
161  void setEndTime(double);
165  void setInteractive(bool);
170  void setTickMarks(int num, double* tick_marks);
171 
172 signals:
173  // emitted when a track is double clicked on
174  void trackSelected(pqAnimationTrack*);
175  // emitted when the current time was changed by this model
176  void currentTimeSet(double);
177  // emitted when the time of a keyframe was changed by this model
178  void keyFrameTimeChanged(pqAnimationTrack* track, pqAnimationKeyFrame* kf, int end, double time);
179 
180 protected slots:
181 
182  void resizeTracks();
183  void trackNameChanged();
184  void enabledChanged();
185 
186 protected:
187  QPolygonF timeBarPoly(double time);
188  double positionFromTime(double time);
189  double timeFromPosition(double pos);
190  double timeFromTick(int tick);
191  int tickFromTime(double pos);
192  void drawForeground(QPainter* painter, const QRectF& rect);
193  bool hitTestCurrentTimePoly(const QPointF& pos);
194  pqAnimationTrack* hitTestTracks(const QPointF& pos);
195  pqAnimationKeyFrame* hitTestKeyFrame(pqAnimationTrack* t, const QPointF& pos);
196 
197  bool eventFilter(QObject* w, QEvent* e);
198 
199  void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* mouseEvent);
200  void mousePressEvent(QGraphicsSceneMouseEvent* mouseEvent);
201  void mouseMoveEvent(QGraphicsSceneMouseEvent* mouseEvent);
202  void mouseReleaseEvent(QGraphicsSceneMouseEvent* mouseEvent);
203 
204  double timeToNormalizedTime(double) const;
205  double normalizedTimeToTime(double) const;
206 
211  int currentTicks() const;
212 
213 private:
214  ModeType Mode;
215  int Ticks;
216  double CurrentTime;
217  double StartTime;
218  double EndTime;
219  int RowHeight;
220  bool Interactive;
221 
222  QList<double> CustomTicks;
223 
224  // vars to support interaction
225  bool CurrentTimeGrabbed;
226  double NewCurrentTime;
227  pqAnimationTrack* CurrentTrackGrabbed;
228  pqAnimationKeyFrame* CurrentKeyFrameGrabbed;
229  int CurrentKeyFrameEdge;
230  QPair<double, double> InteractiveRange;
231  QList<double> SnapHints;
232 
233  QList<pqAnimationTrack*> Tracks;
234 
235  // model that provides names of tracks
236  QStandardItemModel Header;
237 
238  // model that provides enabled state for the tracks.
239  QStandardItemModel EnabledHeader;
240 
241  pqCheckBoxPixMaps* CheckBoxPixMaps;
242 
243  QString EnabledHeaderToolTip;
244 };
245 
246 #endif // pqAnimationModel_h
const QList< double > & customTicks() const
provides access to the custom ticks set using setTickMarks() method.
ModeType
Real, Sequence or Custom mode Real mode shows no tick marks for timesteps Sequence mode shows evenly ...
pqCheckBoxPixMaps is a helper class that can used to create pixmaps for checkboxs in various states...
const QString & enabledHeaderToolTip() const