CuteLogger
Fast and simple logging solution for Qt based applications
hdrpreviewwindow.h
1/*
2 * Copyright (c) 2026 Meltytech, LLC
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef HDRPREVIEWWINDOW_H
19#define HDRPREVIEWWINDOW_H
20
21#include "videowidget.h"
22#include <QKeyEvent>
23#include <QPointer>
24#include <QQuickView>
25#include <QRect>
26#include <QResizeEvent>
27#include <QString>
28#include <QTimer>
29#include <QVideoFrame>
30#include <QVideoSink>
31
32class HdrPreviewWindow : public QQuickView
33{
34 Q_OBJECT
35 Q_PROPERTY(float hdrGain READ hdrGain NOTIFY hdrGainChanged)
36 Q_PROPERTY(int hdrTransferMode READ hdrTransferMode NOTIFY hdrTransferModeChanged)
37 Q_PROPERTY(int displayPeakNits READ displayPeakNits WRITE setDisplayPeakNits NOTIFY
38 displayPeakNitsChanged)
39 Q_PROPERTY(int contentPeakNits READ contentPeakNits WRITE setContentPeakNits NOTIFY
40 contentPeakNitsChanged)
41 Q_PROPERTY(bool toneMapping READ toneMapping WRITE setToneMapping NOTIFY toneMappingChanged)
42 Q_PROPERTY(bool playing READ isPlaying NOTIFY playingChanged)
43 Q_PROPERTY(bool fullScreen READ isFullScreen NOTIFY fullScreenChanged)
44 Q_PROPERTY(int videoPosition READ videoPosition NOTIFY videoPositionChanged)
45 Q_PROPERTY(int videoDuration READ videoDuration NOTIFY videoDurationChanged)
46 Q_PROPERTY(QString positionText READ positionText NOTIFY videoPositionChanged)
47 Q_PROPERTY(QString durationText READ durationText NOTIFY videoDurationChanged)
48
49public:
50 explicit HdrPreviewWindow(QWindow *parent = nullptr);
51 ~HdrPreviewWindow();
52
53 Q_INVOKABLE void setVideoSink(QVideoSink *sink);
54 float hdrGain() const { return m_hdrGain; }
55 int hdrTransferMode() const { return static_cast<int>(m_hdrTransfer); }
56 bool isHdrAvailable() const;
57 int displayPeakNits() const { return m_displayPeakNits; }
58 void setDisplayPeakNits(int nits);
59 int contentPeakNits() const { return m_contentPeakNits; }
60 void setContentPeakNits(int nits);
61 bool toneMapping() const { return m_toneMapping; }
62 void setToneMapping(bool enabled);
63 bool isPlaying() const { return m_isPlaying; }
66 void restoreGeometry(const QRect &r);
67 void setNormalGeometry(const QRect &r);
68 bool isFullScreen() const { return windowStates() & Qt::WindowFullScreen; }
69 int videoPosition() const { return m_videoPosition; }
70 int videoDuration() const { return m_videoDuration; }
71 QString positionText() const;
72 QString durationText() const;
73
74 Q_INVOKABLE void triggerPlayPause();
75 Q_INVOKABLE void triggerRewind();
76 Q_INVOKABLE void triggerFastForward();
77 Q_INVOKABLE void toggleFullScreen();
78 Q_INVOKABLE void seekToFrame(int frame);
79 Q_INVOKABLE void beginSystemMove() { startSystemMove(); }
80
81public slots:
82 void pushFrame(const QVideoFrame &frame);
83 void setHdrTransfer(HdrTransfer transfer);
84 void setPlaying(bool playing);
85
86signals:
87 void hdrGainChanged();
88 void hdrTransferModeChanged();
89 void hdrModeRestartRequested();
93 void hdrModeConfirmed(bool available);
94 void displayPeakNitsChanged();
95 void contentPeakNitsChanged();
96 void toneMappingChanged();
97 void playingChanged();
98 void fullScreenChanged();
99 void videoPositionChanged();
100 void videoDurationChanged();
101
102protected:
103 void keyPressEvent(QKeyEvent *event) override;
104 void keyReleaseEvent(QKeyEvent *event) override;
105 bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result) override;
106 void resizeEvent(QResizeEvent *event) override;
107
108private slots:
109 void checkEdrHeadroom();
110 void onScreenChanged(QScreen *screen);
111 void processPendingScreenChange();
112
113private:
114 bool isHdrMode() const;
115 void updateHdrGain();
116 void invalidateVideoNode();
117
118 QPointer<QVideoSink> m_videoSink;
119 QPointer<QScreen> m_lastScreen;
120 QPointer<QScreen> m_pendingScreen;
121 QTimer m_edrTimer;
122 QTimer m_screenChangeTimer;
123 bool m_loggedSwapChain{false};
124 bool m_loggedGainSkip{false};
125 bool m_lastKnownHdrMode{false};
126 bool m_pendingWasHdrMode{false};
127 bool m_warnedAboutScreenChange{false};
128 bool m_skipNextFrame{false};
129 HdrTransfer m_hdrTransfer{HdrTransfer::SDR};
130 bool m_isPlaying{false};
131 float m_lastLoggedHeadroom{0.0f};
132 int m_edrCheckCount{0};
133 float m_hdrGain{1.0f};
134 int m_displayPeakNits{0};
135 int m_contentPeakNits{0};
136 bool m_toneMapping{true};
137 bool m_skipDarSnap{false};
138 QRect m_normalGeometry;
139 int m_videoPosition{0};
140 int m_videoDuration{0};
141};
142
143#endif // HDRPREVIEWWINDOW_H