00001 00023 #ifndef PROPERTY_DATA_H 00024 #define PROPERTY_DATA_H 00025 00026 #include <QtGui> 00027 00028 class PropertyData 00029 { 00030 public: 00031 enum DataType { MinRange=0, MaxRange, ActiveIndex, ImagePath, User, numDataType }; 00032 inline void init(bool enable = true) 00033 { 00034 PropertyItem* prop = new PropertyItem; 00035 prop->enable = enable; 00036 00037 m_properties.insert(m_name, prop); 00038 } 00039 inline void init(const QString& label, const QIcon& icon = QIcon()) 00040 { 00041 init(); 00042 setLabel(label); 00043 setIcon(icon); 00044 } 00045 00046 inline void setLabel(const QString& label) { m_properties.value(m_name)->label = label; } 00047 inline void setIcon(const QIcon& icon) { m_properties.value(m_name)->icon = icon; } 00048 inline void setName(const char* name) { m_name = name; } 00049 inline void setData(DataType type, const QVariant& value) { m_properties.value(m_name)->data[type] = value; } 00050 inline void setEnable(bool enable) { m_properties.value(m_name)->enable = enable; } 00051 inline QString label() { return m_properties.value(m_name)->label; } 00052 inline bool isEnable() { return m_properties.value(m_name)->enable; } 00053 inline bool isInit() { return m_properties.contains(m_name); } 00054 inline QVariant data(DataType type) const { return m_properties.value(m_name)->data[type]; } 00055 00056 private: 00057 struct PropertyItem 00058 { 00059 QString label; 00060 QIcon icon; 00061 bool enable; 00062 QMap <DataType, QVariant> data; 00063 }; 00064 00065 QString m_name; 00066 QHash<QString, PropertyItem*> m_properties; 00067 }; 00068 00069 class IProperty 00070 { 00071 public: 00072 virtual ~IProperty(){}; 00073 virtual QWidget* createEditor(QWidget*) = 0; 00074 virtual void updateEditor(QWidget*) = 0; 00075 00076 virtual const char* name() = 0; 00077 virtual QString label() const = 0; 00078 virtual QVariant value() const = 0; 00079 virtual QString valueToString() const = 0; 00080 virtual QString status() const = 0; 00081 00082 virtual void addChild(IProperty*) = 0; 00083 virtual void clearChildren() = 0; 00084 virtual int children() = 0; 00085 virtual IProperty* child(int) const = 0; 00086 virtual IProperty* child(const QString&) const = 0; 00087 00088 virtual int indexOf(IProperty*) = 0; 00089 virtual IProperty* parent() = 0; 00090 virtual void setParent(IProperty* parent) = 0; 00091 virtual void setFake(bool) = 0; 00092 virtual void setValue(const QVariant&) = 0; 00093 virtual bool isFake() = 0; 00094 }; 00095 00096 class AbstractProperty : public IProperty 00097 { 00098 public: 00099 AbstractProperty(const char* name, const QString& label, PropertyData* propertyData, const QVariant& value) 00100 : m_name(name), m_label(label), m_value(value), m_propertyData(propertyData), m_fake(false){}; 00101 00102 inline ~AbstractProperty() { clearChildren(); } 00103 inline QWidget* createEditor(QWidget*){ return 0; } 00104 inline void updateEditor(QWidget*) {} 00105 00106 inline const char* name() { return m_name; } 00107 inline QString label() const { return m_label; } 00108 inline QVariant value() const { return m_value; } 00109 inline QString valueToString() const { return m_value.toString(); } 00110 QString status() const; 00111 00112 inline int children() { return m_children.count(); } 00113 inline void addChild(IProperty* child) { m_children.append(child); } 00114 inline void clearChildren() { qDeleteAll(m_children); m_children.clear(); } 00115 inline IProperty* child(int index) const { return m_children.value(index); } 00116 IProperty* child(const QString&) const; 00117 00118 inline int indexOf(IProperty* child) { return m_children.indexOf(child); } 00119 inline IProperty* parent() { return m_parent; } 00120 inline void setParent(IProperty* parent) { m_parent = parent; } 00121 inline void setFake(bool fake) { m_fake = fake; } 00122 inline void setValue(const QVariant& value) { m_value = value; } 00123 inline bool isFake() { return m_fake; } 00124 00125 protected: 00126 inline PropertyData* propertyData() const { m_propertyData->setName(m_name); return m_propertyData; } 00127 00128 const char* m_name; 00129 QString m_label; 00130 QVariant m_value; 00131 00132 QList<IProperty*> m_children; 00133 00134 private: 00135 IProperty* m_parent; 00136 PropertyData* m_propertyData; 00137 bool m_fake; 00138 }; 00139 00140 class IntProperty : public AbstractProperty 00141 { 00142 public: 00143 IntProperty(const char*, const QString&, PropertyData*, int); 00144 QWidget* createEditor(QWidget*); 00145 void updateEditor(QWidget*); 00146 void setRange(int, int); 00147 00148 private: 00149 int m_min; 00150 int m_max; 00151 }; 00152 00153 class DoubleProperty : public AbstractProperty 00154 { 00155 public: 00156 DoubleProperty(const char*, const QString&, PropertyData*, double); 00157 QWidget* createEditor(QWidget*); 00158 void updateEditor(QWidget*); 00159 void setRange(double, double); 00160 00161 private: 00162 double m_min; 00163 double m_max; 00164 }; 00165 00166 class BoolProperty : public AbstractProperty 00167 { 00168 public: 00169 BoolProperty(const char*, const QString&, PropertyData*, bool); 00170 QWidget* createEditor(QWidget*); 00171 void updateEditor(QWidget*); 00172 }; 00173 00174 class StringProperty : public AbstractProperty 00175 { 00176 public: 00177 StringProperty(const char*, const QString&, PropertyData*, const QString&); 00178 QWidget* createEditor(QWidget*); 00179 void updateEditor(QWidget*); 00180 }; 00181 00182 class ListProperty : public AbstractProperty 00183 { 00184 public: 00185 ListProperty(const char*, const QString&, PropertyData*, const QStringList&); 00186 QWidget* createEditor(QWidget*); 00187 void updateEditor(QWidget*); 00188 void setCurrentIndex(int); 00189 void setValue(const QVariant&); 00190 QString status() const; 00191 QVariant value() const; 00192 QString valueToString() const; 00193 00194 private: 00195 QStringList m_list; 00196 int m_index; 00197 }; 00198 00199 class PixmapProperty : public AbstractProperty 00200 { 00201 public: 00202 PixmapProperty(const char*, const QString&, PropertyData*, const QPixmap&); 00203 QWidget* createEditor(QWidget*); 00204 void updateEditor(QWidget*); 00205 void setValue(const QVariant&); 00206 QString status() const; 00207 QVariant value() const; 00208 QString valueToString() const; 00209 void setPath(const QString&); 00210 00211 private: 00212 QString m_path; 00213 }; 00214 00215 class FamilyProperty : public AbstractProperty 00216 { 00217 public: 00218 FamilyProperty(const char*, const QString&, PropertyData*, const QFont&); 00219 QWidget* createEditor(QWidget*); 00220 void updateEditor(QWidget*); 00221 QString status() const; 00222 }; 00223 00224 class EnumProperty : public AbstractProperty 00225 { 00226 public: 00227 EnumProperty(const char*, const QString&, PropertyData*, const QMetaEnum&); 00228 QWidget* createEditor(QWidget*); 00229 void updateEditor(QWidget*); 00230 void setValue(const QVariant&); 00231 QString status() const; 00232 QVariant value() const; 00233 QString valueToString() const; 00234 void setCurrentIndex(int); 00235 00236 private: 00237 QMetaEnum m_enums; 00238 QStringList m_keys; 00239 int m_index; 00240 }; 00241 00242 class PointProperty : public AbstractProperty 00243 { 00244 public: 00245 PointProperty(const char*, const QString&, PropertyData*, const QPoint&); 00246 QVariant value() const; 00247 }; 00248 00249 class SizeProperty : public AbstractProperty 00250 { 00251 public: 00252 SizeProperty(const char*, const QString&, PropertyData*, const QSize&); 00253 QVariant value() const; 00254 }; 00255 00256 class RectProperty : public AbstractProperty 00257 { 00258 public: 00259 RectProperty(const char*, const QString&, PropertyData*, const QRect&); 00260 QVariant value() const; 00261 }; 00262 00263 class LineProperty : public AbstractProperty 00264 { 00265 public: 00266 LineProperty(const char*, const QString&, PropertyData*, const QLine&); 00267 QVariant value() const; 00268 }; 00269 00270 class PolygonProperty : public AbstractProperty 00271 { 00272 public: 00273 PolygonProperty(const char*, const QString&, PropertyData*, const QPolygon&); 00274 QVariant value() const; 00275 }; 00276 00277 class PenProperty : public AbstractProperty 00278 { 00279 public: 00280 PenProperty(const char*, const QString&, PropertyData*, const QPen&); 00281 QVariant value() const; 00282 00283 private: 00284 QStringList m_penStyle; 00285 }; 00286 00287 class BrushProperty : public AbstractProperty 00288 { 00289 public: 00290 BrushProperty(const char*, const QString&, PropertyData*, const QBrush&); 00291 QVariant value() const; 00292 00293 private: 00294 QStringList m_brushStyle; 00295 }; 00296 00297 class FontProperty : public AbstractProperty 00298 { 00299 public: 00300 FontProperty(const char*, const QString&, PropertyData*, const QFont&); 00301 QVariant value() const; 00302 }; 00303 00304 class MatrixProperty : public AbstractProperty 00305 { 00306 public: 00307 MatrixProperty(const char*, const QString&, PropertyData*, const QMatrix&); 00308 QVariant value() const; 00309 }; 00310 00311 class PixmapBox : public QWidget 00312 { 00313 Q_OBJECT 00314 00315 private slots: 00316 void openDialog(); 00317 00318 public: 00319 PixmapBox(QWidget*); 00320 00321 void setPixmap(const QPixmap&); 00322 void setPath(const QString&); 00323 QPixmap pixmap() const; 00324 QString path() const; 00325 00326 private: 00327 QPixmap m_pixmap; 00328 QString m_path; 00329 QHBoxLayout m_hbox; 00330 QLabel m_label; 00331 QPushButton m_button; 00332 }; 00333 00334 #endif