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:
60 
66  enum ModeType
67  {
70  Custom
71  };
72 
73  pqAnimationModel(QGraphicsView* p = 0);
75 
77  int count();
79  pqAnimationTrack* track(int);
80 
83  pqAnimationTrack* addTrack(pqAnimationTrack* trackToAdd=NULL);
85  void removeTrack(pqAnimationTrack* track);
86 
88  ModeType mode() const;
90  int ticks() const;
92  double currentTime() const;
94  double startTime() const;
96  double endTime() const;
98  bool interactive() const;
99 
100  QAbstractItemModel* header();
101  QAbstractItemModel* enabledHeader();
102 
103  void setRowHeight(int);
104  int rowHeight() const;
105 
108  const QList<double>& customTicks() const
109  { return this->CustomTicks; }
110 
113  void setEnabledHeaderToolTip(const QString& val);
114  const QString& enabledHeaderToolTip() const
115  { return this->EnabledHeaderToolTip; }
116 
117 public slots:
118 
120  void setMode(ModeType);
122  void setTicks(int);
124  void setCurrentTime(double);
126  void setStartTime(double);
128  void setEndTime(double);
130  void setInteractive(bool);
133  void setTickMarks(int num, double* tick_marks);
134 
135 signals:
136  // emitted when a track is double clicked on
137  void trackSelected(pqAnimationTrack*);
138  // emitted when the current time was changed by this model
139  void currentTimeSet(double);
140  // emitted when the time of a keyframe was changed by this model
141  void keyFrameTimeChanged(pqAnimationTrack* track, pqAnimationKeyFrame* kf, int end, double time);
142 
143 protected slots:
144 
145  void resizeTracks();
146  void trackNameChanged();
147  void enabledChanged();
148 
149 protected:
150  QPolygonF timeBarPoly(double time);
151  double positionFromTime(double time);
152  double timeFromPosition(double pos);
153  double timeFromTick(int tick);
154  int tickFromTime(double pos);
155  void drawForeground(QPainter* painter, const QRectF& rect);
156  bool hitTestCurrentTimePoly(const QPointF& pos);
157  pqAnimationTrack* hitTestTracks(const QPointF& pos);
158  pqAnimationKeyFrame* hitTestKeyFrame(pqAnimationTrack* t, const QPointF& pos);
159 
160  bool eventFilter(QObject* w, QEvent* e);
161 
162  void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* mouseEvent);
163  void mousePressEvent(QGraphicsSceneMouseEvent* mouseEvent);
164  void mouseMoveEvent(QGraphicsSceneMouseEvent* mouseEvent);
165  void mouseReleaseEvent(QGraphicsSceneMouseEvent* mouseEvent);
166 
167  double timeToNormalizedTime(double) const;
168  double normalizedTimeToTime(double) const;
169 
172  int currentTicks() const;
173 private:
174 
175  ModeType Mode;
176  int Ticks;
177  double CurrentTime;
178  double StartTime;
179  double EndTime;
180  int RowHeight;
181  bool Interactive;
182 
183  QList<double> CustomTicks;
184 
185  // vars to support interaction
186  bool CurrentTimeGrabbed;
187  double NewCurrentTime;
188  pqAnimationTrack* CurrentTrackGrabbed;
189  pqAnimationKeyFrame* CurrentKeyFrameGrabbed;
190  int CurrentKeyFrameEdge;
191  QPair<double, double> InteractiveRange;
192  QList<double> SnapHints;
193 
194  QList<pqAnimationTrack*> Tracks;
195 
196  // model that provides names of tracks
197  QStandardItemModel Header;
198 
199  // model that provides enabled state for the tracks.
200  QStandardItemModel EnabledHeader;
201 
202  pqCheckBoxPixMaps* CheckBoxPixMaps;
203 
204  QString EnabledHeaderToolTip;
205 };
206 
207 #endif // pqAnimationModel_h
208 
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