128 lines
3.5 KiB
C++
128 lines
3.5 KiB
C++
/**
|
||
* @file PaiToolBar.h
|
||
* @brief 工具栏
|
||
* @date 2011-9-16
|
||
*/
|
||
#ifndef PAI_FRAME_WIDGET_PAITOOLBAR_H
|
||
#define PAI_FRAME_WIDGET_PAITOOLBAR_H
|
||
|
||
#include <QToolBar>
|
||
#include <QWidgetAction>
|
||
#include "Turtle.h"
|
||
|
||
/**
|
||
* @brief BEGIN_PAITOOLBAR_WIDGET这个宏为自定义控件创建QWidgetAction, 必须结合END_PAITOOLBAR_WIDGET使用,两个宏中间是创建自定义控件的代码
|
||
* @param[out] pWidget 返回的QAction指针,也是自定义控件的指针,两个同名,但作用域不同
|
||
* @param[in] pObject1 自定义Action的指针,用于创建信号连接,如果不需要就使用NULL,信号连接代码也写在两个宏中间,对应使用R1,R2变量
|
||
* @param[in] pObject2 自定义Action的指针
|
||
*/
|
||
#define BEGIN_PAITOOLBAR_WIDGET(pWidget, pObject1, pObject2) \
|
||
QAction *pWidget = NULL; \
|
||
{ \
|
||
QObject *pTmpReceiver1 = pObject1; \
|
||
QObject *pTmpReceiver2 = pObject2; \
|
||
class Local_Widget_Action : public QWidgetAction \
|
||
{ \
|
||
public: \
|
||
Local_Widget_Action(QObject *pReceiver1, QObject *pReciever2, QObject *pParent = NULL) : \
|
||
QWidgetAction(pParent), \
|
||
pR1(pReceiver1), \
|
||
pR2(pReciever2){} \
|
||
virtual QWidget* createWidget(QWidget *pParent) {
|
||
/**
|
||
* @brief 结束创建QWidgetAction
|
||
* @param[out] pWidget 返回的QAction指针
|
||
*/
|
||
|
||
#define END_PAITOOLBAR_WIDGET(pWidget) \
|
||
pWidget->setParent(pParent); \
|
||
return pWidget;} \
|
||
QObject *pR1, pR2; \
|
||
}* pAction = new Local_Widget_Action (pTmpReceiver1, pTmpReceiver2); \
|
||
pWidget = pAction; \
|
||
}
|
||
|
||
namespace pai
|
||
{
|
||
namespace gui
|
||
{
|
||
|
||
/**
|
||
* @class PaiToolBar
|
||
* @brief P.A.I 风格的工具栏
|
||
*/
|
||
class PAI_WIDGET_EXPORT PaiToolBar : public QToolBar
|
||
{
|
||
public:
|
||
/**
|
||
* @brief 构造函数
|
||
* @param[in] pParent 父窗口句柄
|
||
*/
|
||
PaiToolBar(QWidget *pParent = NULL);
|
||
|
||
/**
|
||
* @brief 构造函数
|
||
* @param[in] title 标题
|
||
* @param[in] pParent 父窗口句柄
|
||
*/
|
||
PaiToolBar(const QString & title, QWidget *pParent = NULL);
|
||
|
||
/**
|
||
* @brief 析构函数
|
||
*/
|
||
virtual ~PaiToolBar();
|
||
|
||
/**
|
||
* @brief 选择需要显示的边框,默认全都显示
|
||
* @param[in] top 上
|
||
* @param[in] bottom 下
|
||
* @param[in] left 左
|
||
* @param[in] right 右
|
||
*/
|
||
void ShowBorder(bool top, bool bottom, bool left, bool right);
|
||
|
||
/**
|
||
* @brief 添加一个弹簧控件使以后再添加的QAction靠右
|
||
* @return 弹簧控件对应的QAction,可以用它做Unregister
|
||
*/
|
||
QAction* AddSpacer();
|
||
|
||
/**
|
||
* @brief 设置左边缘距离
|
||
* @param[in] margin 左边缘距离
|
||
*/
|
||
void SetLeftMargin(int margin);
|
||
|
||
/**
|
||
* @brief 在标准间距(space)的基础上,再添加固定的间距
|
||
* @param[in] space 间距大小,默认4像素
|
||
* @return 对应Action
|
||
*/
|
||
QAction* AddConstSpace(int space = 4);
|
||
|
||
protected:
|
||
/**
|
||
* @brief 重绘ToolBar
|
||
* @param[in] pEvent 事件对象
|
||
*/
|
||
virtual void paintEvent(QPaintEvent *pEvent);
|
||
|
||
private:
|
||
/**
|
||
* @brief 初始化ToolBar
|
||
*/
|
||
void InitToolBar();
|
||
|
||
private:
|
||
bool m_ShowTopEdge; ///< 显示上方边界
|
||
bool m_ShowBottomEdge; ///< 显示下方边界
|
||
bool m_ShowLeftEdge; ///< 显示左方边界
|
||
bool m_ShowRightEdge; ///< 显示右方边界
|
||
QWidget *m_pLeftMarginWgt; ///< 用来支撑left margin
|
||
};
|
||
|
||
}
|
||
}
|
||
|
||
#endif ///< PAI_FRAME_WIDGET_PAITOOLBAR_H
|