#ifndef CMWIDGET_H
#define CMWIDGET_H

#include <QWidget>
#include <QString>
#include <QMap>
#include <QTimerEvent>
#include "IPermissionSupport.h"
#include "export_ctrls_common.h"
#include "cpermissioninfo.h"
#include <set>
class CTRLS_COMMON_EXPORT CMWidget : public QWidget, public IPermissionSupport {
    Q_OBJECT
public:
    explicit CMWidget(QWidget *parent = 0);
    ~CMWidget();
public:
    virtual void MInit();
    virtual void MExit();
    virtual void MTimeFresh();
    virtual void MFresh();
    virtual void MApply();

    void showEvent(QShowEvent*);
    void hideEvent(QHideEvent *);
    void paintEvent(QPaintEvent *pEvent);
    void timerEvent(QTimerEvent *pEvent);
    bool isMWidgetHidden();
    QString m_sName;
    //int32_t m_iLevel;
    typedef QMap<uintptr_t, CMWidget*> WIDGETMAP;
    WIDGETMAP mchildwidgets;

    


    void SetPermission(std::string sPermissionName, NoPermissionBehaviour noPermissionBehaviour = kReadOnly);
protected:
    virtual void InitPermissions();
    virtual void UpdatePermissionUI(bool bParentHasPermission = true);
    /*!
     * 设置object权限关联
     * 
     * \param object
     * \param permissionInfo
     */
    void SetPermission(QWidget* object, const PermissionInfo& permissionInfo);
    /*!
     * 设置控制权限关联
     * 
     * \param object
     * \param permissionInfo
     */
    void SetControlPermission(QWidget* object, const PermissionInfo& permissionInfo);
private:
    std::map<QWidget*, PermissionInfo> m_mapObjectsPermission;
    std::map<QWidget*, PermissionInfo> m_mapControlPermission;
signals:
    void shown();
public:
    virtual void showShieldWindow(bool bshow, QString &str = QString());

    bool m_bHide;
    QString m_strHide;
    bool m_bReadOnly;
    virtual void SetReadOnly(bool bReadOnly);
    int m_iTimerID;
    int m_iTimerInterval;
};

#endif // CMWIDGET_H
