00001 00023 #ifndef MODULE_INTERFACE_H 00024 #define MODULE_INTERFACE_H 00025 00026 #include <QtCore> 00027 #include "property_data.h" 00028 #include "exceptions.h" 00029 00031 class ModuleInterface : public QObject 00032 { 00033 public: 00034 inline PropertyData* propertyData(const char* name) { m_property.setName(name); return &m_property; } 00035 inline void setModuleID(const QString& id) { m_moduleID = id; } 00036 inline QString moduleID() const { return m_moduleID; } 00037 00038 private: 00039 PropertyData m_property; 00040 QString m_moduleID; 00041 }; 00042 00044 class PluginInterface : public ModuleInterface 00045 { 00046 public: 00047 virtual ~PluginInterface(){}; 00048 virtual QGraphicsItem* graphicsItem() = 0; 00049 virtual bool init() = 0; 00050 virtual void timer(){}; 00051 virtual bool hasTimer() { return false; } 00052 }; 00053 00055 class ControllerInterface : public ModuleInterface 00056 { 00057 public: 00058 virtual ~ControllerInterface(){}; 00059 virtual QWidget* configWidget() = 0; 00060 virtual QSize size() = 0; 00061 virtual bool init() = 0; 00062 virtual void exit() = 0; 00063 virtual void setPixel(int, int, bool) = 0; 00064 virtual void update() = 0; 00065 virtual void clear(const QRect& rect=QRect()) = 0; 00066 }; 00067 00069 class ModuleFactory : public QObject 00070 { 00071 public: 00072 enum ModulType { Plugin, Controller, NoPlugin }; 00073 inline ModuleFactory(const QString& name, const QString& label, const QIcon& icon = QIcon()) { 00074 m_groupName = name; 00075 m_groupLabel = label; 00076 m_groupIcon = icon; 00077 } 00078 virtual ~ModuleFactory(){ qDeleteAll(m_modules.values()); }; 00079 virtual void init() = 0; 00080 virtual ModulType type() = 0; 00081 virtual ModuleInterface* create(const QString&) = 0; 00082 00083 inline QString name(int index) const { return m_modules.value(index)->name; } 00084 inline QString label(int index) const { return m_modules.value(index)->label; } 00085 inline QIcon icon(int index) const { return m_modules.value(index)->icon; } 00086 inline QString groupName() const { return m_groupName; } 00087 inline QString groupLabel() const { return m_groupLabel; } 00088 inline QIcon groupIcon() const { return m_groupIcon; } 00089 inline int count() const { return m_modules.count(); } 00090 00091 protected: 00092 inline void addModul(const QString& name, const QString& label, const QIcon& icon = QIcon()){ 00093 ModulItem* item = new ModulItem; 00094 item->name = name; 00095 item->label = label; 00096 item->icon = icon; 00097 00098 m_modules.insert(m_modules.count(), item); 00099 } 00100 00101 private: 00102 struct ModulItem 00103 { 00104 QString name; 00105 QString label; 00106 QIcon icon; 00107 }; 00108 00109 QString m_groupName; 00110 QString m_groupLabel; 00111 QIcon m_groupIcon; 00112 QMap<int, ModulItem*> m_modules; 00113 }; 00114 00115 Q_DECLARE_INTERFACE(ModuleFactory, "lcdbuilder.ModuleFactory") 00116 00117 #endif