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 int displayPeakNits() const { return m_displayPeakNits; }
57 void setDisplayPeakNits(int nits);
58 int contentPeakNits() const { return m_contentPeakNits; }
59 void setContentPeakNits(int nits);
60 bool toneMapping() const { return m_toneMapping; }
61 void setToneMapping(bool enabled);
62 bool isPlaying() const { return m_isPlaying; }
65 void restoreGeometry(const QRect &r);
66 void setNormalGeometry(const QRect &r);
67 bool isFullScreen() const { return windowStates() & Qt::WindowFullScreen; }
68 int videoPosition() const { return m_videoPosition; }
69 int videoDuration() const { return m_videoDuration; }
70 QString positionText() const;
71 QString durationText() const;
72
73 Q_INVOKABLE void triggerPlayPause();
74 Q_INVOKABLE void triggerRewind();
75 Q_INVOKABLE void triggerFastForward();
76 Q_INVOKABLE void toggleFullScreen();
77 Q_INVOKABLE void seekToFrame(int frame);
78
79public slots:
80 void pushFrame(const QVideoFrame &frame);
81 void setHdrTransfer(HdrTransfer transfer);
82 void setPlaying(bool playing);
83
84signals:
85 void hdrGainChanged();
86 void hdrTransferModeChanged();
87 void hdrModeRestartRequested();
88 void displayPeakNitsChanged();
89 void contentPeakNitsChanged();
90 void toneMappingChanged();
91 void playingChanged();
92 void fullScreenChanged();
93 void videoPositionChanged();
94 void videoDurationChanged();
95
96protected:
97 void keyPressEvent(QKeyEvent *event) override;
98 void keyReleaseEvent(QKeyEvent *event) override;
99 bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result) override;
100 void resizeEvent(QResizeEvent *event) override;
101
102private slots:
103 void checkEdrHeadroom();
104 void onScreenChanged(QScreen *screen);
105 void processPendingScreenChange();
106
107private:
108 bool isHdrMode() const;
109 void updateHdrGain();
110 void invalidateVideoNode();
111
112 QPointer<QVideoSink> m_videoSink;
113 QPointer<QScreen> m_lastScreen;
114 QPointer<QScreen> m_pendingScreen;
115 QTimer m_edrTimer;
116 QTimer m_screenChangeTimer;
117 bool m_loggedSwapChain{false};
118 bool m_loggedGainSkip{false};
119 bool m_lastKnownHdrMode{false};
120 bool m_pendingWasHdrMode{false};
121 bool m_warnedAboutScreenChange{false};
122 bool m_skipNextFrame{false};
123 HdrTransfer m_hdrTransfer{HdrTransfer::SDR};
124 bool m_isPlaying{false};
125 float m_lastLoggedHeadroom{0.0f};
126 int m_edrCheckCount{0};
127 float m_hdrGain{1.0f};
128 int m_displayPeakNits{0};
129 int m_contentPeakNits{0};
130 bool m_toneMapping{true};
131 bool m_skipDarSnap{false};
132 QRect m_normalGeometry;
133 int m_videoPosition{0};
134 int m_videoDuration{0};
135};
136
137#endif // HDRPREVIEWWINDOW_H