You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nmWTAI-Platform/Src/nmNum/nmSubWxs/nmWxPebiResultAnimationSett...

136 lines
4.7 KiB
C++

#include "nmWxPebiResultAnimationSettingsDlg.h"
#include "nmPebiResultPlaybackController.h"
#include "ZxBaseUtil.h"
#include <QCheckBox>
#include <QDialogButtonBox>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QShowEvent>
#include <QSizePolicy>
#include <QSpinBox>
#include <QTimer>
#include <QVBoxLayout>
#include <QtGlobal>
nmWxPebiResultAnimationSettingsDlg::
nmWxPebiResultAnimationSettingsDlg(
int nStepsPerSecond,
bool bLoopEnabled,
QWidget* pParent)
: 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);
m_pSpeedSpin->setValue(qBound(
static_cast<int>(
nmPebiResultPlaybackController::MinimumPlaybackSpeed),
nStepsPerSecond,
static_cast<int>(
nmPebiResultPlaybackController::MaximumPlaybackSpeed)));
m_pLoopCheck->setChecked(bLoopEnabled);
// 范围及初值回填后计算推荐尺寸,窗口宽高由内容、字体及主题共同决定。
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, 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(accept()));
connect(pButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
setTabOrder(m_pSpeedSpin, m_pLoopCheck);
setTabOrder(m_pLoopCheck, pOkButton);
setTabOrder(pOkButton, pCancelButton);
return pFooter;
}
nmWxPebiResultAnimationSettingsDlg::
~nmWxPebiResultAnimationSettingsDlg()
{
}
int nmWxPebiResultAnimationSettingsDlg::getPlaybackSpeed() const
{
return m_pSpeedSpin->value();
}
bool nmWxPebiResultAnimationSettingsDlg::isLoopEnabled() const
{
return m_pLoopCheck->isChecked();
}
void nmWxPebiResultAnimationSettingsDlg::showEvent(QShowEvent* pEvent)
{
iDlgBase::showEvent(pEvent);
m_pSpeedSpin->setFocus(Qt::OtherFocusReason);
QTimer::singleShot(0, m_pSpeedSpin, SLOT(selectAll()));
}