1 /*
2     SPDX-FileCopyrightText: 2011 Till Theato <root@ttill.de>
3     SPDX-FileCopyrightText: 2017 Nicolas Carion
4     SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
5 */
6 
7 #ifndef KEYFRAMEWIDGET_H
8 #define KEYFRAMEWIDGET_H
9 
10 #include "abstractparamwidget.hpp"
11 
12 #include "definitions.h"
13 #include <QPersistentModelIndex>
14 #include <memory>
15 #include <unordered_map>
16 
17 class AssetParameterModel;
18 class DoubleWidget;
19 class KeyframeView;
20 class KeyframeModelList;
21 class QVBoxLayout;
22 class QToolButton;
23 class QToolBar;
24 class TimecodeDisplay;
25 class KSelectAction;
26 class KeyframeMonitorHelper;
27 
28 class KeyframeWidget : public AbstractParamWidget
29 {
30     Q_OBJECT
31 
32 public:
33     explicit KeyframeWidget(std::shared_ptr<AssetParameterModel> model, QModelIndex index, QSize frameSize, QWidget *parent = nullptr);
34     ~KeyframeWidget() override;
35 
36     /** @brief Add a new parameter to be managed using the same keyframe viewer */
37     void addParameter(const QPersistentModelIndex &index);
38     int getPosition() const;
39     /** @brief Returns the monitor scene required for this asset
40      */
41     MonitorSceneType requiredScene() const;
42     void updateTimecodeFormat();
43     /** @brief Show / hide keyframe related widgets
44      */
45     void showKeyframes(bool enable);
46     /** @brief Returns true if keyframes options are visible
47      */
48     bool keyframesVisible() const;
49     void resetKeyframes();
50 
51 public slots:
52     void slotRefresh() override;
53     /** @brief initialize qml overlay
54      */
55     void slotInitMonitor(bool active) override;
56 
57 public slots:
58     void slotSetPosition(int pos = -1, bool update = true);
59 
60 private slots:
61     /** @brief Update the value of the widgets to reflect keyframe change */
62     void slotRefreshParams();
63     void slotAtKeyframe(bool atKeyframe, bool singleKeyframe);
64     void slotEditKeyframeType(QAction *action);
65     void slotUpdateKeyframesFromMonitor(const QPersistentModelIndex &index, const QVariant &res);
66     void slotCopyKeyframes();
67     void slotCopyValueAtCursorPos();
68     void slotImportKeyframes();
69     void slotRemoveNextKeyframes();
70     void slotSeekToKeyframe(int ix);
71     void monitorSeek(int pos);
72     void disconnectEffectStack();
73 
74 private:
75     QVBoxLayout *m_lay;
76     QToolBar *m_toolbar;
77     std::shared_ptr<KeyframeModelList> m_keyframes;
78     KeyframeView *m_keyframeview;
79     KeyframeMonitorHelper *m_monitorHelper;
80     QToolButton *m_buttonAddDelete;
81     QToolButton *m_buttonCenter;
82     QToolButton *m_buttonCopy;
83     QToolButton *m_buttonApply;
84     KSelectAction *m_selectType;
85     TimecodeDisplay *m_time;
86     MonitorSceneType m_neededScene;
87     QSize m_sourceFrameSize;
88     void connectMonitor(bool active);
89     std::unordered_map<QPersistentModelIndex, QWidget *> m_parameters;
90     int m_baseHeight;
91     int m_addedHeight;
92 
93 signals:
94     void addIndex(QPersistentModelIndex ix);
95     void setKeyframes(const QString &);
96     void updateEffectKeyframe(bool);
97     void goToNext();
98     void goToPrevious();
99     void addRemove();
100 };
101 
102 #endif
103