|
|
#include "nmWxPebiResultAnimationExportDlg.h"
|
|
|
#include "nmNumericDisplayFormat.h"
|
|
|
|
|
|
#include "nmFFmpegVideoWriter.h"
|
|
|
#include "ZxBaseUtil.h"
|
|
|
|
|
|
#include <QApplication>
|
|
|
#include <QButtonGroup>
|
|
|
#include <QComboBox>
|
|
|
#include <QDesktopWidget>
|
|
|
#include <QDialogButtonBox>
|
|
|
#include <QDir>
|
|
|
#include <QFileDialog>
|
|
|
#include <QFileInfo>
|
|
|
#include <QFontMetrics>
|
|
|
#include <QGridLayout>
|
|
|
#include <QGroupBox>
|
|
|
#include <QHBoxLayout>
|
|
|
#include <QLabel>
|
|
|
#include <QLineEdit>
|
|
|
#include <QMessageBox>
|
|
|
#include <QPushButton>
|
|
|
#include <QRadioButton>
|
|
|
#include <QSizePolicy>
|
|
|
#include <QSpinBox>
|
|
|
#include <QVBoxLayout>
|
|
|
#include <QVariant>
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
/** @brief 列表填充后测量推荐字符宽度,实际控件宽度始终交给布局管理。 */
|
|
|
void updateExportComboContentsLength(QComboBox* pCombo)
|
|
|
{
|
|
|
pCombo->ensurePolished();
|
|
|
const QFontMetrics oMetrics = pCombo->fontMetrics();
|
|
|
int nTextWidth = 0;
|
|
|
for(int nIndex = 0; nIndex < pCombo->count(); ++nIndex) {
|
|
|
nTextWidth = qMax(nTextWidth,
|
|
|
oMetrics.boundingRect(pCombo->itemText(nIndex)).width());
|
|
|
}
|
|
|
// 中文文本按实际像素宽度折算;保留主题对边框、箭头和图标区域的尺寸计算。
|
|
|
const int nCharacterWidth = qMax(1, oMetrics.width(QLatin1Char('X')));
|
|
|
pCombo->setMinimumContentsLength(qMax(1,
|
|
|
(nTextWidth + nCharacterWidth - 1) / nCharacterWidth));
|
|
|
}
|
|
|
|
|
|
/** @brief 创建右对齐标签,与同组输入框保持垂直居中。 */
|
|
|
QLabel* createRightAlignedLabel(const QString& sText, QWidget* pParent)
|
|
|
{
|
|
|
QLabel* pLabel = new QLabel(sText, pParent);
|
|
|
pLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
|
|
return pLabel;
|
|
|
}
|
|
|
|
|
|
/** @brief 统一像素尺寸的显示格式,不参与实际导出尺寸计算。 */
|
|
|
QString formatPixelSize(int nWidth, int nHeight)
|
|
|
{
|
|
|
QString sText = QString::number(nWidth);
|
|
|
sText.append(' ');
|
|
|
sText.append(QChar(0x00D7));
|
|
|
sText.append(QString::fromLatin1(" %1 px").arg(nHeight));
|
|
|
return sText;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
nmWxPebiResultAnimationExportDlg::nmWxPebiResultAnimationExportDlg(
|
|
|
const QVector<double>& vecFrameTimesHours,
|
|
|
const QSize& oCurrentViewportSize,
|
|
|
QWidget* pParent)
|
|
|
: iDlgBase(pParent),
|
|
|
m_vecFrameTimesHours(vecFrameTimesHours),
|
|
|
m_pFpsSpinBox(nullptr),
|
|
|
m_pStartFrameCombo(nullptr),
|
|
|
m_pEndFrameCombo(nullptr),
|
|
|
m_pSamplingIntervalSpinBox(nullptr),
|
|
|
m_pResolutionButtonGroup(nullptr),
|
|
|
m_pCurrentSizeRadioButton(nullptr),
|
|
|
m_p720pRadioButton(nullptr),
|
|
|
m_p1080pRadioButton(nullptr),
|
|
|
m_pCustomSizeRadioButton(nullptr),
|
|
|
m_pWidthSpinBox(nullptr),
|
|
|
m_pHeightSpinBox(nullptr),
|
|
|
m_pVideoFormatCombo(nullptr),
|
|
|
m_pTargetPathEdit(nullptr),
|
|
|
m_pOutputFrameCountLabel(nullptr),
|
|
|
m_pEstimatedDurationLabel(nullptr),
|
|
|
m_pErrorLabel(nullptr)
|
|
|
{
|
|
|
int nCurrentWidth = oCurrentViewportSize.width();
|
|
|
int nCurrentHeight = oCurrentViewportSize.height();
|
|
|
if(nCurrentWidth <= 0 || nCurrentHeight <= 0) {
|
|
|
nCurrentWidth = 1280;
|
|
|
nCurrentHeight = 720;
|
|
|
}
|
|
|
m_oEffectiveCurrentViewportSize = QSize(
|
|
|
normalizeEvenDimension(nCurrentWidth),
|
|
|
normalizeEvenDimension(nCurrentHeight));
|
|
|
|
|
|
createUi();
|
|
|
populateFrameItems();
|
|
|
populateVideoFormats();
|
|
|
setTargetFilePath(getSuggestedTargetFilePath());
|
|
|
onResolutionPresetChanged(Resolution_CurrentView);
|
|
|
onFrameRangeChanged();
|
|
|
|
|
|
// 列表和摘要准备完毕后一次性确定推荐尺寸,避免首次显示时下拉框重新伸缩。
|
|
|
updateExportComboContentsLength(m_pStartFrameCombo);
|
|
|
updateExportComboContentsLength(m_pEndFrameCombo);
|
|
|
updateExportComboContentsLength(m_pVideoFormatCombo);
|
|
|
adjustSize();
|
|
|
|
|
|
// 为保存路径预留更舒适的初始宽度,并随字体放大;小屏幕按可用区域限制新增宽度。
|
|
|
// 仅调整打开时的尺寸,不设置固定宽度或额外最小宽度,后续仍可由用户自由伸缩。
|
|
|
const int nPreferredWidth = qMax(560, fontMetrics().height() * 32);
|
|
|
const int nAvailableWidth = QApplication::desktop()->availableGeometry(this).width();
|
|
|
resize(qMax(width(), qMin(nPreferredWidth, nAvailableWidth * 9 / 10)), height());
|
|
|
}
|
|
|
|
|
|
nmPebiResultAnimationExportSettings
|
|
|
nmWxPebiResultAnimationExportDlg::getSettings() const
|
|
|
{
|
|
|
return m_oAcceptedSettings;
|
|
|
}
|
|
|
|
|
|
QString nmWxPebiResultAnimationExportDlg::getTargetFilePath() const
|
|
|
{
|
|
|
return m_sAcceptedTargetFilePath;
|
|
|
}
|
|
|
|
|
|
void nmWxPebiResultAnimationExportDlg::onFrameRangeChanged()
|
|
|
{
|
|
|
const int nStartIndex = m_pStartFrameCombo->currentIndex();
|
|
|
if(nStartIndex >= 0 &&
|
|
|
m_pEndFrameCombo->currentIndex() < nStartIndex) {
|
|
|
const bool bBlocked = m_pEndFrameCombo->blockSignals(true);
|
|
|
m_pEndFrameCombo->setCurrentIndex(nStartIndex);
|
|
|
m_pEndFrameCombo->blockSignals(bBlocked);
|
|
|
}
|
|
|
|
|
|
// 只更新提示,时间选择仍按帧下标绑定,不从显示文字反解析。
|
|
|
m_pStartFrameCombo->setToolTip(m_pStartFrameCombo->itemData(
|
|
|
m_pStartFrameCombo->currentIndex(), Qt::ToolTipRole).toString());
|
|
|
m_pEndFrameCombo->setToolTip(m_pEndFrameCombo->itemData(
|
|
|
m_pEndFrameCombo->currentIndex(), Qt::ToolTipRole).toString());
|
|
|
const int nRangeLength = qMax(1,
|
|
|
m_pEndFrameCombo->currentIndex() -
|
|
|
m_pStartFrameCombo->currentIndex());
|
|
|
m_pSamplingIntervalSpinBox->setMaximum(nRangeLength);
|
|
|
updateSummary();
|
|
|
}
|
|
|
|
|
|
void nmWxPebiResultAnimationExportDlg::onResolutionPresetChanged(
|
|
|
int nPresetId)
|
|
|
{
|
|
|
const bool bCustom = nPresetId == Resolution_Custom;
|
|
|
m_pWidthSpinBox->setEnabled(bCustom);
|
|
|
m_pHeightSpinBox->setEnabled(bCustom);
|
|
|
updateSummary();
|
|
|
}
|
|
|
|
|
|
void nmWxPebiResultAnimationExportDlg::normalizeCustomDimensions()
|
|
|
{
|
|
|
// editingFinished后再回写,避免valueChanged期间干扰用户键盘输入。
|
|
|
m_pWidthSpinBox->setValue(
|
|
|
normalizeEvenDimension(m_pWidthSpinBox->value()));
|
|
|
m_pHeightSpinBox->setValue(
|
|
|
normalizeEvenDimension(m_pHeightSpinBox->value()));
|
|
|
updateSummary();
|
|
|
}
|
|
|
|
|
|
void nmWxPebiResultAnimationExportDlg::updateSummary()
|
|
|
{
|
|
|
const nmPebiResultAnimationExportSettings oSettings =
|
|
|
collectSettings();
|
|
|
const int nOutputFrameCount = oSettings.getOutputFrameCount();
|
|
|
m_pOutputFrameCountLabel->setText(
|
|
|
tr("%1 frames").arg(nOutputFrameCount));
|
|
|
const double dDuration = oSettings.m_nFramesPerSecond > 0
|
|
|
? static_cast<double>(nOutputFrameCount) /
|
|
|
static_cast<double>(oSettings.m_nFramesPerSecond)
|
|
|
: 0.0;
|
|
|
m_pEstimatedDurationLabel->setText(
|
|
|
tr("%1 s").arg(nmNumericDisplayFormat::format(dDuration)));
|
|
|
m_pEstimatedDurationLabel->setToolTip(
|
|
|
tr("%1 s").arg(nmNumericDisplayFormat::fullPrecision(dDuration)));
|
|
|
clearError();
|
|
|
}
|
|
|
|
|
|
void nmWxPebiResultAnimationExportDlg::onVideoFormatChanged(int nIndex)
|
|
|
{
|
|
|
Q_UNUSED(nIndex);
|
|
|
if(m_pTargetPathEdit != nullptr &&
|
|
|
!m_pTargetPathEdit->text().isEmpty()) {
|
|
|
setTargetFilePath(normalizeTargetFilePath(
|
|
|
m_pTargetPathEdit->text()));
|
|
|
}
|
|
|
clearError();
|
|
|
}
|
|
|
|
|
|
void nmWxPebiResultAnimationExportDlg::browseTargetFile()
|
|
|
{
|
|
|
const QString sExtension = getSelectedVideoExtension();
|
|
|
if(sExtension.isEmpty()) {
|
|
|
showError(tr("The selected video format is unsupported."));
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
const QString sInitialPath = m_pTargetPathEdit->text().isEmpty()
|
|
|
? getSuggestedTargetFilePath() : m_pTargetPathEdit->text();
|
|
|
const QFileInfo oInitialFileInfo(sInitialPath);
|
|
|
|
|
|
QFileDialog oFileDialog(this, tr("Save Result Animation"));
|
|
|
oFileDialog.setAcceptMode(QFileDialog::AcceptSave);
|
|
|
oFileDialog.setFileMode(QFileDialog::AnyFile);
|
|
|
oFileDialog.setNameFilter(getSelectedVideoFilter());
|
|
|
oFileDialog.setDefaultSuffix(sExtension);
|
|
|
oFileDialog.setOption(QFileDialog::DontConfirmOverwrite, true);
|
|
|
oFileDialog.setDirectory(oInitialFileInfo.absolutePath());
|
|
|
oFileDialog.selectFile(oInitialFileInfo.fileName());
|
|
|
if(oFileDialog.exec() != QDialog::Accepted ||
|
|
|
oFileDialog.selectedFiles().isEmpty()) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
const QString sTargetPath = normalizeTargetFilePath(
|
|
|
oFileDialog.selectedFiles().first());
|
|
|
const QFileInfo oTargetFileInfo(sTargetPath);
|
|
|
setTargetFilePath(oTargetFileInfo.absoluteFilePath());
|
|
|
ZxBaseUtil::setLastDir(oTargetFileInfo.absolutePath());
|
|
|
clearError();
|
|
|
}
|
|
|
|
|
|
void nmWxPebiResultAnimationExportDlg::acceptSettings()
|
|
|
{
|
|
|
// 只有自定义模式需要把编辑值回写为编码器最终使用的偶数尺寸。
|
|
|
if(m_pCustomSizeRadioButton->isChecked()) {
|
|
|
normalizeCustomDimensions();
|
|
|
}
|
|
|
const nmPebiResultAnimationExportSettings oSettings =
|
|
|
collectSettings();
|
|
|
if(!oSettings.isValid(m_vecFrameTimesHours.size())) {
|
|
|
showError(tr("The animation export settings are invalid."));
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if(m_pTargetPathEdit->text().isEmpty()) {
|
|
|
showError(tr("Please select an output file."));
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
const QString sExtension = getSelectedVideoExtension();
|
|
|
if(sExtension.isEmpty()) {
|
|
|
showError(tr("The selected video format is unsupported."));
|
|
|
return;
|
|
|
}
|
|
|
const QString sTargetPath = QFileInfo(normalizeTargetFilePath(
|
|
|
m_pTargetPathEdit->text())).absoluteFilePath();
|
|
|
const QFileInfo oTargetFileInfo(sTargetPath);
|
|
|
if(oTargetFileInfo.suffix().compare(
|
|
|
sExtension, Qt::CaseInsensitive) != 0) {
|
|
|
showError(tr("The selected video file extension does not match "
|
|
|
"the selected format."));
|
|
|
return;
|
|
|
}
|
|
|
if(oTargetFileInfo.isDir()) {
|
|
|
showError(tr("The selected output path is a directory."));
|
|
|
return;
|
|
|
}
|
|
|
if(!QDir(oTargetFileInfo.absolutePath()).exists()) {
|
|
|
showError(tr("The selected output directory does not exist."));
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
setTargetFilePath(sTargetPath);
|
|
|
if(oTargetFileInfo.exists() &&
|
|
|
QMessageBox::question(
|
|
|
this, tr("Export Animation"),
|
|
|
tr("The selected file already exists. Replace it?"),
|
|
|
QMessageBox::Yes | QMessageBox::No,
|
|
|
QMessageBox::No) != QMessageBox::Yes) {
|
|
|
return;
|
|
|
}
|
|
|
m_oAcceptedSettings = oSettings;
|
|
|
m_sAcceptedTargetFilePath = sTargetPath;
|
|
|
accept();
|
|
|
}
|
|
|
|
|
|
void nmWxPebiResultAnimationExportDlg::createUi()
|
|
|
{
|
|
|
setWindowTitle(tr("Export Animation"));
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
|
|
|
|
|
QVBoxLayout* pMainLayout = new QVBoxLayout(this);
|
|
|
pMainLayout->setContentsMargins(12, 10, 12, 0);
|
|
|
pMainLayout->setSpacing(10);
|
|
|
|
|
|
QGroupBox* pFrameGroup = createFrameGroup();
|
|
|
QGroupBox* pOutputSizeGroup = createOutputSizeGroup();
|
|
|
QGroupBox* pOutputFileGroup = createOutputFileGroup();
|
|
|
QGroupBox* pInformationGroup = createInformationGroup();
|
|
|
pMainLayout->addWidget(pFrameGroup);
|
|
|
pMainLayout->addWidget(pOutputSizeGroup);
|
|
|
pMainLayout->addWidget(pOutputFileGroup);
|
|
|
pMainLayout->addWidget(pInformationGroup);
|
|
|
|
|
|
// 按当前字体和翻译后的标签计算公共列宽,使各参数分组的输入起点对齐。
|
|
|
// 尺寸分组使用单选项加宽高组合,保持自身的两列等比例伸缩布局。
|
|
|
QGridLayout* arrFieldLayouts[] = {
|
|
|
static_cast<QGridLayout*>(pFrameGroup->layout()),
|
|
|
static_cast<QGridLayout*>(pOutputFileGroup->layout()),
|
|
|
static_cast<QGridLayout*>(pInformationGroup->layout())
|
|
|
};
|
|
|
const int nFieldLayoutCount = sizeof(arrFieldLayouts) / sizeof(arrFieldLayouts[0]);
|
|
|
int nLabelWidth = 0;
|
|
|
for(int nLayoutIndex = 0; nLayoutIndex < nFieldLayoutCount; ++nLayoutIndex) {
|
|
|
QGridLayout* pLayout = arrFieldLayouts[nLayoutIndex];
|
|
|
for(int nRow = 0; nRow < pLayout->rowCount(); ++nRow) {
|
|
|
QLayoutItem* pItem = pLayout->itemAtPosition(nRow, 0);
|
|
|
if(pItem != nullptr) {
|
|
|
nLabelWidth = qMax(nLabelWidth, pItem->sizeHint().width());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
for(int nLayoutIndex = 0; nLayoutIndex < nFieldLayoutCount; ++nLayoutIndex) {
|
|
|
arrFieldLayouts[nLayoutIndex]->setColumnMinimumWidth(0, nLabelWidth);
|
|
|
}
|
|
|
|
|
|
// 高度余量由分组与底栏之间的空白吸收,输入框始终使用主题推荐高度。
|
|
|
pMainLayout->addStretch(1);
|
|
|
m_pErrorLabel = new QLabel(this);
|
|
|
m_pErrorLabel->setStyleSheet("QLabel { color: #a32626; }");
|
|
|
m_pErrorLabel->setWordWrap(true);
|
|
|
m_pErrorLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
|
|
m_pErrorLabel->hide();
|
|
|
pMainLayout->addWidget(m_pErrorLabel);
|
|
|
pMainLayout->addWidget(createFooter());
|
|
|
connectUiSignals();
|
|
|
}
|
|
|
|
|
|
QGroupBox* nmWxPebiResultAnimationExportDlg::createFrameGroup()
|
|
|
{
|
|
|
QGroupBox* pFrameGroup = new QGroupBox(tr("Frame Settings"), this);
|
|
|
pFrameGroup->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
QGridLayout* pFrameGrid = new QGridLayout(pFrameGroup);
|
|
|
pFrameGrid->setContentsMargins(8, 15, 8, 10);
|
|
|
pFrameGrid->setHorizontalSpacing(6);
|
|
|
pFrameGrid->setVerticalSpacing(6);
|
|
|
pFrameGrid->setColumnStretch(1, 1);
|
|
|
const QSizePolicy oFieldSizePolicy(
|
|
|
QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
|
|
m_pFpsSpinBox = new QSpinBox(pFrameGroup);
|
|
|
m_pFpsSpinBox->setRange(1, 5000);
|
|
|
m_pFpsSpinBox->setValue(15);
|
|
|
m_pFpsSpinBox->setSuffix(tr(" FPS"));
|
|
|
m_pFpsSpinBox->setSizePolicy(oFieldSizePolicy);
|
|
|
pFrameGrid->addWidget(
|
|
|
createRightAlignedLabel(tr("Frame rate"), pFrameGroup), 0, 0);
|
|
|
pFrameGrid->addWidget(m_pFpsSpinBox, 0, 1);
|
|
|
|
|
|
m_pStartFrameCombo = new QComboBox(pFrameGroup);
|
|
|
m_pStartFrameCombo->setObjectName(QLatin1String("exportStartFrameCombo"));
|
|
|
m_pStartFrameCombo->setSizePolicy(oFieldSizePolicy);
|
|
|
// Qt 4.8 的 AdjustToContents 会延迟自行 adjustSize;字符宽度策略只提供布局建议。
|
|
|
m_pStartFrameCombo->setSizeAdjustPolicy(
|
|
|
QComboBox::AdjustToMinimumContentsLengthWithIcon);
|
|
|
pFrameGrid->addWidget(
|
|
|
createRightAlignedLabel(tr("Start time"), pFrameGroup), 1, 0);
|
|
|
pFrameGrid->addWidget(m_pStartFrameCombo, 1, 1);
|
|
|
|
|
|
m_pEndFrameCombo = new QComboBox(pFrameGroup);
|
|
|
m_pEndFrameCombo->setObjectName(QLatin1String("exportEndFrameCombo"));
|
|
|
m_pEndFrameCombo->setSizePolicy(oFieldSizePolicy);
|
|
|
m_pEndFrameCombo->setSizeAdjustPolicy(
|
|
|
QComboBox::AdjustToMinimumContentsLengthWithIcon);
|
|
|
pFrameGrid->addWidget(
|
|
|
createRightAlignedLabel(tr("End time"), pFrameGroup), 2, 0);
|
|
|
pFrameGrid->addWidget(m_pEndFrameCombo, 2, 1);
|
|
|
|
|
|
m_pSamplingIntervalSpinBox = new QSpinBox(pFrameGroup);
|
|
|
m_pSamplingIntervalSpinBox->setRange(1, 1);
|
|
|
m_pSamplingIntervalSpinBox->setSizePolicy(oFieldSizePolicy);
|
|
|
pFrameGrid->addWidget(
|
|
|
createRightAlignedLabel(tr("Frame step"), pFrameGroup), 3, 0);
|
|
|
pFrameGrid->addWidget(m_pSamplingIntervalSpinBox, 3, 1);
|
|
|
return pFrameGroup;
|
|
|
}
|
|
|
|
|
|
QGroupBox* nmWxPebiResultAnimationExportDlg::createOutputSizeGroup()
|
|
|
{
|
|
|
QGroupBox* pOutputSizeGroup = new QGroupBox(tr("Output Size"), this);
|
|
|
pOutputSizeGroup->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
QGridLayout* pOutputSizeGrid = new QGridLayout(pOutputSizeGroup);
|
|
|
pOutputSizeGrid->setContentsMargins(8, 15, 8, 10);
|
|
|
pOutputSizeGrid->setHorizontalSpacing(6);
|
|
|
pOutputSizeGrid->setVerticalSpacing(6);
|
|
|
|
|
|
// 单选按钮仍按稳定枚举绑定,显示文本和布局顺序不参与导出尺寸判断。
|
|
|
m_pResolutionButtonGroup = new QButtonGroup(this);
|
|
|
m_pCurrentSizeRadioButton = new QRadioButton(
|
|
|
tr("Current image size") + QString::fromLatin1(" ") +
|
|
|
formatPixelSize(m_oEffectiveCurrentViewportSize.width(),
|
|
|
m_oEffectiveCurrentViewportSize.height()),
|
|
|
pOutputSizeGroup);
|
|
|
m_p720pRadioButton = new QRadioButton(
|
|
|
formatPixelSize(1280, 720), pOutputSizeGroup);
|
|
|
m_p1080pRadioButton = new QRadioButton(
|
|
|
formatPixelSize(1920, 1080), pOutputSizeGroup);
|
|
|
m_pCustomSizeRadioButton = new QRadioButton(
|
|
|
tr("Custom size"), pOutputSizeGroup);
|
|
|
m_pResolutionButtonGroup->addButton(
|
|
|
m_pCurrentSizeRadioButton, Resolution_CurrentView);
|
|
|
m_pResolutionButtonGroup->addButton(
|
|
|
m_p720pRadioButton, Resolution_720p);
|
|
|
m_pResolutionButtonGroup->addButton(
|
|
|
m_p1080pRadioButton, Resolution_1080p);
|
|
|
m_pResolutionButtonGroup->addButton(
|
|
|
m_pCustomSizeRadioButton, Resolution_Custom);
|
|
|
m_pCurrentSizeRadioButton->setChecked(true);
|
|
|
|
|
|
pOutputSizeGrid->addWidget(
|
|
|
m_pCurrentSizeRadioButton, 0, 0, 1, 5, Qt::AlignLeft);
|
|
|
pOutputSizeGrid->addWidget(
|
|
|
m_p720pRadioButton, 1, 0, 1, 5, Qt::AlignLeft);
|
|
|
pOutputSizeGrid->addWidget(
|
|
|
m_p1080pRadioButton, 2, 0, 1, 5, Qt::AlignLeft);
|
|
|
pOutputSizeGrid->addWidget(m_pCustomSizeRadioButton, 3, 0, Qt::AlignLeft);
|
|
|
|
|
|
m_pWidthSpinBox = new QSpinBox(pOutputSizeGroup);
|
|
|
m_pHeightSpinBox = new QSpinBox(pOutputSizeGroup);
|
|
|
m_pWidthSpinBox->setRange(2, 8192);
|
|
|
m_pHeightSpinBox->setRange(2, 8192);
|
|
|
m_pWidthSpinBox->setSingleStep(2);
|
|
|
m_pHeightSpinBox->setSingleStep(2);
|
|
|
m_pWidthSpinBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
m_pHeightSpinBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
m_pWidthSpinBox->setValue(m_oEffectiveCurrentViewportSize.width());
|
|
|
m_pHeightSpinBox->setValue(m_oEffectiveCurrentViewportSize.height());
|
|
|
QLabel* pMultiplyLabel = new QLabel(
|
|
|
QString(QChar(0x00D7)), pOutputSizeGroup);
|
|
|
pMultiplyLabel->setAlignment(Qt::AlignCenter);
|
|
|
QLabel* pPixelLabel = new QLabel(
|
|
|
QString::fromLatin1("px"), pOutputSizeGroup);
|
|
|
pOutputSizeGrid->addWidget(m_pWidthSpinBox, 3, 1);
|
|
|
pOutputSizeGrid->addWidget(pMultiplyLabel, 3, 2, Qt::AlignCenter);
|
|
|
pOutputSizeGrid->addWidget(m_pHeightSpinBox, 3, 3);
|
|
|
pOutputSizeGrid->addWidget(pPixelLabel, 3, 4, Qt::AlignLeft);
|
|
|
// 宽、高输入框按 1:1 分配横向余量,不再限制像素宽度或在两侧增加留白。
|
|
|
pOutputSizeGrid->setColumnStretch(1, 1);
|
|
|
pOutputSizeGrid->setColumnStretch(3, 1);
|
|
|
return pOutputSizeGroup;
|
|
|
}
|
|
|
|
|
|
QGroupBox* nmWxPebiResultAnimationExportDlg::createOutputFileGroup()
|
|
|
{
|
|
|
QGroupBox* pOutputFileGroup = new QGroupBox(tr("Output File"), this);
|
|
|
pOutputFileGroup->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
QGridLayout* pOutputFileGrid = new QGridLayout(pOutputFileGroup);
|
|
|
pOutputFileGrid->setContentsMargins(8, 15, 8, 10);
|
|
|
pOutputFileGrid->setHorizontalSpacing(6);
|
|
|
pOutputFileGrid->setVerticalSpacing(6);
|
|
|
pOutputFileGrid->setColumnStretch(1, 1);
|
|
|
|
|
|
m_pVideoFormatCombo = new QComboBox(pOutputFileGroup);
|
|
|
m_pVideoFormatCombo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
m_pVideoFormatCombo->setSizeAdjustPolicy(
|
|
|
QComboBox::AdjustToMinimumContentsLengthWithIcon);
|
|
|
pOutputFileGrid->addWidget(
|
|
|
createRightAlignedLabel(
|
|
|
tr("File format"), pOutputFileGroup), 0, 0);
|
|
|
pOutputFileGrid->addWidget(m_pVideoFormatCombo, 0, 1, 1, 2);
|
|
|
|
|
|
m_pTargetPathEdit = new QLineEdit(pOutputFileGroup);
|
|
|
m_pTargetPathEdit->setReadOnly(true);
|
|
|
m_pTargetPathEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
QPushButton* pBrowseButton = new QPushButton(
|
|
|
tr("Browse..."), pOutputFileGroup);
|
|
|
// 浏览按钮使用主题推荐宽度,路径框吸收余量;回车默认进入确认校验。
|
|
|
pBrowseButton->setAutoDefault(false);
|
|
|
pOutputFileGrid->addWidget(
|
|
|
createRightAlignedLabel(
|
|
|
tr("Save location"), pOutputFileGroup), 1, 0);
|
|
|
pOutputFileGrid->addWidget(m_pTargetPathEdit, 1, 1);
|
|
|
pOutputFileGrid->addWidget(pBrowseButton, 1, 2);
|
|
|
connect(pBrowseButton, SIGNAL(clicked()),
|
|
|
this, SLOT(browseTargetFile()));
|
|
|
return pOutputFileGroup;
|
|
|
}
|
|
|
|
|
|
QGroupBox* nmWxPebiResultAnimationExportDlg::createInformationGroup()
|
|
|
{
|
|
|
QGroupBox* pInformationGroup = new QGroupBox(
|
|
|
tr("Export Information"), this);
|
|
|
pInformationGroup->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
QGridLayout* pInformationGrid = new QGridLayout(pInformationGroup);
|
|
|
pInformationGrid->setContentsMargins(8, 15, 8, 10);
|
|
|
pInformationGrid->setHorizontalSpacing(6);
|
|
|
pInformationGrid->setVerticalSpacing(6);
|
|
|
pInformationGrid->setColumnStretch(1, 1);
|
|
|
m_pOutputFrameCountLabel = new QLabel(pInformationGroup);
|
|
|
m_pEstimatedDurationLabel = new QLabel(pInformationGroup);
|
|
|
m_pOutputFrameCountLabel->setTextInteractionFlags(
|
|
|
Qt::TextSelectableByMouse);
|
|
|
m_pEstimatedDurationLabel->setTextInteractionFlags(
|
|
|
Qt::TextSelectableByMouse);
|
|
|
pInformationGrid->addWidget(
|
|
|
createRightAlignedLabel(
|
|
|
tr("Output frames"), pInformationGroup), 0, 0);
|
|
|
pInformationGrid->addWidget(
|
|
|
m_pOutputFrameCountLabel, 0, 1, Qt::AlignLeft);
|
|
|
pInformationGrid->addWidget(
|
|
|
createRightAlignedLabel(
|
|
|
tr("Estimated duration"), pInformationGroup), 1, 0);
|
|
|
pInformationGrid->addWidget(
|
|
|
m_pEstimatedDurationLabel, 1, 1, Qt::AlignLeft);
|
|
|
return pInformationGroup;
|
|
|
}
|
|
|
|
|
|
QWidget* nmWxPebiResultAnimationExportDlg::createFooter()
|
|
|
{
|
|
|
QWidget* pFooter = new QWidget(this);
|
|
|
pFooter->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
|
|
QHBoxLayout* pLayout = new QHBoxLayout(pFooter);
|
|
|
pLayout->setContentsMargins(4, 5, 4, 5);
|
|
|
pLayout->setSpacing(8);
|
|
|
pLayout->addStretch();
|
|
|
|
|
|
// 与其他结果设置窗口共用框架图标和底栏边距,按钮尺寸由主题决定。
|
|
|
QDialogButtonBox* pButtonBox = new QDialogButtonBox(
|
|
|
QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
|
|
|
Qt::Horizontal, pFooter);
|
|
|
QPushButton* pOkButton = pButtonBox->button(QDialogButtonBox::Ok);
|
|
|
QPushButton* pCancelButton = pButtonBox->button(QDialogButtonBox::Cancel);
|
|
|
pOkButton->setText(tr("OK"));
|
|
|
pOkButton->setIcon(zxLoadIcon("OK"));
|
|
|
pOkButton->setDefault(true);
|
|
|
pCancelButton->setText(tr("Cancel"));
|
|
|
pCancelButton->setIcon(zxLoadIcon("Cancel"));
|
|
|
pCancelButton->setAutoDefault(false);
|
|
|
pLayout->addWidget(pButtonBox);
|
|
|
|
|
|
// 确认仍经过原有参数校验、路径规范化和覆盖确认,不直接结束对话框。
|
|
|
connect(pButtonBox, SIGNAL(accepted()),
|
|
|
this, SLOT(acceptSettings()));
|
|
|
connect(pButtonBox, SIGNAL(rejected()),
|
|
|
this, SLOT(reject()));
|
|
|
return pFooter;
|
|
|
}
|
|
|
|
|
|
void nmWxPebiResultAnimationExportDlg::connectUiSignals()
|
|
|
{
|
|
|
connect(m_pStartFrameCombo, SIGNAL(currentIndexChanged(int)),
|
|
|
this, SLOT(onFrameRangeChanged()));
|
|
|
connect(m_pEndFrameCombo, SIGNAL(currentIndexChanged(int)),
|
|
|
this, SLOT(onFrameRangeChanged()));
|
|
|
connect(m_pSamplingIntervalSpinBox, SIGNAL(valueChanged(int)),
|
|
|
this, SLOT(updateSummary()));
|
|
|
connect(m_pFpsSpinBox, SIGNAL(valueChanged(int)),
|
|
|
this, SLOT(updateSummary()));
|
|
|
connect(m_pResolutionButtonGroup, SIGNAL(buttonClicked(int)),
|
|
|
this, SLOT(onResolutionPresetChanged(int)));
|
|
|
connect(m_pVideoFormatCombo, SIGNAL(currentIndexChanged(int)),
|
|
|
this, SLOT(onVideoFormatChanged(int)));
|
|
|
connect(m_pWidthSpinBox, SIGNAL(valueChanged(int)),
|
|
|
this, SLOT(updateSummary()));
|
|
|
connect(m_pHeightSpinBox, SIGNAL(valueChanged(int)),
|
|
|
this, SLOT(updateSummary()));
|
|
|
connect(m_pWidthSpinBox, SIGNAL(editingFinished()),
|
|
|
this, SLOT(normalizeCustomDimensions()));
|
|
|
connect(m_pHeightSpinBox, SIGNAL(editingFinished()),
|
|
|
this, SLOT(normalizeCustomDimensions()));
|
|
|
}
|
|
|
|
|
|
void nmWxPebiResultAnimationExportDlg::populateFrameItems()
|
|
|
{
|
|
|
const QStringList listTimes = nmNumericDisplayFormat::formatDistinct(m_vecFrameTimesHours);
|
|
|
for(int nFrameIndex = 0;
|
|
|
nFrameIndex < m_vecFrameTimesHours.size(); ++nFrameIndex) {
|
|
|
const QString sText = tr("%1 h").arg(listTimes[nFrameIndex]);
|
|
|
const QString sFullText = tr("%1 h").arg(
|
|
|
nmNumericDisplayFormat::fullPrecision(m_vecFrameTimesHours[nFrameIndex]));
|
|
|
m_pStartFrameCombo->addItem(sText, nFrameIndex);
|
|
|
m_pEndFrameCombo->addItem(sText, nFrameIndex);
|
|
|
m_pStartFrameCombo->setItemData(nFrameIndex, sFullText, Qt::ToolTipRole);
|
|
|
m_pEndFrameCombo->setItemData(nFrameIndex, sFullText, Qt::ToolTipRole);
|
|
|
}
|
|
|
if(!m_vecFrameTimesHours.isEmpty()) {
|
|
|
m_pStartFrameCombo->setCurrentIndex(0);
|
|
|
m_pEndFrameCombo->setCurrentIndex(
|
|
|
m_vecFrameTimesHours.size() - 1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void nmWxPebiResultAnimationExportDlg::populateVideoFormats()
|
|
|
{
|
|
|
// itemData只保存稳定扩展名,界面翻译不会参与格式识别。
|
|
|
m_pVideoFormatCombo->addItem(
|
|
|
tr("MP4 Video (*.mp4)"), QString::fromLatin1("mp4"));
|
|
|
m_pVideoFormatCombo->addItem(
|
|
|
tr("AVI Video (*.avi)"), QString::fromLatin1("avi"));
|
|
|
m_pVideoFormatCombo->addItem(
|
|
|
tr("QuickTime Video (*.mov)"), QString::fromLatin1("mov"));
|
|
|
m_pVideoFormatCombo->addItem(
|
|
|
tr("MPEG Video (*.mpg)"), QString::fromLatin1("mpg"));
|
|
|
m_pVideoFormatCombo->addItem(
|
|
|
tr("WebM Video (*.webm)"), QString::fromLatin1("webm"));
|
|
|
m_pVideoFormatCombo->addItem(
|
|
|
tr("Matroska Video (*.mkv)"), QString::fromLatin1("mkv"));
|
|
|
m_pVideoFormatCombo->addItem(
|
|
|
tr("Windows Media Video (*.wmv)"), QString::fromLatin1("wmv"));
|
|
|
m_pVideoFormatCombo->addItem(
|
|
|
tr("Flash Video (*.flv)"), QString::fromLatin1("flv"));
|
|
|
m_pVideoFormatCombo->setCurrentIndex(0);
|
|
|
}
|
|
|
|
|
|
nmPebiResultAnimationExportSettings
|
|
|
nmWxPebiResultAnimationExportDlg::collectSettings() const
|
|
|
{
|
|
|
nmPebiResultAnimationExportSettings oSettings;
|
|
|
oSettings.m_nFramesPerSecond = m_pFpsSpinBox->value();
|
|
|
oSettings.m_nStartFrameIndex =
|
|
|
m_pStartFrameCombo->itemData(
|
|
|
m_pStartFrameCombo->currentIndex()).toInt();
|
|
|
oSettings.m_nEndFrameIndex =
|
|
|
m_pEndFrameCombo->itemData(
|
|
|
m_pEndFrameCombo->currentIndex()).toInt();
|
|
|
oSettings.m_nSamplingInterval =
|
|
|
m_pSamplingIntervalSpinBox->value();
|
|
|
const QSize oOutputSize = getSelectedOutputSize();
|
|
|
oSettings.m_nOutputWidth = oOutputSize.width();
|
|
|
oSettings.m_nOutputHeight = oOutputSize.height();
|
|
|
return oSettings;
|
|
|
}
|
|
|
|
|
|
QSize nmWxPebiResultAnimationExportDlg::getSelectedOutputSize() const
|
|
|
{
|
|
|
const int nPresetId = m_pResolutionButtonGroup == nullptr
|
|
|
? Resolution_CurrentView :
|
|
|
m_pResolutionButtonGroup->checkedId();
|
|
|
if(nPresetId == Resolution_720p) {
|
|
|
return QSize(1280, 720);
|
|
|
}
|
|
|
if(nPresetId == Resolution_1080p) {
|
|
|
return QSize(1920, 1080);
|
|
|
}
|
|
|
if(nPresetId == Resolution_Custom) {
|
|
|
return QSize(
|
|
|
normalizeEvenDimension(m_pWidthSpinBox->value()),
|
|
|
normalizeEvenDimension(m_pHeightSpinBox->value()));
|
|
|
}
|
|
|
return m_oEffectiveCurrentViewportSize;
|
|
|
}
|
|
|
|
|
|
QString nmWxPebiResultAnimationExportDlg::getSelectedVideoExtension() const
|
|
|
{
|
|
|
if(m_pVideoFormatCombo == nullptr ||
|
|
|
m_pVideoFormatCombo->currentIndex() < 0) {
|
|
|
return QString();
|
|
|
}
|
|
|
const QString sExtension = m_pVideoFormatCombo->itemData(
|
|
|
m_pVideoFormatCombo->currentIndex()).toString().toLower();
|
|
|
return nmFFmpegVideoWriter::isSupportedExtension(sExtension)
|
|
|
? sExtension : QString();
|
|
|
}
|
|
|
|
|
|
QString nmWxPebiResultAnimationExportDlg::getSelectedVideoFilter() const
|
|
|
{
|
|
|
return m_pVideoFormatCombo == nullptr
|
|
|
? QString() : m_pVideoFormatCombo->currentText();
|
|
|
}
|
|
|
|
|
|
QString nmWxPebiResultAnimationExportDlg::normalizeTargetFilePath(
|
|
|
const QString& sPath) const
|
|
|
{
|
|
|
const QString sExtension = getSelectedVideoExtension();
|
|
|
if(sPath.isEmpty() || sExtension.isEmpty()) {
|
|
|
return QString();
|
|
|
}
|
|
|
|
|
|
QString sNormalizedPath = QDir::fromNativeSeparators(sPath);
|
|
|
const QString sExistingExtension =
|
|
|
QFileInfo(sNormalizedPath).suffix().toLower();
|
|
|
if(sExistingExtension.isEmpty()) {
|
|
|
if(!sNormalizedPath.endsWith('.')) {
|
|
|
sNormalizedPath.append('.');
|
|
|
}
|
|
|
sNormalizedPath.append(sExtension);
|
|
|
} else if(nmFFmpegVideoWriter::isSupportedExtension(
|
|
|
sExistingExtension)) {
|
|
|
sNormalizedPath.chop(sExistingExtension.length());
|
|
|
sNormalizedPath.append(sExtension);
|
|
|
} else {
|
|
|
sNormalizedPath.append(
|
|
|
QString::fromLatin1(".%1").arg(sExtension));
|
|
|
}
|
|
|
return QDir::cleanPath(sNormalizedPath);
|
|
|
}
|
|
|
|
|
|
QString nmWxPebiResultAnimationExportDlg::getSuggestedTargetFilePath() const
|
|
|
{
|
|
|
QString sDirectory = ZxBaseUtil::getLastDir();
|
|
|
if(sDirectory.isEmpty() || !QDir(sDirectory).exists()) {
|
|
|
sDirectory = QDir::homePath();
|
|
|
}
|
|
|
return QDir(sDirectory).absoluteFilePath(
|
|
|
QString::fromLatin1("PEBI-result.%1").arg(
|
|
|
getSelectedVideoExtension()));
|
|
|
}
|
|
|
|
|
|
void nmWxPebiResultAnimationExportDlg::setTargetFilePath(
|
|
|
const QString& sPath)
|
|
|
{
|
|
|
const QString sDisplayPath = QDir::toNativeSeparators(sPath);
|
|
|
m_pTargetPathEdit->setText(sDisplayPath);
|
|
|
m_pTargetPathEdit->setToolTip(sDisplayPath);
|
|
|
}
|
|
|
|
|
|
void nmWxPebiResultAnimationExportDlg::showError(const QString& sError)
|
|
|
{
|
|
|
m_pErrorLabel->setText(sError);
|
|
|
m_pErrorLabel->show();
|
|
|
}
|
|
|
|
|
|
void nmWxPebiResultAnimationExportDlg::clearError()
|
|
|
{
|
|
|
m_pErrorLabel->clear();
|
|
|
m_pErrorLabel->hide();
|
|
|
}
|
|
|
|
|
|
int nmWxPebiResultAnimationExportDlg::normalizeEvenDimension(int nValue)
|
|
|
{
|
|
|
nValue = qBound(2, nValue, 8192);
|
|
|
if((nValue % 2) != 0) {
|
|
|
++nValue;
|
|
|
}
|
|
|
return qMin(nValue, 8192);
|
|
|
}
|