File indexing completed on 2024-05-12 04:52:48
0001 /* 0002 SPDX-FileCopyrightText: 2011 Till Theato <root@ttill.de> 0003 SPDX-FileCopyrightText: 2017 Nicolas Carion 0004 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #pragma once 0008 0009 #include "assets/keyframes/model/keyframemodel.hpp" 0010 #include "assets/keyframes/model/keyframemodellist.hpp" 0011 #include <QWidget> 0012 #include <memory> 0013 0014 class KeyframeModelList; 0015 0016 class KeyframeView : public QWidget 0017 { 0018 Q_OBJECT 0019 0020 public: 0021 explicit KeyframeView(std::shared_ptr<KeyframeModelList> model, int duration, QWidget *parent = nullptr); 0022 ~KeyframeView() override; 0023 void setDuration(int duration); 0024 const QString getAssetId(); 0025 /** @brief Copy a keyframe parameter to selected keyframes. */ 0026 void copyCurrentValue(const QModelIndex &ix, const QString ¶mName); 0027 /** @brief Returns the index (position in model) of the currently selected keyframes. */ 0028 const QVector<int> selectedKeyframesIndexes(); 0029 0030 public Q_SLOTS: 0031 /** @brief moves the current position*/ 0032 void slotSetPosition(int pos, bool isInRange); 0033 /** @brief remove the keyframe at given position 0034 If pos is negative, we remove keyframe at current position 0035 */ 0036 void slotRemoveKeyframe(const QVector<int> &positions); 0037 /** @brief Add a keyframe with given parameter value at given pos. 0038 If pos is negative, then keyframe is added at current position 0039 */ 0040 bool slotAddKeyframe(int pos = -1); 0041 /** @brief Duplicate selected keyframe at cursor position 0042 */ 0043 void slotDuplicateKeyframe(); 0044 /** @brief If there is a keyframe at current position, it is removed. 0045 Otherwise, we add a new one with given value. 0046 */ 0047 void slotAddRemove(); 0048 void slotGoToNext(); 0049 void slotGoToPrev(); 0050 void slotModelChanged(); 0051 void slotModelDisplayChanged(); 0052 void slotEditType(int type, const QPersistentModelIndex &index); 0053 /** @brief Emit initial info for monitor. */ 0054 void initKeyframePos(); 0055 /** @brief Move selected keyframe to cursor position. */ 0056 void slotCenterKeyframe(); 0057 0058 protected: 0059 void paintEvent(QPaintEvent *event) override; 0060 void mousePressEvent(QMouseEvent *event) override; 0061 void mouseReleaseEvent(QMouseEvent *event) override; 0062 void mouseMoveEvent(QMouseEvent *event) override; 0063 void mouseDoubleClickEvent(QMouseEvent *event) override; 0064 void wheelEvent(QWheelEvent *event) override; 0065 0066 private: 0067 std::shared_ptr<KeyframeModelList> m_model; 0068 int m_duration; 0069 int m_position; 0070 int m_currentKeyframeOriginal; 0071 QVector<int> m_selectedKeyframes; 0072 int m_hoverKeyframe; 0073 int m_lineHeight; 0074 int m_zoomHeight; 0075 int m_offset; 0076 double m_scale; 0077 double m_zoomFactor; 0078 double m_zoomStart; 0079 bool m_moveKeyframeMode; 0080 bool m_keyframeZonePress; 0081 int m_clickPoint; 0082 int m_clickEnd; 0083 /** @brief The zoom factor (start, end - between 0 and 1) */ 0084 QPointF m_zoomHandle; 0085 QPointF m_lastZoomHandle; 0086 /** @brief Mouse is the zoom left handle */ 0087 bool m_hoverZoomIn; 0088 /** @brief Mouse is the zoom right handle */ 0089 bool m_hoverZoomOut; 0090 /** @brief Mouse is over the zoom bar */ 0091 bool m_hoverZoom; 0092 /** @brief the x click position offset for moving zoom */ 0093 double m_clickOffset; 0094 int m_size; 0095 0096 QColor m_colSelected; 0097 QColor m_colKeyframe; 0098 QColor m_colKeyframeBg; 0099 QMetaObject::Connection m_centerConnection; 0100 0101 Q_SIGNALS: 0102 void seekToPos(int pos); 0103 void atKeyframe(bool isKeyframe, bool singleKeyframe); 0104 void modified(); 0105 void activateEffect(); 0106 void updateKeyframeOriginal(int pos); 0107 };