Vollbildmodus für HDMI

This commit is contained in:
2026-09-15 20:21:22 +02:00
parent 934f32a3bd
commit 4a44d04c75
10 changed files with 576 additions and 411 deletions

View File

@@ -9,6 +9,71 @@
#include <QMetaObject>
#include <QResizeEvent>
#include <QMessageBox>
#include <QKeyEvent>
#include <QMouseEvent>
#include <QCloseEvent>
#include <QScreen>
// ── FullscreenVideoView ────────────────────────────────────────────────
FullscreenVideoView::FullscreenVideoView(QWidget *parent)
: QWidget(parent, Qt::Window)
{
setWindowTitle(tr("uartscope - Video (Fullscreen)"));
setAttribute(Qt::WA_DeleteOnClose);
setCursor(Qt::BlankCursor);
QPalette pal = palette();
pal.setColor(QPalette::Window, Qt::black);
setPalette(pal);
setAutoFillBackground(true);
}
void FullscreenVideoView::setFrame(const QImage &frame)
{
m_frame = frame;
update();
}
void FullscreenVideoView::paintEvent(QPaintEvent *)
{
QPainter p(this);
p.fillRect(rect(), Qt::black);
if (m_frame.isNull()) {
p.setPen(QColor(0x44, 0x44, 0x44));
p.setFont(QFont("Sans", 14));
p.drawText(rect(), Qt::AlignCenter, tr("No signal"));
return;
}
const QImage scaled = m_frame.scaled(size(), Qt::KeepAspectRatio,
Qt::SmoothTransformation);
const QPoint origin((width() - scaled.width()) / 2,
(height() - scaled.height()) / 2);
p.drawImage(origin, scaled);
}
void FullscreenVideoView::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Escape || event->key() == Qt::Key_F11)
close();
else
QWidget::keyPressEvent(event);
}
void FullscreenVideoView::mouseDoubleClickEvent(QMouseEvent *)
{
close();
}
void FullscreenVideoView::closeEvent(QCloseEvent *event)
{
emit closed();
QWidget::closeEvent(event);
}
// ── VideoWidget ─────────────────────────────────────────────────────────
static QStringList enumerateVideoDevices()
{
@@ -44,6 +109,8 @@ VideoWidget::VideoWidget(QWidget *parent)
m_infoLabel->setText(tr("Stopped"));
if (m_recording)
stopRecording();
if (m_fullscreenView)
m_fullscreenView->close();
update();
});
connect(m_worker, &V4l2Worker::errorOccurred, this, [this](const QString &msg) {
@@ -63,6 +130,9 @@ void VideoWidget::shutdown()
return;
m_shutdownDone = true;
if (m_fullscreenView)
m_fullscreenView->close();
if (m_recording)
stopRecording();
@@ -119,12 +189,18 @@ void VideoWidget::setupUi()
m_recordBtn->setToolTip(tr("Record the live preview to an MP4 file (requires ffmpeg)"));
connect(m_recordBtn, &QPushButton::toggled, this, &VideoWidget::onRecordToggled);
m_fullscreenBtn = new QPushButton(tr("⛶"), this);
m_fullscreenBtn->setMaximumWidth(28);
m_fullscreenBtn->setToolTip(tr("Show video fullscreen (Esc or double-click to exit)"));
connect(m_fullscreenBtn, &QPushButton::clicked, this, &VideoWidget::onFullscreenToggle);
ctrlRow->addWidget(m_deviceCombo, 1);
ctrlRow->addWidget(refreshBtn);
ctrlRow->addWidget(m_startBtn);
ctrlRow->addWidget(m_freezeBtn);
ctrlRow->addWidget(m_screenshotBtn);
ctrlRow->addWidget(m_recordBtn);
ctrlRow->addWidget(m_fullscreenBtn);
layout->addLayout(ctrlRow);
m_infoLabel = new QLabel(tr("No device started"), this);
@@ -229,6 +305,9 @@ void VideoWidget::onNewFrame(const QImage &frame)
m_frame = frame;
updateScaled();
update();
if (m_fullscreenView)
m_fullscreenView->setFrame(frame);
}
void VideoWidget::clearFrame()
@@ -321,6 +400,28 @@ void VideoWidget::onRecordToggled(bool checked)
stopRecording();
}
void VideoWidget::onFullscreenToggle()
{
// Already open - a second click just closes it again.
if (m_fullscreenView) {
m_fullscreenView->close();
return;
}
m_fullscreenView = new FullscreenVideoView();
connect(m_fullscreenView, &FullscreenVideoView::closed, this, [this] {
m_fullscreenView = nullptr;
});
// Put it on whichever screen the main window currently lives on
// (useful when a second/HDMI display is attached), then go fullscreen.
if (QScreen *screen = this->screen())
m_fullscreenView->setGeometry(screen->geometry());
m_fullscreenView->setFrame(m_frame);
m_fullscreenView->showFullScreen();
}
void VideoWidget::startRecording()
{
if (m_frame.isNull()) {