fix(Nm): 统一动画设置界面并优化伸缩布局

- 统一窗口主题、框架图标及底部按钮布局
- 调整速度输入框伸缩方式,移除固定最小宽度
- 整理初始化代码并补充中文注释和按钮翻译
feature/Dialog-Unification-20261106
lh 17 hours ago
parent 8a586e02eb
commit 257c1940c1

Binary file not shown.

@ -3423,6 +3423,8 @@ No valid error was returned; keep the last accepted result and reduce the step.<
<message><source>Animation settings</source><translation>动画设置</translation></message>
<message><source>Loop enabled</source><translation>启用循环</translation></message>
<message><source>Speed (steps/second)</source><translation>速度(步/秒)</translation></message>
<message><source>OK</source><translation>确定</translation></message>
<message><source>Cancel</source><translation>取消</translation></message>
</context>
<context>
<name>nmWxPebiResultFilterSettingsDlg</name>

@ -1,10 +1,9 @@
#ifndef NMWXPEBIRESULTANIMATIONSETTINGSDLG_H
#define NMWXPEBIRESULTANIMATIONSETTINGSDLG_H
#include "iDlgBase.h"
#include "nmSubWxs_global.h"
#include <QDialog>
class QCheckBox;
class QShowEvent;
class QSpinBox;
@ -16,7 +15,7 @@ class QSpinBox;
* 两个值并事务式提交,因此取消或关闭对话框不会改变窗口偏好。
*/
class NM_SUB_WXS_EXPORT nmWxPebiResultAnimationSettingsDlg
: public QDialog
: public iDlgBase
{
Q_OBJECT
@ -46,6 +45,13 @@ protected:
private:
Q_DISABLE_COPY(nmWxPebiResultAnimationSettingsDlg)
/** @brief 创建统一主题下的表单与底栏,纵向余量不拉高输入控件。 */
void createUi();
/** @brief 创建随窗口横向伸展的速度输入框和循环选项。 */
QWidget* createFields();
/** @brief 创建靠右的标准确认、取消按钮,连接原有接受/拒绝流程。 */
QWidget* createFooter();
/** @brief 限制为正整数步/秒的速度输入框。 */
QSpinBox* m_pSpeedSpin;
/** @brief 是否在末帧之后回到第 0 帧。 */

@ -1,45 +1,38 @@
#include "nmWxPebiResultAnimationSettingsDlg.h"
#include "nmPebiResultPlaybackController.h"
#include "ZxBaseUtil.h"
#include <QCheckBox>
#include <QCoreApplication>
#include <QDialogButtonBox>
#include <QFormLayout>
#include <QIcon>
#include <QLayout>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QShowEvent>
#include <QSize>
#include <QSizePolicy>
#include <QSpinBox>
#include <QTimer>
#include <QVBoxLayout>
#include <QtGlobal>
namespace {
QString resultAnimationIconPath(const QString& sFileName)
{
const QString sApplicationDir = QCoreApplication::applicationDirPath();
return sApplicationDir.section('/', 0, -2) +
"/Res/Icon/" + sFileName;
}
}
nmWxPebiResultAnimationSettingsDlg::
nmWxPebiResultAnimationSettingsDlg(
int nStepsPerSecond,
bool bLoopEnabled,
QWidget* pParent)
: QDialog(pParent),
m_pSpeedSpin(new QSpinBox(this)),
m_pLoopCheck(new QCheckBox(tr("Loop enabled"), this))
: iDlgBase(pParent),
m_pSpeedSpin(nullptr),
m_pLoopCheck(nullptr)
{
setWindowTitle(tr("Animation settings"));
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
setModal(true);
// 接入统一窗口主题,同时沿用原窗口按 Esc 取消的行为。
setIgnoreEsc(false);
createUi();
// 控件只保存临时值,播放参数仍由调用方在确认后统一提交。
m_pSpeedSpin->setRange(
nmPebiResultPlaybackController::MinimumPlaybackSpeed,
nmPebiResultPlaybackController::MaximumPlaybackSpeed);
@ -51,35 +44,72 @@ nmWxPebiResultAnimationSettingsDlg(
nmPebiResultPlaybackController::MaximumPlaybackSpeed)));
m_pLoopCheck->setChecked(bLoopEnabled);
QFormLayout* pFormLayout = new QFormLayout();
pFormLayout->addRow(tr("Speed (steps/second)"), m_pSpeedSpin);
pFormLayout->addRow(QString(), m_pLoopCheck);
// 范围及初值回填后计算推荐尺寸,窗口宽高由内容、字体及主题共同决定。
adjustSize();
}
void nmWxPebiResultAnimationSettingsDlg::createUi()
{
QVBoxLayout* pMainLayout = new QVBoxLayout(this);
pMainLayout->setContentsMargins(12, 10, 12, 0);
pMainLayout->setSpacing(10);
pMainLayout->addWidget(createFields());
// 纵向余量留在内容与底栏之间,速度输入框和复选框不随窗口拉高。
pMainLayout->addStretch(1);
pMainLayout->addWidget(createFooter());
}
QWidget* nmWxPebiResultAnimationSettingsDlg::createFields()
{
QWidget* pFields = new QWidget(this);
pFields->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
QGridLayout* pLayout = new QGridLayout(pFields);
pLayout->setContentsMargins(0, 0, 0, 0);
pLayout->setHorizontalSpacing(6);
pLayout->setVerticalSpacing(6);
pLayout->setColumnStretch(1, 1);
QLabel* pSpeedLabel = new QLabel(tr("Speed (steps/second)"), pFields);
pSpeedLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
m_pSpeedSpin = new QSpinBox(pFields);
// 横向由布局分配剩余空间,纵向采用主题推荐高度,不固定像素尺寸。
m_pSpeedSpin->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
m_pLoopCheck = new QCheckBox(tr("Loop enabled"), pFields);
pLayout->addWidget(pSpeedLabel, 0, 0);
pLayout->addWidget(m_pSpeedSpin, 0, 1);
pLayout->addWidget(m_pLoopCheck, 1, 1);
return pFields;
}
QWidget* nmWxPebiResultAnimationSettingsDlg::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, this);
QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
Qt::Horizontal, pFooter);
QPushButton* pOkButton = pButtonBox->button(QDialogButtonBox::Ok);
QPushButton* pCancelButton =
pButtonBox->button(QDialogButtonBox::Cancel);
const QSize oButtonIconSize(16, 16);
pOkButton->setIcon(QIcon(resultAnimationIconPath(
QString::fromLatin1("OK.png"))));
pCancelButton->setIcon(QIcon(resultAnimationIconPath(
QString::fromLatin1("Cancel.png"))));
pOkButton->setIconSize(oButtonIconSize);
pCancelButton->setIconSize(oButtonIconSize);
pOkButton->setMinimumWidth(72);
pCancelButton->setMinimumWidth(72);
if(pButtonBox->layout() != nullptr) {
pButtonBox->layout()->setSpacing(6);
}
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(accept()));
connect(pButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
QVBoxLayout* pMainLayout = new QVBoxLayout(this);
pMainLayout->addLayout(pFormLayout);
pMainLayout->addWidget(pButtonBox);
setMinimumWidth(320);
setTabOrder(m_pSpeedSpin, m_pLoopCheck);
setTabOrder(m_pLoopCheck, pOkButton);
setTabOrder(pOkButton, pCancelButton);
return pFooter;
}
nmWxPebiResultAnimationSettingsDlg::
@ -99,7 +129,7 @@ bool nmWxPebiResultAnimationSettingsDlg::isLoopEnabled() const
void nmWxPebiResultAnimationSettingsDlg::showEvent(QShowEvent* pEvent)
{
QDialog::showEvent(pEvent);
iDlgBase::showEvent(pEvent);
m_pSpeedSpin->setFocus(Qt::OtherFocusReason);
QTimer::singleShot(0, m_pSpeedSpin, SLOT(selectAll()));
}

Loading…
Cancel
Save