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);
75  ~pqAnimationModel() override;
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 Q_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);
175  void setTimePrecision(int precision);
176 
181  void setTimeNotation(const QChar& notation);
182 
183 Q_SIGNALS:
184  // emitted when a track is double clicked on
185  void trackSelected(pqAnimationTrack*);
186  // emitted when the current time was changed by this model
187  void currentTimeSet(double);
188  // emitted when the time of a keyframe was changed by this model
189  void keyFrameTimeChanged(pqAnimationTrack* track, pqAnimationKeyFrame* kf, int end, double time);
190 
191 protected Q_SLOTS:
192 
193  void resizeTracks();
194  void trackNameChanged();
195  void enabledChanged();
196 
197 protected:
198  QPolygonF timeBarPoly(double time);
199  double positionFromTime(double time);
200  double timeFromPosition(double pos);
201  double timeFromTick(int tick);
202  int tickFromTime(double pos);
203  void drawForeground(QPainter* painter, const QRectF& rect) override;
204  bool hitTestCurrentTimePoly(const QPointF& pos);
205  pqAnimationTrack* hitTestTracks(const QPointF& pos);
206  pqAnimationKeyFrame* hitTestKeyFrame(pqAnimationTrack* t, const QPointF& pos);
207 
208  bool eventFilter(QObject* w, QEvent* e) override;
209 
210  void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* mouseEvent) override;
211  void mousePressEvent(QGraphicsSceneMouseEvent* mouseEvent) override;
212  void mouseMoveEvent(QGraphicsSceneMouseEvent* mouseEvent) override;
213  void mouseReleaseEvent(QGraphicsSceneMouseEvent* mouseEvent) override;
214 
215  double timeToNormalizedTime(double) const;
216  double normalizedTimeToTime(double) const;
217 
222  int currentTicks() const;
223 
224 private:
225  ModeType Mode;
226  int Ticks;
227  double CurrentTime;
228  double StartTime;
229  double EndTime;
230  int RowHeight;
231  bool Interactive;
232 
233  QList<double> CustomTicks;
234 
235  // vars to support interaction
236  bool CurrentTimeGrabbed;
237  double NewCurrentTime;
238  pqAnimationTrack* CurrentTrackGrabbed;
239  pqAnimationKeyFrame* CurrentKeyFrameGrabbed;
240  int CurrentKeyFrameEdge;
241  QPair<double, double> InteractiveRange;
242  QList<double> SnapHints;
243 
244  QList<pqAnimationTrack*> Tracks;
245 
246  // model that provides names of tracks
247  QStandardItemModel Header;
248 
249  // model that provides enabled state for the tracks.
250  QStandardItemModel EnabledHeader;
251 
252  pqCheckBoxPixMaps* CheckBoxPixMaps;
253 
254  QString EnabledHeaderToolTip;
255 
256  int TimePrecision;
257  QChar TimeNotation;
258 };
259 
260 #endif // pqAnimationModel_h
const QList< double > & customTicks() const
provides access to the custom ticks set using setTickMarks() method.
time
ModeType
Real, Sequence or Custom mode Real mode shows no tick marks for timesteps Sequence mode shows evenly ...
#define PQWIDGETS_EXPORT
mode
pqCheckBoxPixMaps is a helper class that can used to create pixmaps for checkboxs in various states...
startTime
const QString & enabledHeaderToolTip() const