File indexing completed on 2024-05-19 04:54:25

0001 /*
0002     SPDX-FileCopyrightText: 2017 Jean-Baptiste Mardelle <jb@kdenlive.org>
0003     SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 */
0005 
0006 #pragma once
0007 
0008 #include "abstractcollapsiblewidget.h"
0009 #include "definitions.h"
0010 #include "utils/timecode.h"
0011 
0012 #include <QDomElement>
0013 #include <memory>
0014 
0015 class QLabel;
0016 class KDualAction;
0017 class KSqueezedTextLabel;
0018 class EffectItemModel;
0019 class AssetParameterView;
0020 class TimecodeDisplay;
0021 
0022 /**)
0023  * @class CollapsibleEffectView
0024  * @brief A container for the parameters of an effect
0025  * @author Jean-Baptiste Mardelle
0026  */
0027 class CollapsibleEffectView : public AbstractCollapsibleWidget
0028 {
0029     Q_OBJECT
0030 
0031 public:
0032     explicit CollapsibleEffectView(const QString &effectName, const std::shared_ptr<EffectItemModel> &effectModel, QSize frameSize, QWidget *parent = nullptr);
0033     ~CollapsibleEffectView() override;
0034     KSqueezedTextLabel *title;
0035 
0036     void updateTimecodeFormat();
0037     /** @brief Install event filter so that scrolling with mouse wheel does not change parameter value. */
0038     bool eventFilter(QObject *o, QEvent *e) override;
0039     /** @brief Update effect GUI to reflect parameted changes. */
0040     void updateWidget(const ItemInfo &info, const QDomElement &effect);
0041     /** @brief Returns effect xml. */
0042     QDomElement effect() const;
0043     /** @brief Returns effect xml with keyframe offset for saving. */
0044     QDomElement effectForSave() const;
0045     int groupIndex() const;
0046     bool isGroup() const override;
0047     int effectIndex() const;
0048     void setGroupIndex(int ix);
0049     void setGroupName(const QString &groupName);
0050     /** @brief Remove this effect from its group. */
0051     void removeFromGroup();
0052     QString infoString() const;
0053     bool isActive() const;
0054     bool isEnabled() const;
0055     /** @brief Show / hide up / down buttons. */
0056     void adjustButtons(int ix, int max);
0057     /** @brief Returns this effect's monitor scene type if any is needed. */
0058     MonitorSceneType needsMonitorEffectScene() const;
0059     /** @brief Import keyframes from a clip's data. */
0060     void setKeyframes(const QString &tag, const QString &keyframes);
0061     /** @brief Pass frame size info (dar, etc). */
0062     void updateFrameInfo();
0063     /** @brief Select active keyframe. */
0064     void setActiveKeyframe(int kf);
0065     /** @brief Returns true if effect can be moved (false for speed effect). */
0066     bool isMovable() const;
0067     /** @brief Returns the effect in xml format for saving. */
0068     QDomDocument toXml() const;
0069     /** @brief Update monitor scene depending on effect enabled state. */
0070     void updateScene();
0071     void updateInOut(QPair<int, int> inOut, bool withUndo);
0072     void slotNextKeyframe();
0073     void slotPreviousKeyframe();
0074     void addRemoveKeyframe();
0075     /** @brief Used to pass a standard action like copy or paste to the effect stack widget */
0076     void sendStandardCommand(int command);
0077 
0078 public Q_SLOTS:
0079     void slotSyncEffectsPos(int pos);
0080     /** @brief Enable / disable an effect. */
0081     void slotDisable(bool disable);
0082     /** @brief Restrict an effec to an in/out point region, of full length. */
0083     void switchInOut(bool checked);
0084     void slotResetEffect();
0085     void importKeyframes(const QString &keyframes);
0086     void slotActivateEffect(bool active);
0087     void updateHeight();
0088     /** @brief Should we block wheel event (if parent is a view with scrollbar) */
0089     void blockWheelEvent(bool block);
0090     /** @brief Switch between collapsed/expanded state */
0091     void switchCollapsed(int row);
0092     /** @brief Open a save effect dialog */
0093     void slotSaveEffect();
0094 
0095 private Q_SLOTS:
0096     void setWidgetHeight(qreal value);
0097     void enableView(bool enabled);
0098     void enableHideKeyframes(bool enabled);
0099     void slotSwitch(bool expand);
0100     void slotDeleteEffect();
0101     void slotEffectUp();
0102     void slotEffectDown();
0103     void slotCreateGroup();
0104     void slotCreateRegion();
0105     void slotUnGroup();
0106     /** @brief A sub effect parameter was changed */
0107     void slotUpdateRegionEffectParams(const QDomElement & /*old*/, const QDomElement & /*e*/, int /*ix*/);
0108     void prepareImportClipKeyframes();
0109     void updateEffectZone();
0110     void slotHideKeyframes(bool hide);
0111 
0112 private:
0113     AssetParameterView *m_view;
0114     std::shared_ptr<EffectItemModel> m_model;
0115     KDualAction *m_collapse;
0116     QList<CollapsibleEffectView *> m_subParamWidgets;
0117     QDomElement m_effect;
0118     ItemInfo m_itemInfo;
0119     QDomElement m_original_effect;
0120     QList<QDomElement> m_subEffects;
0121     QMenu *m_menu;
0122     bool m_isMovable;
0123     bool m_blockWheel;
0124     /** @brief The add group action. */
0125     QAction *m_groupAction;
0126     KDualAction *m_enabledButton;
0127     KDualAction *m_keyframesButton;
0128     QAction *m_inOutButton;
0129     QLabel *m_colorIcon;
0130     QPixmap m_iconPix;
0131     QPoint m_dragStart;
0132     TimecodeDisplay *m_inPos;
0133     TimecodeDisplay *m_outPos;
0134     bool m_dragging;
0135 
0136 protected:
0137     void mouseDoubleClickEvent(QMouseEvent *event) override;
0138     void mousePressEvent(QMouseEvent *event) override;
0139     void mouseMoveEvent(QMouseEvent *e) override;
0140     void wheelEvent(QWheelEvent *e) override;
0141     void mouseReleaseEvent(QMouseEvent *event) override;
0142     void dragEnterEvent(QDragEnterEvent *event) override;
0143     void dragLeaveEvent(QDragLeaveEvent *event) override;
0144     void dropEvent(QDropEvent *event) override;
0145 
0146 Q_SIGNALS:
0147     void parameterChanged(const QDomElement &, const QDomElement &, int);
0148     void syncEffectsPos(int);
0149     void effectStateChanged(bool, int ix, MonitorSceneType effectNeedsMonitorScene);
0150     void deleteEffect(std::shared_ptr<EffectItemModel> effect);
0151     void moveEffect(int destRow, std::shared_ptr<EffectItemModel> effect);
0152     void checkMonitorPosition(int);
0153     void seekTimeline(int);
0154     /** @brief Start an MLT filter job on this clip. */
0155     void startFilterJob(QMap<QString, QString> &, QMap<QString, QString> &, QMap<QString, QString> &);
0156     /** @brief An effect was reset, trigger param reload. */
0157     void resetEffect(int ix);
0158     /** @brief Ask for creation of a group. */
0159     void createGroup(std::shared_ptr<EffectItemModel> effectModel);
0160     void unGroup(CollapsibleEffectView *);
0161     void createRegion(int, const QUrl &);
0162     void deleteGroup(const QDomDocument &);
0163     void importClipKeyframes(GraphicsRectItem, ItemInfo, QDomElement, const QMap<QString, QString> &keyframes = QMap<QString, QString>());
0164     void switchHeight(std::shared_ptr<EffectItemModel> model, int height);
0165     void startDrag(const QPixmap, const QString assetId, ObjectId sourceObject, int row);
0166     void activateEffect(int row);
0167     void showEffectZone(ObjectId id, QPair<int, int> inOut, bool checked);
0168     void refresh();
0169 };