235 lines
6.6 KiB
C
235 lines
6.6 KiB
C
|
|
/**
|
|||
|
|
* @file PaiLineEdit.h
|
|||
|
|
* @brief PaiLineEdit是P.A.I系统定制发布的单行文本框控件
|
|||
|
|
* @date 2011-10-21
|
|||
|
|
*/
|
|||
|
|
#ifndef PAI_FRAME_WIDGET_PAILINEEDIT_H
|
|||
|
|
#define PAI_FRAME_WIDGET_PAILINEEDIT_H
|
|||
|
|
|
|||
|
|
#include <QLineEdit>
|
|||
|
|
#include "Turtle.h"
|
|||
|
|
class QTimer;
|
|||
|
|
class QPushButton;
|
|||
|
|
|
|||
|
|
namespace pai
|
|||
|
|
{
|
|||
|
|
class SmartCompleter;
|
|||
|
|
namespace gui
|
|||
|
|
{
|
|||
|
|
/**
|
|||
|
|
* @class PaiLineEdit
|
|||
|
|
* @brief P.A.I系统定制发布的单行文本框控件,用户可以方便地设置密码风格,错误风格和搜索框风格
|
|||
|
|
*/
|
|||
|
|
class PAI_WIDGET_EXPORT PaiLineEdit : public QLineEdit
|
|||
|
|
{
|
|||
|
|
Q_OBJECT
|
|||
|
|
public:
|
|||
|
|
/**
|
|||
|
|
* @enum PromptType
|
|||
|
|
* @brief 不同模式下文字显示的颜色和图标不同
|
|||
|
|
*/
|
|||
|
|
enum PromptType
|
|||
|
|
{
|
|||
|
|
PT_NULL, ///< 无提示信息
|
|||
|
|
PT_Information, ///< 普通信息
|
|||
|
|
PT_Question, ///< 疑问信息
|
|||
|
|
PT_Warning, ///< 警告信息
|
|||
|
|
PT_Error ///< 错误信息
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 构造函数
|
|||
|
|
* @param[in] pParent 父窗口句柄
|
|||
|
|
*/
|
|||
|
|
PaiLineEdit(QWidget *pParent = NULL);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 构造函数
|
|||
|
|
* @param[in] text 单行文本框里的文本初始值
|
|||
|
|
* @param[in] pParent 父窗口句柄
|
|||
|
|
*/
|
|||
|
|
PaiLineEdit(const QString & text, QWidget *pParent = NULL);
|
|||
|
|
~PaiLineEdit();
|
|||
|
|
/**
|
|||
|
|
* @brief 设置校验器的错误提示
|
|||
|
|
* @param[in] validateFailure 校验器的错误提示
|
|||
|
|
*/
|
|||
|
|
void SetValidatorFailureMessage(const QString & validateFailure);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 设置超出最大长度的错误提示
|
|||
|
|
* @param[in] exceedMaxLength 超出最大长度的错误提示
|
|||
|
|
*/
|
|||
|
|
void SetExceedMaxLengthMessage(const QString & exceedMaxLength);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 当输入框内没有文字的时候显示该提示信息
|
|||
|
|
* @param[in] text 提示信息
|
|||
|
|
* @note 请勿使用基类的 setPlaceholderText()
|
|||
|
|
*/
|
|||
|
|
void setPlaceholderText(const QString & text);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 获得 placeholder 信息
|
|||
|
|
* @return 文本
|
|||
|
|
*/
|
|||
|
|
QString placeholderText() const;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 显示提示信息
|
|||
|
|
* @param[in] message 输入需显示的信息
|
|||
|
|
* @param[in] type 输入需显示的错误表示
|
|||
|
|
*/
|
|||
|
|
virtual void ShowPromptMessge(const QString & message, PromptType type = PT_Information);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 输入框是否为空
|
|||
|
|
* return true 空 false 非空
|
|||
|
|
*/
|
|||
|
|
bool IsEmpty();
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 设置输入字符后多长时间没有响应就认为编辑停止
|
|||
|
|
* @param[in] duration 持续时间(毫秒),当前默认300毫秒
|
|||
|
|
* @note 如果过编辑完成,则同时立即认为编辑停止,不再等待
|
|||
|
|
* 如需等待搜索结果,再响应returnPressed或editFilished等信号,
|
|||
|
|
* 请将该值设为60ms以下,根据测试人从输入字符到按回车键的间隔在60ms以下
|
|||
|
|
*/
|
|||
|
|
void SetEditStopDuration(int duration);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 设置模糊匹配Completer
|
|||
|
|
* @param[in] pComleter 模糊匹配Completer的指针
|
|||
|
|
*/
|
|||
|
|
void SetSmartCompleter(pai::SmartCompleter *pComleter);
|
|||
|
|
/**
|
|||
|
|
* @brief 得到当前模糊匹配Completer
|
|||
|
|
*/
|
|||
|
|
pai::SmartCompleter *SmartCompleter() const;
|
|||
|
|
|
|||
|
|
|
|||
|
|
protected:
|
|||
|
|
/**
|
|||
|
|
* @brief 向文本框的右侧设置搜索按钮
|
|||
|
|
* @param[in] iconPath icon路径
|
|||
|
|
*/
|
|||
|
|
void SetRightIcon(const QString & iconPath);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 检验输入的是否合法并显示警告信息
|
|||
|
|
* @param[in] inputText 输入的字符串
|
|||
|
|
*/
|
|||
|
|
void CheckInput(const QString & inputText);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 重写mousePressEvent
|
|||
|
|
* @param[in] pEvent 鼠标按压事件
|
|||
|
|
*/
|
|||
|
|
virtual void mousePressEvent(QMouseEvent *pEvent);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 设置LineEdit 的宽度
|
|||
|
|
* @return 控件的宽度和高度
|
|||
|
|
*/
|
|||
|
|
virtual QSize sizeHint() const;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 重新实现该函数来添加额外的元素
|
|||
|
|
* @param[in] pEvent 重绘事件
|
|||
|
|
*/
|
|||
|
|
virtual void paintEvent(QPaintEvent *pEvent);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 重新keyReleaseEvent函数 为了实现输入非法字符,提示警告信息
|
|||
|
|
* @param[in] pEvent 键盘释放事件
|
|||
|
|
*/
|
|||
|
|
virtual void keyReleaseEvent(QKeyEvent *pEvent);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief keyPressEvent函数 为了实现输入非法字符,提示警告信息
|
|||
|
|
* @param[in] pEvent 键盘按压事件
|
|||
|
|
*/
|
|||
|
|
virtual void keyPressEvent(QKeyEvent *pEvent);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 重写inputMethodEvent函数 为了实现输入非法字符,提示警告信息
|
|||
|
|
* @param[in] pEvent 输入方式事件
|
|||
|
|
*/
|
|||
|
|
virtual void inputMethodEvent(QInputMethodEvent *pEvent);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 重写contextMenuEvent函数 为了实现输入字符长度大于100时,提示警告信息
|
|||
|
|
* @param[in] pEvent 上下文菜单事件
|
|||
|
|
*/
|
|||
|
|
virtual void contextMenuEvent(QContextMenuEvent *pEvent);
|
|||
|
|
|
|||
|
|
private:
|
|||
|
|
/**
|
|||
|
|
* @brief 初始化控件
|
|||
|
|
*/
|
|||
|
|
void Init();
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 处理键盘上下键和回车键的操作
|
|||
|
|
* @param[in] key 键盘上被按的方向键
|
|||
|
|
*/
|
|||
|
|
void DealDirectionKey(int key);
|
|||
|
|
|
|||
|
|
private slots:
|
|||
|
|
/**
|
|||
|
|
* @brief 文本编辑完成
|
|||
|
|
*/
|
|||
|
|
void TextEditingFinished();
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 编辑停止超过固定秒后发送停止信号,时间间隙可由SetEditStopDuration(...)函数设置
|
|||
|
|
*/
|
|||
|
|
void EmitEditingStoped();
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief FuzzyComleter的响应
|
|||
|
|
*/
|
|||
|
|
void InsertCompletion(const QString &completion);
|
|||
|
|
|
|||
|
|
protected:
|
|||
|
|
QString m_PlaceholderText; ///< Placeholder文本
|
|||
|
|
QString m_PromptMessage; ///< 提示信息
|
|||
|
|
QString m_ValidateMessage; ///< 校验信息
|
|||
|
|
QString m_ExceedMaxLengthMessage; ///< 过长信息
|
|||
|
|
PromptType m_PromptType; ///< 提示类型
|
|||
|
|
QTimer *m_pDelayTimer; ///< 用于检查是否停止编辑
|
|||
|
|
QPushButton *m_pRightPBtn; ///< 按钮
|
|||
|
|
pai::SmartCompleter *m_pCompleter; ///< 模糊匹配的
|
|||
|
|
|
|||
|
|
signals:
|
|||
|
|
/**
|
|||
|
|
* @brief 文本编辑完成
|
|||
|
|
* @param[in] text 当前文本
|
|||
|
|
*/
|
|||
|
|
void EditingFinished(const QString & text);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 编辑停止
|
|||
|
|
* @note 如果过编辑完成,则同时立即发射该信号,不再等待
|
|||
|
|
* 如需等待搜索结果,再响应returnPressed或editFilished等信号,
|
|||
|
|
* 请将该值设为60ms以下,根据测试人从输入字符到按回车键的间隔在60ms以下
|
|||
|
|
* @param[in] text 当前文本
|
|||
|
|
*/
|
|||
|
|
void EditingStoped(const QString & text);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 右边的按钮被点击后触发的信号
|
|||
|
|
*/
|
|||
|
|
void RightIconClicked();
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
*@brief 点击鼠标发出此信号
|
|||
|
|
*/
|
|||
|
|
void LeftMousePress();
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endif ///< PAI_FRAME_WIDGET_PAILINEEDIT_H
|