pqAnimationModel.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Kitware Inc.
2 // SPDX-FileCopyrightText: Copyright (c) Sandia Corporation
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #ifndef pqAnimationModel_h
6 #define pqAnimationModel_h
7 
8 #include "pqWidgetsModule.h"
9 
10 #include "vtkParaViewDeprecation.h"
11 
12 #include <QGraphicsScene>
13 #include <QObject>
14 #include <QPolygonF>
15 #include <QStandardItemModel>
16 
17 class pqAnimationTrack;
18 class pqAnimationKeyFrame;
19 class QGraphicsView;
20 class pqCheckBoxPixMaps;
21 
22 // a model that represents a collection of animation tracks
24  "See `pqTimeManagerWidget` for new design") PQWIDGETS_EXPORT pqAnimationModel
25  : public QGraphicsScene
26 {
27  Q_OBJECT
28  Q_ENUMS(ModeType)
29  Q_PROPERTY(ModeType mode READ mode WRITE setMode)
30  Q_PROPERTY(int ticks READ ticks WRITE setTicks)
31  Q_PROPERTY(double currentTime READ currentTime WRITE setCurrentTime)
32  Q_PROPERTY(double startTime READ startTime WRITE setStartTime)
33  Q_PROPERTY(double endTime READ endTime WRITE setEndTime)
34  Q_PROPERTY(bool interactive READ interactive WRITE setInteractive)
35 public:
43  enum ModeType
44  {
45  Real,
46  Sequence,
47  Custom
48  };
49 
50  pqAnimationModel(QGraphicsView* p = nullptr);
51  ~pqAnimationModel() override;
52 
56  int count();
60  pqAnimationTrack* track(int);
61 
66  pqAnimationTrack* addTrack(pqAnimationTrack* trackToAdd = nullptr);
70  void removeTrack(pqAnimationTrack* track);
71 
75  ModeType mode() const;
79  int ticks() const;
83  double currentTime() const;
87  double startTime() const;
91  double endTime() const;
95  double zoomStartTime() const;
99  double zoomEndTime() const;
103  double zoomFactor() const;
104 
108  bool interactive() const;
109 
110  QAbstractItemModel* header();
111  QAbstractItemModel* enabledHeader();
112 
113  void setRowHeight(int);
114  int rowHeight() const;
115 
119  void positionZoom(double zoomStartTime);
120 
124  const QList<double>& customTicks() const { return this->CustomTicks; }
125 
130  void setEnabledHeaderToolTip(const QString& val);
131  const QString& enabledHeaderToolTip() const { return this->EnabledHeaderToolTip; }
132 
133 public Q_SLOTS: // NOLINT(readability-redundant-access-specifiers)
134 
138  void setMode(ModeType);
142  void setTicks(int);
146  void setCurrentTime(double);
150  void setStartTime(double);
154  void setEndTime(double);
158  void setInteractive(bool);
163  void setTickMarks(int num, double* tick_marks);
168  void setTimePrecision(int precision);
169 
174  void setTimeNotation(const QChar& notation);
175 
179  void zoomTrack(pqAnimationTrack* track);
180 
181 Q_SIGNALS:
182  // emitted when a track is double clicked on
183  void trackSelected(pqAnimationTrack*);
184  // emitted when the current time was changed by this model
185  void currentTimeSet(double);
186  // emitted when the time of a keyframe was changed by this model
187  void keyFrameTimeChanged(pqAnimationTrack* track, pqAnimationKeyFrame* kf, int end, double time);
188  // emitted when the zoom factor or position are changed
189  void zoomChanged();
190 
191 protected Q_SLOTS:
192 
193  void resizeTracks();
194  void trackNameChanged();
195  void enabledChanged();
196 
197 protected: // NOLINT(readability-redundant-access-specifiers)
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 
210  QRectF drawTimeLabel(double time, const QRectF& row, QPainter* painter,
211  const QFontMetrics& metrics, QList<const QRectF*> const& priorities);
212 
213  void updateNewTime(QGraphicsSceneMouseEvent* mouseEvent);
214  bool hitTestCurrentTimePoly(const QPointF& pos);
215  pqAnimationTrack* hitTestTracks(const QPointF& pos);
216  pqAnimationKeyFrame* hitTestKeyFrame(pqAnimationTrack* t, const QPointF& pos);
217 
218  bool eventFilter(QObject* w, QEvent* e) override;
219 
220  void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* mouseEvent) override;
221  void mousePressEvent(QGraphicsSceneMouseEvent* mouseEvent) override;
222  void mouseMoveEvent(QGraphicsSceneMouseEvent* mouseEvent) override;
223  void mouseReleaseEvent(QGraphicsSceneMouseEvent* mouseEvent) override;
224  void wheelEvent(QGraphicsSceneWheelEvent* wheelEvent) override;
225 
226  double timeToNormalizedTime(double) const;
227  double normalizedTimeToTime(double) const;
228 
233  int currentTicks() const;
234 
235 private:
236  ModeType Mode = Real;
237  int Ticks = 10;
238  double CurrentTime = 0;
239  double StartTime = 0;
240  double EndTime = 1;
241  double ZoomStartTime = 0;
242  double ZoomEndTime = 1;
243  double ZoomFactor = 1;
244  int RowHeight;
245  bool Interactive = false;
246 
247  QList<double> CustomTicks;
248 
249  // vars to support interaction
250  bool CurrentTimeGrabbed = false;
251  double NewCurrentTime = 0;
252  double TimeLineGrabbedPosition = 0;
253  double OldZoomStartTime = 0;
254  bool TimeLineGrabbed = false;
255  pqAnimationTrack* CurrentTrackGrabbed = nullptr;
256  pqAnimationKeyFrame* CurrentKeyFrameGrabbed = nullptr;
257  int CurrentKeyFrameEdge = 0;
258  QPair<double, double> InteractiveRange;
259  QList<double> SnapHints;
260 
261  QList<pqAnimationTrack*> Tracks;
262 
263  // model that provides names of tracks
264  QStandardItemModel Header;
265 
266  // model that provides enabled state for the tracks.
267  QStandardItemModel EnabledHeader;
268 
269  pqCheckBoxPixMaps* CheckBoxPixMaps;
270 
271  QString EnabledHeaderToolTip = "Enable/Disable Track";
272 
273  int TimePrecision = 6;
274  QChar TimeNotation = 'g';
275 };
276 
277 #endif // pqAnimationModel_h
vtkParaViewDeprecation.h
pqTimeManagerWidget
pqTimeManagerWidget is the main widget for the Time Manager dock.
Definition: pqTimeManagerWidget.h:26
mode
mode
startTime
startTime
PARAVIEW_DEPRECATED_IN_5_12_0
#define PARAVIEW_DEPRECATED_IN_5_12_0(reason)
Definition: vtkParaViewDeprecation.h:100
pqCheckBoxPixMaps
pqCheckBoxPixMaps is a helper class that can used to create pixmaps for checkboxs in various states.
Definition: pqCheckBoxPixMaps.h:17