1 #pragma once 2 3 #ifndef TSELECTION_H 4 #define TSELECTION_H 5 6 #include "menubarcommand.h" 7 #include "tcommon.h" 8 9 #undef DVAPI 10 #undef DVVAR 11 #ifdef TOONZQT_EXPORTS 12 #define DVAPI DV_EXPORT_API 13 #define DVVAR DV_EXPORT_VAR 14 #else 15 #define DVAPI DV_IMPORT_API 16 #define DVVAR DV_IMPORT_VAR 17 #endif 18 19 class QMenu; 20 class QWidget; 21 22 //============================================================================= 23 // TSelection 24 //----------------------------------------------------------------------------- 25 26 class DVAPI TSelection { 27 public: 28 class View { 29 public: ~View()30 virtual ~View(){}; 31 32 virtual void onSelectionChanged() = 0; enableCommands()33 virtual void enableCommands() {} 34 }; 35 36 public: 37 TSelection(); 38 virtual ~TSelection(); 39 40 // override this to define selection related commands enableCommands()41 virtual void enableCommands() { 42 if (m_view) m_view->enableCommands(); 43 } 44 45 // call selection handler enableCommand() 46 void enableCommand(CommandId cmdId, CommandHandlerInterface *handler); 47 48 // overridden enableCommands() will call enableCommand() 49 template <class T> enableCommand(T * target,CommandId cmdId,void (T::* method)())50 inline void enableCommand(T *target, CommandId cmdId, void (T::*method)()) { 51 enableCommand(cmdId, new CommandHandlerHelper<T>(target, method)); 52 } 53 54 template <class T, typename R> enableCommand(T * target,CommandId cmdId,void (T::* method)(R),R value)55 inline void enableCommand(T *target, CommandId cmdId, void (T::*method)(R), 56 R value) { 57 enableCommand(cmdId, 58 new CommandHandlerHelper2<T, R>(target, method, value)); 59 } 60 61 void makeCurrent(); 62 void makeNotCurrent(); 63 static TSelection *getCurrent(); 64 static void setCurrent(TSelection *selection); 65 66 virtual bool isEmpty() const = 0; 67 virtual void selectNone() = 0; 68 addMenuActions(QMenu * menu)69 virtual bool addMenuActions(QMenu *menu) { return false; } 70 void addMenuAction(QMenu *menu, CommandId cmdId); 71 setView(View * view)72 void setView(View *view) { m_view = view; } getView()73 View *getView() const { return m_view; } 74 75 void notifyView(); 76 77 private: 78 View *m_view; 79 }; 80 81 #endif // TSELECTION_H 82