File indexing completed on 2024-04-28 04:51:18

0001 /*
0002     SPDX-FileCopyrightText: 2017 Nicolas Carion
0003     SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 */
0005 
0006 #pragma once
0007 
0008 #include "definitions.h"
0009 #include <QModelIndex>
0010 #include <QMutex>
0011 #include <QVector>
0012 #include <QWidget>
0013 #include <memory>
0014 
0015 class QVBoxLayout;
0016 class QMenu;
0017 class QActionGroup;
0018 class AbstractParamWidget;
0019 class AssetParameterModel;
0020 class KeyframeWidget;
0021 
0022 /** @class AssetParameterView
0023     @brief This class is the view for a list of parameters.
0024  */
0025 class AssetParameterView : public QWidget
0026 {
0027     Q_OBJECT
0028 
0029 public:
0030     AssetParameterView(QWidget *parent = nullptr);
0031 
0032     /** Sets the model to be displayed by current view */
0033     virtual void setModel(const std::shared_ptr<AssetParameterModel> &model, QSize frameSize, bool addSpacer = false);
0034 
0035     /** Set the widget to display no model (this yield ownership on the smart-ptr)*/
0036     void unsetModel();
0037 
0038     /** Returns the preferred widget height */
0039     int contentHeight() const;
0040 
0041     /** Returns the type of monitor overlay required by this effect */
0042     MonitorSceneType needsMonitorEffectScene() const;
0043 
0044     /** Returns true is the effect can use keyframes */
0045     bool keyframesAllowed() const;
0046     /** Returns true is the keyframes should be hidden on first opening*/
0047     bool modelHideKeyframes() const;
0048     /** Returns the preset menu to be embedded in toolbars */
0049     QMenu *presetMenu();
0050 
0051 public Q_SLOTS:
0052     void slotRefresh();
0053     void toggleKeyframes(bool enable);
0054     /** Reset all parameter values to default */
0055     void resetValues();
0056     /** Save all parameters to a preset */
0057     void slotSavePreset(QString presetName = QString());
0058     /** Save all parameters to a preset */
0059     void slotLoadPreset();
0060     void slotUpdatePreset();
0061     void slotDeleteCurrentPreset();
0062     void slotDeletePreset(const QString &presetName);
0063 
0064 protected:
0065     /** @brief This is a handler for the dataChanged slot of the model.
0066         It basically instructs the widgets in the given range to be refreshed */
0067     void refresh(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
0068 
0069     QVBoxLayout *m_lay;
0070     /** @brief Protect from concurrent operations
0071      **/
0072     QMutex m_lock;
0073     std::shared_ptr<AssetParameterModel> m_model;
0074     std::vector<AbstractParamWidget *> m_widgets;
0075     KeyframeWidget *m_mainKeyframeWidget{nullptr};
0076     QMenu *m_presetMenu;
0077     std::shared_ptr<QActionGroup> m_presetGroup;
0078 
0079 private:
0080     QVector<QPair<QString, QVariant>> getDefaultValues() const;
0081 
0082 private Q_SLOTS:
0083     /** @brief Apply a change of parameter sent by the view
0084        @param index is the index corresponding to the modified param
0085        @param value is the new value of the parameter
0086        @param storeUndo: if true, an undo object is created
0087     */
0088     void commitChanges(const QModelIndex &index, const QString &value, bool storeUndo);
0089     void commitMultipleChanges(const QList<QModelIndex> &indexes, const QStringList &values, bool storeUndo);
0090     void disableCurrentFilter(bool disable);
0091 
0092 Q_SIGNALS:
0093     void seekToPos(int);
0094     void initKeyframeView(bool active);
0095     /** @brief clear and refill the effect presets */
0096     void updatePresets(const QString &presetName = QString());
0097     void updateHeight();
0098     void activateEffect();
0099     void nextKeyframe();
0100     void previousKeyframe();
0101     void addRemoveKeyframe();
0102     /** @brief Used to pass a standard action like copy or paste to the effect stack widget */
0103     void sendStandardCommand(int command);
0104 };