1 /*
2     SPDX-FileCopyrightText: 2007-2009 Sergio Pistone <sergio_pistone@yahoo.com.ar>
3     SPDX-FileCopyrightText: 2010-2019 Mladen Milinkovic <max@smoothware.net>
4 
5     SPDX-License-Identifier: GPL-2.0-or-later
6 */
7 
8 #ifndef PLAYERWIDGET_H
9 #define PLAYERWIDGET_H
10 
11 #include "core/time.h"
12 #include "core/subtitle.h"
13 #include "core/subtitleline.h"
14 
15 #include <QExplicitlySharedDataPointer>
16 #include <QPoint>
17 #include <QWidget>
18 
19 QT_FORWARD_DECLARE_CLASS(QGridLayout)
20 QT_FORWARD_DECLARE_CLASS(QLabel)
21 QT_FORWARD_DECLARE_CLASS(QToolButton)
22 QT_FORWARD_DECLARE_CLASS(QSlider)
23 
24 class LayeredWidget;
25 class AttachableWidget;
26 class TimeEdit;
27 
28 namespace SubtitleComposer {
29 class TextOverlayWidget;
30 
31 class PlayerWidget : public QWidget
32 {
33 	Q_OBJECT
34 
35 public:
36 	PlayerWidget(QWidget *parent);
37 	virtual ~PlayerWidget();
38 
39 	void loadConfig();
40 	void saveConfig();
41 
fullScreenMode()42 	inline bool fullScreenMode() const { return m_fullScreenMode; }
43 	void setFullScreenMode(bool fullScreenMode);
44 
playingLine()45 	inline SubtitleLine * playingLine() { return m_playingLine; }
46 
47 	bool eventFilter(QObject *object, QEvent *event) override;
48 
49 	QWidget *infoSidebarWidget();
50 
51 	void pauseAfterPlayingLine(const SubtitleLine *line);
52 
53 public slots:
54 	void setSubtitle(Subtitle *subtitle = 0);
55 	void setTranslationMode(bool enabled);
56 	void setShowTranslation(bool showTranslation);
57 
58 	void increaseFontSize(int size = 1);
59 	void decreaseFontSize(int size = 1);
60 
61 signals:
62 	void playingLineChanged(SubtitleLine *line);
63 
64 protected:
65 	void timerEvent(QTimerEvent *event) override;
66 
67 private:
68 	static QToolButton * toolButton(QWidget *parent, const char *name);
69 	static QToolButton * createToolButton(QWidget *parent, const char *name, int size);
70 
71 	void updatePlayingLine(const Time &videoPosition);
72 	void setPlayingLine(SubtitleLine *line);
73 
74 	void updatePositionEditVisibility();
75 
76 private slots:
77 	void setPlayingLineFromVideo();
78 
79 	void onVolumeSliderMoved(int value);
80 	void onSeekSliderMoved(int value);
81 	void onPositionEditValueChanged(int position);
82 
83 	void onConfigChanged();
84 
85 	void onPlayerFileOpened(const QString &filePath);
86 	void onPlayerFileOpenError(const QString &filePath, const QString &reason);
87 	void onPlayerFileClosed();
88 	void onPlayerPlaybackError(const QString &errorMessage);
89 	void onPlayerPlaying();
90 	void onPlayerStopped();
91 	void onPlayerPositionChanged(double seconds);
92 	void onPlayerLengthChanged(double seconds);
93 	void onPlayerFramesPerSecondChanged(double fps);
94 	void onPlayerPlaybackRateChanged(double rate);
95 	void onPlayerVolumeChanged(double volume);
96 
97 	void onPlayerLeftClicked(const QPoint &point);
98 	void onPlayerRightClicked(const QPoint &point);
99 	void onPlayerDoubleClicked(const QPoint &point);
100 
101 private:
102 	QExplicitlySharedDataPointer<Subtitle> m_subtitle;
103 	bool m_translationMode;
104 	bool m_showTranslation;
105 	SubtitleLine *m_playingLine = nullptr;
106 	SubtitleLine *m_prevLine = nullptr;
107 	SubtitleLine *m_nextLine = nullptr;
108 
109 	const SubtitleLine *m_pauseAfterPlayingLine;
110 
111 	int m_fullScreenTID;
112 	bool m_fullScreenMode;
113 
114 	QGridLayout *m_mainLayout;
115 
116 	LayeredWidget *m_layeredWidget;
117 	AttachableWidget *m_fullScreenControls;
118 
119 	QSlider *m_seekSlider;
120 	QSlider *m_fsSeekSlider;
121 	QLabel *m_fsPositionLabel;
122 	QString m_lengthString;
123 
124 	QSlider *m_volumeSlider;
125 	QSlider *m_fsVolumeSlider;
126 
127 	QWidget *m_infoControlsGroupBox;
128 	QLabel *m_positionLabel;
129 	TimeEdit *m_positionEdit;
130 	bool m_showPositionTimeEdit;
131 	QLabel *m_lengthLabel;
132 	QLabel *m_fpsLabel;
133 	QLabel *m_rateLabel;
134 
135 	QPoint m_savedCursorPos;                // for hiding the mouse on full screen mode
136 	QPoint m_currentCursorPos;
137 };
138 }
139 #endif
140