CuteLogger
Fast and simple logging solution for Qt based applications
htmlgenerator.h
1/*
2 * Copyright (c) 2025 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 HTMLGENERATOR_H
19#define HTMLGENERATOR_H
20
21#include <QElapsedTimer>
22#include <QJsonObject>
23#include <QNetworkAccessManager>
24#include <QObject>
25#include <QProcess>
26#include <QSize>
27#include <QTemporaryDir>
28#include <QTimer>
29#include <QWebSocket>
30
31class HtmlGenerator : public QObject
32{
33 Q_OBJECT
34public:
35 explicit HtmlGenerator(QObject *parent = nullptr);
36 ~HtmlGenerator();
37
38 void setAnimationParameters(double fps, int duration);
39 void launchBrowser(const QString &executablePath,
40 const QString &url,
41 const QSize &viewport,
42 const QString &outputPath);
43
44signals:
45 void progressUpdate(float);
46 void imageReady(QString outputPath);
47
48private slots:
49 void connectToBrowser();
50 void createNewPage();
51 void onWebSocketConnected();
52 void onMessageReceived(const QString &message);
53 void onWebSocketDisconnected();
54 void onChromeProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
55 void onChromeProcessError(QProcess::ProcessError error);
56 void startAnimationCapture();
57 void captureAnimationFrame();
58 void handleAnimationFrame(const QJsonObject &result);
59 void completeAnimationCapture();
60 void takeScreenshot();
61 void handleScreenshotResult(const QJsonObject &result);
62 int sendCommand(const QString &method, const QJsonObject &params = QJsonObject());
63
64private:
65 QWebSocket *m_webSocket;
66 QNetworkAccessManager *m_networkManager;
67 int m_messageId;
68 QProcess *m_chromeProcess;
69 QString m_url;
70 QSize m_viewport;
71 QString m_outputPath;
72 bool m_pendingScreenshot = false;
73 int m_screenshotMessageId = 0;
74 bool m_screenshotCompleted = false;
75 QTemporaryDir m_tempDir;
76
77 // Animation recording members
78 bool m_animationMode = false;
79 double m_fps = 0.0;
80 int m_duration = 0;
81 int m_currentFrame = 0;
82 int m_totalFrames = 0;
83 QTimer *m_animationTimer = nullptr;
84 QElapsedTimer m_animationElapsed;
85};
86
87#endif // HTMLGENERATOR_H