Simplify XDMA types and add fullscreen preview
This commit is contained in:
@@ -138,6 +138,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
openDevice();
|
||||
});
|
||||
connect(ui_->showPreviewButton, &QPushButton::clicked, this, [this]() { showPreviewWindow(); });
|
||||
connect(ui_->fullscreenPreviewButton, &QPushButton::clicked, this, [this]() { showFullscreenPreviewWindow(); });
|
||||
connect(ui_->startButton, &QPushButton::clicked, this, [this]() { startCapture(); });
|
||||
connect(ui_->stopButton, &QPushButton::clicked, this, [this]() { stopCapture(); });
|
||||
connect(signalStatusTimer_, &QTimer::timeout, this, [this]() { updateSignalStatus(true); });
|
||||
@@ -192,12 +193,22 @@ void MainWindow::refreshDevices()
|
||||
|
||||
void MainWindow::showPreviewWindow()
|
||||
{
|
||||
updatePreviewSourceSize();
|
||||
previewWindow_->showPreview();
|
||||
|
||||
if (handle_ && !applyPreview())
|
||||
appendLog(QStringLiteral("Show Preview failed: unable to update preview window"));
|
||||
}
|
||||
|
||||
void MainWindow::showFullscreenPreviewWindow()
|
||||
{
|
||||
updatePreviewSourceSize();
|
||||
previewWindow_->showFullscreenPreview();
|
||||
|
||||
if (handle_ && !applyPreview())
|
||||
appendLog(QStringLiteral("Fullscreen Preview failed: unable to update preview window"));
|
||||
}
|
||||
|
||||
bool MainWindow::openDevice()
|
||||
{
|
||||
if (handle_)
|
||||
@@ -268,6 +279,7 @@ void MainWindow::startCapture()
|
||||
if (!handle_ && !openDevice())
|
||||
return;
|
||||
|
||||
updatePreviewSourceSize();
|
||||
previewWindow_->showPreview();
|
||||
if (!applyPreview())
|
||||
return;
|
||||
@@ -323,6 +335,31 @@ bool MainWindow::applyPreview()
|
||||
return true;
|
||||
}
|
||||
|
||||
void MainWindow::updatePreviewSourceSize(const gvfg_runtime_info_t &info)
|
||||
{
|
||||
const auto &signal = info.input_signal;
|
||||
const auto &callback = info.callback_frame;
|
||||
|
||||
if (signal.width > 0 && signal.height > 0)
|
||||
{
|
||||
previewWindow_->setSourceSize(signal.width, signal.height);
|
||||
return;
|
||||
}
|
||||
|
||||
if (callback.valid && callback.width > 0 && callback.height > 0)
|
||||
previewWindow_->setSourceSize(callback.width, callback.height);
|
||||
}
|
||||
|
||||
void MainWindow::updatePreviewSourceSize()
|
||||
{
|
||||
if (!handle_)
|
||||
return;
|
||||
|
||||
gvfg_runtime_info_t info{};
|
||||
if (gvfg_get_runtime_info(handle_, &info) == GVFG_OK)
|
||||
updatePreviewSourceSize(info);
|
||||
}
|
||||
|
||||
void MainWindow::updateSignalStatus(bool writeLog)
|
||||
{
|
||||
if (!handle_)
|
||||
@@ -340,6 +377,8 @@ void MainWindow::updateSignalStatus(bool writeLog)
|
||||
const bool videoFormatValid = fpgaMaskValid(fpga.valid_mask, GVFG_FPGA_SIGNAL_VALID_VIDEO_FORMAT);
|
||||
const bool bitDepthValid = fpgaMaskValid(fpga.valid_mask, GVFG_FPGA_SIGNAL_VALID_BIT_DEPTH);
|
||||
const bool statusValid = fpgaMaskValid(fpga.valid_mask, GVFG_FPGA_SIGNAL_VALID_STATUS);
|
||||
if (previewWindow_->isVisible())
|
||||
updatePreviewSourceSize(info);
|
||||
|
||||
const QString fpgaResolution = (fpga.width_valid && fpga.height_valid)
|
||||
? QStringLiteral("%1x%2").arg(signal.width).arg(signal.height)
|
||||
@@ -403,6 +442,7 @@ void MainWindow::updateUiState()
|
||||
ui_->openButton->setEnabled(!captureRunning_);
|
||||
ui_->startButton->setEnabled(deviceOpen && !captureRunning_);
|
||||
ui_->stopButton->setEnabled(captureRunning_);
|
||||
ui_->fullscreenPreviewButton->setEnabled(true);
|
||||
ui_->refreshButton->setEnabled(!deviceOpen && !captureRunning_);
|
||||
ui_->deviceCombo->setEnabled(!deviceOpen && !captureRunning_);
|
||||
}
|
||||
|
||||
@@ -34,11 +34,14 @@ protected:
|
||||
private:
|
||||
void refreshDevices();
|
||||
void showPreviewWindow();
|
||||
void showFullscreenPreviewWindow();
|
||||
bool openDevice();
|
||||
void closeDevice();
|
||||
void startCapture();
|
||||
void stopCapture();
|
||||
bool applyPreview();
|
||||
void updatePreviewSourceSize(const gvfg_runtime_info_t &info);
|
||||
void updatePreviewSourceSize();
|
||||
void updateSignalStatus(bool writeLog);
|
||||
void updateUiState();
|
||||
void showError(const QString &apiName, gvfg_status_t status);
|
||||
|
||||
@@ -47,6 +47,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="fullscreenPreviewButton">
|
||||
<property name="text">
|
||||
<string>Fullscreen Preview</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="startButton">
|
||||
<property name="text">
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
#include "previewwindow.h"
|
||||
#include "ui_previewwindow.h"
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QCloseEvent>
|
||||
#include <QKeyEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QScreen>
|
||||
#include <QSize>
|
||||
#include <algorithm>
|
||||
|
||||
PreviewWindow::PreviewWindow(QWidget *parent)
|
||||
: QWidget(parent), ui_(new Ui::PreviewWindow)
|
||||
@@ -21,19 +27,81 @@ void *PreviewWindow::nativePreviewHandle() const
|
||||
return reinterpret_cast<void *>(ui_->previewHost->winId());
|
||||
}
|
||||
|
||||
void PreviewWindow::setSourceSize(int sourceWidth, int sourceHeight)
|
||||
{
|
||||
if (sourceWidth <= 0 || sourceHeight <= 0)
|
||||
return;
|
||||
|
||||
if (sourceWidth_ == sourceWidth && sourceHeight_ == sourceHeight && isVisible())
|
||||
return;
|
||||
|
||||
sourceWidth_ = sourceWidth;
|
||||
sourceHeight_ = sourceHeight;
|
||||
|
||||
if (isFullScreen())
|
||||
return;
|
||||
|
||||
QScreen *targetScreen = screen();
|
||||
if (!targetScreen)
|
||||
targetScreen = QGuiApplication::primaryScreen();
|
||||
|
||||
ui_->previewHost->setMinimumSize(QSize(1, 1));
|
||||
ui_->previewHost->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
|
||||
|
||||
const QSize currentHostSize = ui_->previewHost->size();
|
||||
const QSize windowOverhead = size() - currentHostSize;
|
||||
|
||||
QSize targetSize(sourceWidth, sourceHeight);
|
||||
if (targetScreen)
|
||||
{
|
||||
const QSize maxSize = targetScreen->availableGeometry().size() - windowOverhead - QSize(16, 48);
|
||||
const QSize boundedSize(std::max(320, maxSize.width()), std::max(180, maxSize.height()));
|
||||
if (targetSize.width() > boundedSize.width() || targetSize.height() > boundedSize.height())
|
||||
targetSize.scale(boundedSize, Qt::KeepAspectRatio);
|
||||
}
|
||||
|
||||
resize(targetSize + windowOverhead);
|
||||
}
|
||||
|
||||
void PreviewWindow::closePreview()
|
||||
{
|
||||
closeAllowed_ = true;
|
||||
close();
|
||||
}
|
||||
|
||||
void PreviewWindow::showPreview()
|
||||
void PreviewWindow::showPreview(int sourceWidth, int sourceHeight)
|
||||
{
|
||||
setSourceSize(sourceWidth, sourceHeight);
|
||||
if (isFullScreen())
|
||||
showNormal();
|
||||
show();
|
||||
raise();
|
||||
activateWindow();
|
||||
}
|
||||
|
||||
void PreviewWindow::showFullscreenPreview(int sourceWidth, int sourceHeight)
|
||||
{
|
||||
setSourceSize(sourceWidth, sourceHeight);
|
||||
enterFullscreen();
|
||||
}
|
||||
|
||||
void PreviewWindow::enterFullscreen()
|
||||
{
|
||||
showFullScreen();
|
||||
raise();
|
||||
activateWindow();
|
||||
}
|
||||
|
||||
void PreviewWindow::exitFullscreen()
|
||||
{
|
||||
if (!isFullScreen())
|
||||
return;
|
||||
|
||||
showNormal();
|
||||
raise();
|
||||
activateWindow();
|
||||
}
|
||||
|
||||
void PreviewWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
if (closeAllowed_)
|
||||
@@ -45,3 +113,28 @@ void PreviewWindow::closeEvent(QCloseEvent *event)
|
||||
hide();
|
||||
event->ignore();
|
||||
}
|
||||
|
||||
void PreviewWindow::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if (event->key() == Qt::Key_Escape && isFullScreen())
|
||||
{
|
||||
exitFullscreen();
|
||||
event->accept();
|
||||
return;
|
||||
}
|
||||
|
||||
if (event->key() == Qt::Key_F11)
|
||||
{
|
||||
isFullScreen() ? exitFullscreen() : enterFullscreen();
|
||||
event->accept();
|
||||
return;
|
||||
}
|
||||
|
||||
QWidget::keyPressEvent(event);
|
||||
}
|
||||
|
||||
void PreviewWindow::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
{
|
||||
isFullScreen() ? exitFullscreen() : enterFullscreen();
|
||||
event->accept();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QKeyEvent;
|
||||
class QMouseEvent;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui
|
||||
{
|
||||
@@ -18,15 +21,24 @@ public:
|
||||
~PreviewWindow() override;
|
||||
|
||||
void *nativePreviewHandle() const;
|
||||
void setSourceSize(int sourceWidth, int sourceHeight);
|
||||
void closePreview();
|
||||
|
||||
public slots:
|
||||
void showPreview();
|
||||
void showPreview(int sourceWidth = 0, int sourceHeight = 0);
|
||||
void showFullscreenPreview(int sourceWidth = 0, int sourceHeight = 0);
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
void keyPressEvent(QKeyEvent *event) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
|
||||
private:
|
||||
void enterFullscreen();
|
||||
void exitFullscreen();
|
||||
|
||||
Ui::PreviewWindow *ui_ = nullptr;
|
||||
bool closeAllowed_ = false;
|
||||
int sourceWidth_ = 0;
|
||||
int sourceHeight_ = 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user