You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
2.9 KiB
99 lines
2.9 KiB
#pragma once |
|
|
|
#include <QWidget> |
|
#include <QImage> |
|
#include <QString> |
|
#include <QPoint> |
|
#include <QTimer> |
|
|
|
class QSlider; |
|
class QPushButton; |
|
class QLabel; |
|
class VideoPlayerEngine; |
|
|
|
/* Виджет отрисовки кадра (aspect-fit на чёрном фоне). */ |
|
class VideoRenderWidget : public QWidget { |
|
Q_OBJECT |
|
public: |
|
explicit VideoRenderWidget(QWidget* parent = nullptr); |
|
void setFrame(const QImage& img); |
|
void clearFrame(); |
|
|
|
protected: |
|
void paintEvent(QPaintEvent* event) override; |
|
|
|
private: |
|
QImage m_frame; |
|
}; |
|
|
|
/* Отдельное окно плеера без рамки: drag-перенос, dblclick/Alt+Enter — fullscreen, |
|
* Esc — выход/закрытие, timeline + play/pause/close. */ |
|
class VideoPlayerWindow : public QWidget { |
|
Q_OBJECT |
|
public: |
|
explicit VideoPlayerWindow(QWidget* parent = nullptr); |
|
~VideoPlayerWindow() override; |
|
|
|
void playFile(const QString& path); |
|
|
|
signals: |
|
void closed(); |
|
|
|
protected: |
|
void keyPressEvent(QKeyEvent* event) override; |
|
void mousePressEvent(QMouseEvent* event) override; |
|
void mouseMoveEvent(QMouseEvent* event) override; |
|
void mouseReleaseEvent(QMouseEvent* event) override; |
|
void mouseDoubleClickEvent(QMouseEvent* event) override; |
|
void closeEvent(QCloseEvent* event) override; |
|
void resizeEvent(QResizeEvent* event) override; |
|
bool eventFilter(QObject* obj, QEvent* event) override; |
|
|
|
private slots: |
|
void onEngineOpened(int width, int height, qint64 durationMs, bool hasAudio); |
|
void onPositionChanged(qint64 ms); |
|
void onStateChanged(int state); |
|
void onError(const QString& msg); |
|
void onFramePresented(); |
|
void onSliderPressed(); |
|
void onSliderReleased(); |
|
void onPlayPause(); |
|
void onClose(); |
|
void onFinished(); |
|
void showControls(); |
|
void hideControls(); |
|
|
|
private: |
|
enum ResizeMode { |
|
ResizeNone = 0, |
|
ResizeLeft, ResizeRight, ResizeTop, ResizeBottom, |
|
ResizeTopLeft, ResizeTopRight, ResizeBottomLeft, ResizeBottomRight |
|
}; |
|
|
|
void toggleFullscreen(); |
|
void updateTimeLabels(qint64 posMs); |
|
void setControlsVisible(bool visible); |
|
QSize fitWindowSize(int vw, int vh) const; |
|
ResizeMode hitTestResize(const QPoint& localPos) const; |
|
void updateResizeCursor(const QPoint& localPos); |
|
void applyResize(const QPoint& globalPos); |
|
void beginResize(ResizeMode m, const QPoint& globalPos); |
|
|
|
VideoRenderWidget* m_render = nullptr; |
|
QWidget* m_controls = nullptr; |
|
QSlider* m_slider = nullptr; |
|
QPushButton* m_playBtn = nullptr; |
|
QPushButton* m_closeBtn = nullptr; |
|
QLabel* m_timeLabel = nullptr; |
|
VideoPlayerEngine* m_engine = nullptr; |
|
|
|
bool m_fullscreen = false; |
|
bool m_sliderDragging = false; |
|
bool m_dragging = false; |
|
QPoint m_dragStart; |
|
QPoint m_windowStart; |
|
ResizeMode m_resizeMode = ResizeNone; |
|
QRect m_resizeStartGeom; |
|
QPoint m_resizeStartGlobal; |
|
QTimer* m_hideTimer = nullptr; |
|
};
|
|
|