Files
clearpilot/system/clearpilot/tools/qt_webview.cc
Your Name 719856d2df wip
2024-05-10 02:48:38 -05:00

106 lines
3.4 KiB
C++

#include <QCommandLineParser>
#include <QApplication>
#include <QWidget>
#include <QTextEdit>
#include <QLabel>
#include <QTimer>
#include <QProcess>
#include <QVBoxLayout>
#include <QFont>
#include <QScreen>
#include <QScrollBar>
#include <QGuiApplication>
#include <qpa/qplatformnativeinterface.h>
#include <wayland-client-protocol.h>
#include <cstdlib>
#include <QWebEngineView>
class WebViewFrame : public QFrame {
Q_OBJECT
public:
explicit WebViewFrame(QWidget *parent = nullptr) : QFrame(parent) {
// QVBoxLayout *layout = new QVBoxLayout(this);
// QWebEngineView *web_view = new QWebEngineView();
// web_view->load(QUrl("http://example.com")); // Change URL as needed
// layout->addWidget(web_view);
}
};
int main(int argc, char *argv[]) {
setenv("XDG_RUNTIME_DIR", "/var/tmp/weston", 1);
setenv("WAYLAND_DISPLAY", "wayland-0", 1);
setenv("QT_QPA_PLATFORM", "wayland", 1);
setenv("QT_WAYLAND_SHELL_INTEGRATION", "wl-shell", 1);
QApplication app(argc, argv);
QCommandLineParser parser;
parser.addHelpOption();
parser.addPositionalArgument("command", "The URL to open.");
parser.process(app);
QStringList args = parser.positionalArguments();
if (args.isEmpty()) {
fprintf(stderr, "Usage: %s '<command>'\n", argv[0]);
return 1;
}
// Common init
QWidget window;
window.setWindowTitle("Generic Window");
window.setStyleSheet("background-color: blue;");
window.showFullScreen();
auto windowHandle = window.windowHandle();
if (!windowHandle) {
fprintf(stderr, "Error: Unable to obtain window handle.\n");
return 1;
}
QPlatformNativeInterface *native = QGuiApplication::platformNativeInterface();
auto *s = static_cast<wl_surface*>(native->nativeResourceForWindow("surface", windowHandle));
if (!s) {
fprintf(stderr, "Error: Unable to obtain native Wayland surface.\n");
return 1;
}
wl_surface_set_buffer_transform(s, WL_OUTPUT_TRANSFORM_270);
wl_surface_commit(s);
window.setFixedSize(2160, 1080);
QVBoxLayout *layout = new QVBoxLayout(&window);
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
QTextEdit *outputDisplay = new QTextEdit;
outputDisplay->setFont(QFont("Consolas", 32));
outputDisplay->setReadOnly(true);
outputDisplay->setFixedSize(window.width(), window.height());
outputDisplay->setStyleSheet("color: white; background-color: black;");
outputDisplay->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); // Hide the vertical scrollbar
layout->addWidget(outputDisplay);
// QString url = args.first();
// web_view->load(QUrl(argv[1]));
// layout->addWidget(web_view);
// Set a timer to change the background color and load the URL after 0.5 seconds
QTimer::singleShot(2000, [&]() {
WebViewFrame *webViewFrame = new WebViewFrame(this);
layout->addWidget(webViewFrame);
// QWebEngineView *web_view = new QWebEngineView();
// web_view->load(QUrl(args.first())); // Load the URL
// layout->addWidget(web_view); // Add the web view to the layout
window.update(); // Refresh window to apply changes
});
// window.showFullScreen();
window.show();
return app.exec();
}