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 = nullptr);
75  ~pqAnimationModel() override;
76 
80  int count();
84  pqAnimationTrack* track(int);
85 
90  pqAnimationTrack* addTrack(pqAnimationTrack* trackToAdd = nullptr);
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  double zoomStartTime() const;
123  double zoomEndTime() const;
127  double zoomFactor() const;
128 
132  bool interactive() const;
133 
134  QAbstractItemModel* header();
135  QAbstractItemModel* enabledHeader();
136 
137  void setRowHeight(int);
138  int rowHeight() const;
139 
143  void positionZoom(double zoomStartTime);
144 
148  const QList<double>& customTicks() const { return this->CustomTicks; }
149 
154  void setEnabledHeaderToolTip(const QString& val);
155  const QString& enabledHeaderToolTip() const { return this->EnabledHeaderToolTip; }
156 
157 public Q_SLOTS: // NOLINT(readability-redundant-access-specifiers)
158 
162  void setMode(ModeType);
166  void setTicks(int);
170  void setCurrentTime(double);
174  void setStartTime(double);
178  void setEndTime(double);
182  void setInteractive(bool);
187  void setTickMarks(int num, double* tick_marks);
192  void setTimePrecision(int precision);
193 
198  void setTimeNotation(const QChar& notation);
199 
203  void zoomTrack(pqAnimationTrack* track);
204 
205 Q_SIGNALS:
206  // emitted when a track is double clicked on
207  void trackSelected(pqAnimationTrack*);
208  // emitted when the current time was changed by this model
209  void currentTimeSet(double);
210  // emitted when the time of a keyframe was changed by this model
211  void keyFrameTimeChanged(pqAnimationTrack* track, pqAnimationKeyFrame* kf, int end, double time);
212  // emitted when the zoom factor or position are changed
213  void zoomChanged();
214 
215 protected Q_SLOTS:
216 
217  void resizeTracks();
218  void trackNameChanged();
219  void enabledChanged();
220 
221 protected: // NOLINT(readability-redundant-access-specifiers)
222  QPolygonF timeBarPoly(double time);
223  double positionFromTime(double time);
224  double timeFromPosition(double pos);
225  double timeFromTick(int tick);
226  int tickFromTime(double pos);
227  void drawForeground(QPainter* painter, const QRectF& rect) override;
228 
234  QRectF drawTimeLabel(double time, const QRectF& row, QPainter* painter,
235  const QFontMetrics& metrics, QList<const QRectF*> const& priorities);
236 
237  void updateNewTime(QGraphicsSceneMouseEvent* mouseEvent);
238  bool hitTestCurrentTimePoly(const QPointF& pos);
239  pqAnimationTrack* hitTestTracks(const QPointF& pos);
240  pqAnimationKeyFrame* hitTestKeyFrame(pqAnimationTrack* t, const QPointF& pos);
241 
242  bool eventFilter(QObject* w, QEvent* e) override;
243 
244  void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* mouseEvent) override;
245  void mousePressEvent(QGraphicsSceneMouseEvent* mouseEvent) override;
246  void mouseMoveEvent(QGraphicsSceneMouseEvent* mouseEvent) override;
247  void mouseReleaseEvent(QGraphicsSceneMouseEvent* mouseEvent) override;
248  void wheelEvent(QGraphicsSceneWheelEvent* wheelEvent) override;
249 
250  double timeToNormalizedTime(double) const;
251  double normalizedTimeToTime(double) const;
252 
257  int currentTicks() const;
258 
259 private:
260  ModeType Mode = Real;
261  int Ticks = 10;
262  double CurrentTime = 0;
263  double StartTime = 0;
264  double EndTime = 1;
265  double ZoomStartTime = 0;
266  double ZoomEndTime = 1;
267  double ZoomFactor = 1;
268  int RowHeight;
269  bool Interactive = false;
270 
271  QList<double> CustomTicks;
272 
273  // vars to support interaction
274  bool CurrentTimeGrabbed = false;
275  double NewCurrentTime = 0;
276  double TimeLineGrabbedPosition = 0;
277  double OldZoomStartTime = 0;
278  bool TimeLineGrabbed = false;
279  pqAnimationTrack* CurrentTrackGrabbed = nullptr;
280  pqAnimationKeyFrame* CurrentKeyFrameGrabbed = nullptr;
281  int CurrentKeyFrameEdge = 0;
282  QPair<double, double> InteractiveRange;
283  QList<double> SnapHints;
284 
285  QList<pqAnimationTrack*> Tracks;
286 
287  // model that provides names of tracks
288  QStandardItemModel Header;
289 
290  // model that provides enabled state for the tracks.
291  QStandardItemModel EnabledHeader;
292 
293  pqCheckBoxPixMaps* CheckBoxPixMaps;
294 
295  QString EnabledHeaderToolTip = "Enable/Disable Track";
296 
297  int TimePrecision = 6;
298  QChar TimeNotation = 'g';
299 };
300 
301 #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