dropshadowmgr.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #ifndef DROPSHADOWMGR_H
  2. #define DROPSHADOWMGR_H
  3. #include <QObject>
  4. #include "idropshadowable.h"
  5. class DropShadowMgr : public QObject
  6. {
  7. Q_OBJECT
  8. public:
  9. static DropShadowMgr* Instance(){return sm_pInstance;}
  10. ~DropShadowMgr() override {sm_pInstance = nullptr;}
  11. public:
  12. //static QMap<BoxShadow, QImage> sm_cacheShadows;
  13. static QList<BoxShadow> sm_cacheShadows;
  14. private:
  15. DropShadowMgr(QObject *parent = nullptr):QObject(parent){}
  16. //防拷贝, C++11
  17. DropShadowMgr(DropShadowMgr const&) = delete;
  18. DropShadowMgr& operator=(DropShadowMgr const&) = delete;
  19. private:
  20. static DropShadowMgr* sm_pInstance; //单例实例
  21. public:
  22. virtual bool eventFilter(QObject *watched, QEvent *event) override;
  23. /*----------------------------------------------------------------
  24. * 关于释放全局单例:
  25. * 一个妥善的方法是让这个类自己知道在合适的时候把自己删除; 或者说把删除自己的操作挂在系统中的某个合适的点上, 使其在恰当的时候自动被执行;
  26. * 程序在结束的时候, 系统会自动析构所有的全局变量;事实上, 系统也会析构所有的类的静态成员变量, 就像这些静态成员也是全局变量一样;
  27. * 利用这个特征, 我们可以在单例类中定义一个这样的静态成员变量, 而它的唯一工作就是在析构函数中删除单例类的实例;
  28. ----------------------------------------------------------------*/
  29. private:
  30. class DropShadowMgrGarbo
  31. {
  32. public:
  33. ~DropShadowMgrGarbo()
  34. {
  35. if(DropShadowMgr::sm_pInstance != nullptr)
  36. delete DropShadowMgr::sm_pInstance;
  37. }
  38. };
  39. static DropShadowMgrGarbo garbo;
  40. /*----------------------------------------------------------------*/
  41. };
  42. #endif // DROPSHADOWMGR_H