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/nmSwitchOutlineConfirmation...

84 lines
3.4 KiB
C++

#include "nmSwitchOutlineConfirmationDlg.h"
#include "ZxBaseUtil.h"
#include <QDialogButtonBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QSizePolicy>
#include <QStyle>
#include <QVBoxLayout>
nmSwitchOutlineConfirmationDlg::nmSwitchOutlineConfirmationDlg(
const QString& sCurrentType, const QString& sTargetType, QWidget* pParent)
: iDlgBase(pParent)
{
createUi(sCurrentType, sTargetType);
// 按提示文字、图标和按钮计算初始尺寸,避免短提示右侧出现额外留白。
adjustSize();
}
void nmSwitchOutlineConfirmationDlg::createUi(
const QString& sCurrentType, const QString& sTargetType)
{
const bool bRedraw = sCurrentType == sTargetType;
setWindowTitle(bRedraw ? tr("Redraw boundary") : tr("Change boundary"));
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
setModal(true);
// Esc 和取消按钮均只返回拒绝结果,不执行任何删除或边界切换操作。
setIgnoreEsc(false);
QVBoxLayout* pMainLayout = new QVBoxLayout(this);
pMainLayout->setContentsMargins(12, 10, 12, 0);
pMainLayout->setSpacing(10);
QWidget* pContent = new QWidget(this);
pContent->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
QHBoxLayout* pContentLayout = new QHBoxLayout(pContent);
pContentLayout->setContentsMargins(0, 0, 0, 0);
pContentLayout->setSpacing(10);
// 提示图标与确认文字并排展示,避免把只供核对的信息排成参数编辑表单。
QLabel* pIconLabel = new QLabel(pContent);
const int nIconSize = style()->pixelMetric(QStyle::PM_MessageBoxIconSize);
pIconLabel->setPixmap(style()->standardIcon(QStyle::SP_MessageBoxQuestion).pixmap(nIconSize, nIconSize));
pContentLayout->addWidget(pIconLabel, 0, Qt::AlignTop);
const QString sMessage = bRedraw
? tr("Redraw %1?").arg(sCurrentType)
: tr("Replace %1 with %2 and start drawing?").arg(sCurrentType, sTargetType);
QLabel* pMessageLabel = new QLabel(sMessage, pContent);
// 名称中的尖括号等字符按原文显示,不被解释为富文本;长文字随窗口换行。
pMessageLabel->setTextFormat(Qt::PlainText);
pMessageLabel->setWordWrap(true);
pMessageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
pContentLayout->addWidget(pMessageLabel, 1);
pMainLayout->addWidget(pContent);
pMainLayout->addStretch(1);
pMainLayout->addWidget(createFooter());
}
QWidget* nmSwitchOutlineConfirmationDlg::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(1);
QDialogButtonBox* pButtons = new QDialogButtonBox(
QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, pFooter);
QPushButton* pConfirmButton = pButtons->button(QDialogButtonBox::Ok);
QPushButton* pCancelButton = pButtons->button(QDialogButtonBox::Cancel);
pConfirmButton->setText(tr("Start drawing"));
pConfirmButton->setIcon(zxLoadIcon("OK"));
pConfirmButton->setDefault(false);
pCancelButton->setText(tr("Cancel"));
pCancelButton->setIcon(zxLoadIcon("Cancel"));
pCancelButton->setDefault(true);
pCancelButton->setFocus(Qt::OtherFocusReason);
pLayout->addWidget(pButtons);
connect(pButtons, SIGNAL(accepted()), this, SLOT(accept()));
connect(pButtons, SIGNAL(rejected()), this, SLOT(reject()));
return pFooter;
}