File indexing completed on 2024-04-21 04:52:23

0001 /*
0002     SPDX-FileCopyrightText: 2017 Jean-Baptiste Mardelle
0003     SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 */
0005 
0006 #pragma once
0007 
0008 #include "timeline2/model/timelineitemmodel.hpp"
0009 #include <QQuickWidget>
0010 
0011 class ThumbnailProvider;
0012 class TimelineController;
0013 class QSortFilterProxyModel;
0014 class MonitorProxy;
0015 class QMenu;
0016 class QActionGroup;
0017 
0018 class TimelineWidget : public QQuickWidget
0019 {
0020     Q_OBJECT
0021 
0022 public:
0023     TimelineWidget(const QUuid uuid, QWidget *parent = Q_NULLPTR);
0024     ~TimelineWidget() override;
0025     /** @brief Sets the model shown by this widget */
0026     void setModel(const std::shared_ptr<TimelineItemModel> &model, MonitorProxy *proxy);
0027     /** @brief Load the marker model (created after model ins instanciated) */
0028     void loadMarkerModel();
0029 
0030     /** @brief Return the project's tractor
0031      */
0032     Mlt::Tractor *tractor();
0033     TimelineController *controller();
0034     std::shared_ptr<TimelineItemModel> model();
0035     void setTool(ToolType::ProjectTool tool);
0036     ToolType::ProjectTool activeTool();
0037     QPair<int, int> getAvTracksCount() const;
0038     /** @brief calculate zoom level for a scale */
0039     int zoomForScale(double value) const;
0040     /** @brief Give keyboard focus to timeline qml */
0041     void focusTimeline();
0042     /** @brief Initiate timeline clip context menu */
0043     void setTimelineMenu(QMenu *clipMenu, QMenu *compositionMenu, QMenu *timelineMenu, QMenu *guideMenu, QMenu *timelineRulerMenu, QAction *editGuideAction, QMenu *headerMenu, QMenu *thumbsMenu, QMenu *subtitleClipMenu);
0044     bool loading;
0045     void connectSubtitleModel(bool firstConnect);
0046     void unsetModel();
0047     const QUuid &getUuid() const;
0048     bool hasSubtitles() const;
0049 
0050 protected:
0051     void mousePressEvent(QMouseEvent *event) override;
0052     void focusInEvent(QFocusEvent *event) override;
0053     bool eventFilter(QObject *object, QEvent *event) override;
0054 
0055 public Q_SLOTS:
0056     void slotChangeZoom(int value, bool zoomOnMouse);
0057     void slotFitZoom();
0058     /** @brief Center timeline view on current timeline cursor position */
0059     void slotCenterView();
0060     void zoneUpdated(const QPoint &zone);
0061     void zoneUpdatedWithUndo(const QPoint &oldZone, const QPoint &newZone);
0062     /** @brief Favorite effects have changed, reload model for context menu */
0063     void updateEffectFavorites();
0064     /** @brief Favorite transitions have changed, reload model for context menu */
0065     void updateTransitionFavorites();
0066     /** @brief Bin clip drag ended, make sure we correctly processed the drop */
0067     void endDrag();
0068     /** @brief Start an audio recording on track tid*/
0069     void startAudioRecord(int tid);
0070     void stopAudioRecord();
0071     /** @brief Show menu to switch track target audio stream */
0072     void showTargetMenu(int tid = -1);
0073     /** @brief Focus qml item under mouse in timeline, for example after app looses focus or a menu showed up*/
0074     void regainFocus();
0075 
0076 private Q_SLOTS:
0077     void slotUngrabHack();
0078     void slotResetContextPos(QAction *);
0079     void showClipMenu(int cid);
0080     void showMixMenu(int cid);
0081     void showCompositionMenu();
0082     void showTimelineMenu();
0083     void showRulerMenu();
0084     void showHeaderMenu();
0085     void showSubtitleClipMenu();
0086 
0087 private:
0088     TimelineController *m_proxy;
0089     QMenu *m_timelineClipMenu;
0090     QMenu *m_timelineMixMenu;
0091     QMenu *m_timelineCompositionMenu;
0092     QMenu *m_timelineMenu;
0093     QMenu *m_timelineRulerMenu;
0094     QMenu *m_guideMenu;
0095     QMenu *m_headerMenu;
0096     QMenu *m_targetsMenu;
0097     QActionGroup *m_targetsGroup{nullptr};
0098     QMenu *m_thumbsMenu;
0099     QMenu *m_favEffects;
0100     QMenu *m_favCompositions;
0101     QAction *m_editGuideAcion;
0102     QMenu *m_timelineSubtitleClipMenu;
0103     static const int comboScale[];
0104     std::unique_ptr<QSortFilterProxyModel> m_sortModel;
0105     /** @brief Keep last scale before fit to restore it on second click */
0106     double m_prevScale;
0107     /** @brief Keep last scroll position before fit to restore it on second click */
0108     int m_scrollPos;
0109     /** @brief Returns an alphabetically sorted list of favorite effects or transitions */
0110     const QMap<QString, QString> sortedItems(const QStringList &items, bool isTransition);
0111     QPoint m_clickPos;
0112     QUuid m_uuid;
0113 
0114 Q_SIGNALS:
0115     void focusProjectMonitor();
0116     void zoneMoved(const QPoint &zone);
0117 };