File indexing completed on 2025-02-23 04:35:41
0001 /* 0002 SPDX-FileCopyrightText: 2010-2022 Mladen Milinkovic <max@smoothware.net> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef WAVEFORMWIDGET_H 0008 #define WAVEFORMWIDGET_H 0009 0010 #include "core/time.h" 0011 #include "core/subtitle.h" 0012 #include "gui/waveform/wavesubtitle.h" 0013 #include "videoplayer/waveformat.h" 0014 0015 #include <QExplicitlySharedDataPointer> 0016 #include <QTimer> 0017 #include <QWidget> 0018 0019 #include <list> 0020 0021 QT_FORWARD_DECLARE_CLASS(QRegion) 0022 QT_FORWARD_DECLARE_CLASS(QPolygon) 0023 QT_FORWARD_DECLARE_CLASS(QProgressBar) 0024 QT_FORWARD_DECLARE_CLASS(QToolButton) 0025 QT_FORWARD_DECLARE_CLASS(QScrollBar) 0026 QT_FORWARD_DECLARE_CLASS(QPropertyAnimation) 0027 QT_FORWARD_DECLARE_CLASS(QToolButton) 0028 QT_FORWARD_DECLARE_CLASS(QBoxLayout) 0029 0030 namespace SubtitleComposer { 0031 class WaveBuffer; 0032 class WaveRenderer; 0033 struct WaveZoomData; 0034 0035 class WaveformWidget : public QWidget 0036 { 0037 Q_OBJECT 0038 0039 public: 0040 explicit WaveformWidget(QWidget *parent = nullptr); 0041 virtual ~WaveformWidget(); 0042 0043 void setZoom(quint32 val); 0044 inline quint32 zoom() const { return m_zoom; } 0045 0046 inline double windowSize() const { return (m_timeEnd - m_timeStart).toMillis(); } 0047 double windowSizeInner(double *autoScrollPadding = nullptr) const; 0048 0049 QWidget *progressWidget(); 0050 0051 QWidget *toolbarWidget(); 0052 0053 inline bool autoScroll() const { return m_autoScroll; } 0054 0055 inline const Time & rightMousePressTime() const { return m_timeRMBPress; } 0056 inline const Time & rightMouseReleaseTime() const { return m_timeRMBRelease; } 0057 0058 SubtitleLine * subtitleLineAtMousePosition() const; 0059 0060 inline const Time & rightMouseSoonerTime() const { 0061 return m_timeRMBPress > m_timeRMBRelease ? m_timeRMBRelease : m_timeRMBPress; 0062 } 0063 inline const Time & rightMouseLaterTime() const { 0064 return m_timeRMBPress > m_timeRMBRelease ? m_timeRMBPress : m_timeRMBRelease; 0065 } 0066 0067 inline void zoomIn() { setZoom(zoom() / 2); } 0068 inline void zoomOut() { setZoom(zoom() * 2); } 0069 0070 signals: 0071 void doubleClick(Time time); 0072 void middleMouseDown(Time time); 0073 void middleMouseMove(Time time); 0074 void middleMouseUp(Time time); 0075 void dragStart(SubtitleLine *line, DragPosition dragPosition); 0076 void dragEnd(SubtitleLine *line, DragPosition dragPosition); 0077 0078 public slots: 0079 void setSubtitle(Subtitle *subtitle = 0); 0080 void setAudioStream(const QString &mediaFile, int audioStream); 0081 void setNullAudioStream(quint64 msecVideoLength); 0082 void clearAudioStream(); 0083 void setAutoscroll(bool autoscroll); 0084 void setScrollPosition(double milliseconds); 0085 void onSubtitleChanged(); 0086 void setTranslationMode(bool enabled); 0087 void setShowTranslation(bool showTranslation); 0088 0089 private slots: 0090 void onPlayerPositionChanged(double seconds); 0091 void onScrollBarValueChanged(int value); 0092 void onHoverScrollTimeout(); 0093 0094 private: 0095 void leaveEvent(QEvent *event) override; 0096 bool eventFilter(QObject *obj, QEvent *event) override; 0097 void showContextMenu(QPoint pos); 0098 0099 void onWaveformResize(quint32 span); 0100 void onWaveformRotate(bool vertical); 0101 0102 void handleTimeUpdate(quint32 msSpan); 0103 0104 QToolButton * createToolButton(const QString &actionName, int iconSize=16); 0105 void updateActions(); 0106 void updateVisibleLines(); 0107 Time timeAt(int y); 0108 DragPosition draggableAt(double posTime, WaveSubtitle **result); 0109 bool scrollToTime(const Time &time, bool scrollToPage); 0110 0111 void updatePointerTime(int pos); 0112 bool mousePress(int pos, Qt::MouseButton button); 0113 bool mouseRelease(int pos, Qt::MouseButton button, const QPointF &globalPos); 0114 0115 private: 0116 QString m_mediaFile; 0117 int m_streamIndex; 0118 QExplicitlySharedDataPointer<Subtitle> m_subtitle; 0119 0120 Time m_timeStart; 0121 Time m_timeCurrent; 0122 Time m_timeEnd; 0123 quint32 m_zoom; // reflects samples/pixel 0124 0125 Time m_timeRMBPress; 0126 Time m_timeRMBRelease; 0127 bool m_RMBDown; 0128 0129 bool m_MMBDown; 0130 0131 QScrollBar *m_scrollBar; 0132 QPropertyAnimation *m_scrollAnimation; 0133 bool m_autoScroll; 0134 bool m_autoScrollPause; 0135 double m_hoverScrollAmount; 0136 QTimer m_hoverScrollTimer; 0137 0138 QWidget *m_toolbar; 0139 0140 WaveRenderer *m_waveformGraphics; 0141 0142 QWidget *m_progressWidget; 0143 QProgressBar *m_progressBar; 0144 0145 std::list<WaveSubtitle *> m_visibleLines; 0146 bool m_visibleLinesDirty; 0147 0148 WaveSubtitle *m_draggedLine; 0149 0150 QBoxLayout *m_widgetLayout; 0151 0152 Time m_pointerTime; 0153 0154 QToolButton *m_btnZoomIn; 0155 QToolButton *m_btnZoomOut; 0156 QToolButton *m_btnAutoScroll; 0157 0158 bool m_translationMode; 0159 bool m_showTranslation; 0160 0161 friend class WaveBuffer; 0162 WaveBuffer *m_wfBuffer; 0163 0164 WaveZoomData **m_zoomData; 0165 quint32 m_zoomDataLen; 0166 0167 friend class WaveRenderer; 0168 }; 0169 } 0170 #endif