logplus/Workflow/WFWidget/include/PaiMessageBox.h
2026-01-17 12:55:45 +08:00

323 lines
10 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @file PaiMessageBox.h
* @brief 实现自定义的MessageBox对话框
* @date 2012-03-06
*/
#ifndef PAI_FRAME_PIPROJECTMANAGEMENT_PAIMESSAGEBOX_H
#define PAI_FRAME_PIPROJECTMANAGEMENT_PAIMESSAGEBOX_H
#include <QMap>
#include "PaiDialog.h"
#include "Turtle.h"
class QLabel;
namespace pai
{
namespace gui
{
class PaiPushButton;
class PaiTextEdit;
}
}
namespace pai
{
namespace gui
{
/**
* @class PaiMessageBox
* @brief 自定义的MessageBox对话框
*/
class PAI_WIDGET_EXPORT PaiMessageBox : public PaiDialog
{
Q_OBJECT
Q_ENUMS(Icon)
Q_FLAGS(StandardButtons)
public:
/**
* @enum Icon
* @brief 标准内置提示图标
*/
enum Icon
{
Icon_None = 0, ///< 无图标
Icon_Information = 1, ///< 信息图标
Icon_Warning = 2, ///< 警告图标
Icon_Critical = 3, ///< 错误图标
Icon_Question = 4 ///< 提问图标
};
/**
* @enum StandardButton
* @brief 内置标准按钮
*/
enum StandardButton
{
NoButton = 0x00000000, ///< 无按钮
Ok = 0x00000400, ///< OK按钮
Save = 0x00000800, ///< 保存按钮
SaveAll = 0x00001000, ///< 保存所有按钮
Open = 0x00002000, ///< 打开按钮
Yes = 0x00004000, ///< Yes按钮
YesToAll = 0x00008000, ///< Yes to all 按钮
No = 0x00010000, ///< NO按钮
NoToAll = 0x00020000, ///< NO to all 按钮
Abort = 0x00040000, ///< 忽略按钮
Retry = 0x00080000, ///< 重试按钮
Ignore = 0x00100000, ///< 忽略按钮
Close = 0x00200000, ///< 关闭按钮
Cancel = 0x00400000, ///< 取消按钮
Discard = 0x00800000, ///< 打开按钮
Help = 0x01000000, ///< 放弃按钮
Apply = 0x02000000, ///< 应用按钮
Reset = 0x04000000, ///< 重置按钮
RestoreDefaults = 0x08000000, ///< 恢复默认按钮
FirstButton = Ok, ///< 首个按钮
LastButton = RestoreDefaults///< 末尾按钮
};
Q_DECLARE_FLAGS(StandardButtons, StandardButton)
/**
* @brief 构造函数
* @param[in] pParent 父对象
*/
PaiMessageBox(QWidget *pParent = NULL);
/**
* @brief 构造函数
* @param[in] icon 内置标准图标
* @param[in] title 对话框标题
* @param[in] text 显示的提示文本
* @param[in] buttons 要使用的标准按钮
* @param[in] pParent 父对象
* @param[in] flag 对话框属性标志位
*/
PaiMessageBox(Icon icon,
const QString & title,
const QString & text,
StandardButtons buttons = NoButton,
QWidget *pParent = NULL,
Qt::WindowFlags flag = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
/**
* @brief 构造函数
* @param[in] icon 内置标准图标
* @param[in] title 对话框标题
* @param[in] text 显示的提示文本
* @param[in] details 显示的细节文本会用TextEdit来显示。
* @param[in] buttons 要使用的标准按钮
* @param[in] pParent 父类
* @param[in] flag 对话框属性标志位
*/
PaiMessageBox(Icon icon,
const QString & title,
const QString & text,
const QString & details,
StandardButtons buttons = NoButton,
QWidget *pParent = NULL,
Qt::WindowFlags flag = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
/**
* @brief 析构函数
*/
virtual ~PaiMessageBox ();
/**
* @brief 设置标准图标
* @param[in] icon 图标
*/
void SetIcon(Icon icon);
/**
* @brief 设置标准按钮
* @param[in] buttons 按钮
*/
void SetStandardButtons(StandardButtons buttons);
/**
* @brief 设置默认按钮
* @param[in] button 默认按钮
*/
void SetDefaultButton(StandardButton button);
/**
* @brief 设置显示文本
* @param[in] text 文本内容
*/
void SetText(const QString & text);
/**
* @brief 设置细节描述文本
* @param[in] text 文本内容
*/
void SetDetailedText(const QString & text);
/**
* @brief 更改标准按钮的名字
* @param[in] button 标准按钮
* @param[in] name 新名字
*/
void SetStandardButtonName(StandardButton button, const QString & name);
/**
* @brief 获得当前详细描述信息
* @return 当前详细描述信息
*/
QString GetDetailedText() const;
/**
* @brief 标准提示对话框
* @param[in] pParent 父类
* @param[in] title 对话框标题
* @param[in] text 显示的提示文本
* @param[in] buttons 要使用的标准按钮
* @param[in] defaultButton 默认按钮
* @return 触发按钮
*/
static StandardButton Information(QWidget *pParent,
const QString & title,
const QString & text,
StandardButtons buttons = Ok,
StandardButton defaultButton = NoButton);
/**
* @brief 标准提问对话框
* @param[in] pParent 父类
* @param[in] title 对话框标题
* @param[in] text 显示的提示文本
* @param[in] buttons 要使用的标准按钮
* @param[in] defaultButton 默认按钮
* @return 触发按钮
*/
static StandardButton Question(QWidget *pParent,
const QString & title,
const QString & text,
StandardButtons buttons = Ok,
StandardButton defaultButton = NoButton);
/**
* @brief 标准警告对话框
* @param[in] pParent 父类
* @param[in] title 对话框标题
* @param[in] text 显示的提示文本
* @param[in] buttons 要使用的标准按钮
* @param[in] defaultButton 默认按钮
* @return 触发按钮
*/
static StandardButton Warning(QWidget *pParent,
const QString & title,
const QString & text,
StandardButtons buttons = Ok,
StandardButton defaultButton = NoButton);
/**
* @brief 标准严重错误对话框
* @param[in] pParent 父类
* @param[in] title 对话框标题
* @param[in] text 显示的提示文本
* @param[in] buttons 要使用的标准按钮
* @param[in] defaultButton 默认按钮
* @return 触发按钮
*/
static StandardButton Critical(QWidget *pParent,
const QString & title,
const QString & text,
StandardButtons buttons = Ok,
StandardButton defaultButton = NoButton);
protected:
/**
* @brief 点击析用退出按钮
* @param[in] pEvent 关闭事件
*/
void closeEvent(QCloseEvent *pEvent);
private:
/**
* @brief 静态标准对话框
* @param[in] pParent 父类
* @param[in] title 对话框标题
* @param[in] text 显示的提示文本
* @param[in] buttons 要使用的标准按钮
* @param[in] defaultButton 默认按钮
*/
static StandardButton ShowNewMessageBox(QWidget *pParent,
Icon icon,
const QString & title,
const QString & text,
StandardButtons buttons,
StandardButton defaultButton);
/**
* @brief 初始化对话框
*/
void InitDialog();
/**
* @brief 获得标准按钮的显示文本
* @param[in] button 标准按钮
* @return 标准按钮的显示文本
*/
QString GetStandardButtonText(StandardButton button);
/**
* @brief 添加一个标准按钮,使用该函数后务必
* 调用RestoreButtonPos来调整布局
* @param[in] button 标准按钮
* @return 标准按钮
*/
PaiPushButton* AddButton(StandardButton button);
/**
* @brief 重新按以设定好的顺序调整布局
*/
void RestoreButtonPos();
/**
* @brief 获得点击系统关闭按钮后等同功能的按钮
* @return 点击系统关闭按钮后等同功能的按钮
*/
StandardButton DetectedEscapeButton();
/**
* @brief 设置返回值为该button
* @param[in] button 要返回的按钮
*/
void SetResutlButton(StandardButton button);
private slots:
/**
* @brief 表准按钮被点击时执行
*/
void ButtonClicked();
private:
QLabel *m_pIconLabel; ///< 图标标签
QLabel *m_pTextLabel; ///< 文本标签
QWidget *m_pBtnWgt; ///< 按钮组件
PaiTextEdit *m_pDetailsTEdit; ///< 文本编辑组件
QMap<StandardButton, PaiPushButton*> m_FlagToBtn; ///< 标记和对应的按钮映射
QList<StandardButton> m_BtnPos; ///< separate left and right with NoButton
QList<StandardButton> m_EscapeBtns; ///< 退出按钮
QMap<StandardButton, QString> m_BtnNames; ///< the name of the standard button
signals:
/**
* @brief 当点击标准按钮时发射该信号
* @param[in] button 点击的按钮
*/
void ButtonClicked(StandardButton button);
};
}
}
Q_DECLARE_OPERATORS_FOR_FLAGS(pai::gui::PaiMessageBox::StandardButtons)
#endif ///< PAI_FRAME_PIPROJECTMANAGEMENT_PAIMESSAGEBOX_H