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.
83 lines
3.3 KiB
C++
83 lines
3.3 KiB
C++
#include "nmDeleteConfirmationDlg.h"
|
|
#include "ZxBaseUtil.h"
|
|
|
|
#include <QDialogButtonBox>
|
|
#include <QHBoxLayout>
|
|
#include <QLabel>
|
|
#include <QPushButton>
|
|
#include <QSizePolicy>
|
|
#include <QStyle>
|
|
#include <QVBoxLayout>
|
|
|
|
nmDeleteConfirmationDlg::nmDeleteConfirmationDlg(
|
|
const QString& sObjectName, const QString& sObjectType, QWidget* pParent)
|
|
: iDlgBase(pParent)
|
|
{
|
|
createUi(sObjectName, sObjectType);
|
|
// 按提示文字、图标和按钮计算初始尺寸,避免短提示右侧出现额外留白。
|
|
adjustSize();
|
|
}
|
|
|
|
void nmDeleteConfirmationDlg::createUi(
|
|
const QString& sObjectName, const QString& sObjectType)
|
|
{
|
|
setWindowTitle(tr("Delete object"));
|
|
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_MessageBoxWarning).pixmap(nIconSize, nIconSize));
|
|
pContentLayout->addWidget(pIconLabel, 0, Qt::AlignTop);
|
|
const QString sDisplayName = sObjectName.trimmed().isEmpty()
|
|
? tr("Unnamed object") : sObjectName;
|
|
const QString sMessage = tr("Delete %1 \"%2\"?").arg(sObjectType, sDisplayName);
|
|
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* nmDeleteConfirmationDlg::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("Delete"));
|
|
pConfirmButton->setIcon(zxLoadIcon("NmDelete"));
|
|
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;
|
|
}
|