Changeset View
Changeset View
Standalone View
Standalone View
src/KPropertyFactory.h
- This file was copied to src/KPropertyWidgetsFactory.h.
Show All 19 Lines | |||||
20 | #ifndef KPROPERTY_FACTORY_H | 20 | #ifndef KPROPERTY_FACTORY_H | ||
21 | #define KPROPERTY_FACTORY_H | 21 | #define KPROPERTY_FACTORY_H | ||
22 | 22 | | |||
23 | #include "KProperty.h" | 23 | #include "KProperty.h" | ||
24 | 24 | | |||
25 | #include <QObject> | 25 | #include <QObject> | ||
26 | #include <QVariant> | 26 | #include <QVariant> | ||
27 | #include <QHash> | 27 | #include <QHash> | ||
28 | #include <QLabel> | | |||
29 | #include <QPainter> | | |||
30 | #include <QStyleOptionViewItem> | | |||
31 | 28 | | |||
32 | //! An interface for for composed property handlers | 29 | //! An interface for for composed property handlers | ||
33 | /*! You have to subclass KComposedPropertyInterface to override the behaviour of a property type.\n | 30 | /*! You have to subclass KComposedPropertyInterface to override the behaviour of a property type.\n | ||
34 | In the constructor, you should create the child properties (if needed). | 31 | In the constructor, you should create the child properties (if needed). | ||
35 | Then, you need to implement the functions concerning values.\n | 32 | Then, you need to implement the functions concerning values.\n | ||
36 | 33 | | |||
37 | Example implementation of composed properties can be found in editors/ directory. | 34 | Example implementation of composed properties can be found in editors/ directory. | ||
38 | */ | 35 | */ | ||
39 | class KPROPERTY_EXPORT KComposedPropertyInterface | 36 | class KPROPERTYCORE_EXPORT KComposedPropertyInterface | ||
40 | { | 37 | { | ||
41 | public: | 38 | public: | ||
42 | explicit KComposedPropertyInterface(KProperty *parent); | 39 | explicit KComposedPropertyInterface(KProperty *parent); | ||
43 | virtual ~KComposedPropertyInterface(); | 40 | virtual ~KComposedPropertyInterface(); | ||
44 | 41 | | |||
45 | /*! This function modifies the child properties for parent value @a value. | 42 | /*! This function modifies the child properties for parent value @a value. | ||
46 | It is called by @ref Property::setValue() when | 43 | It is called by @ref Property::setValue() when | ||
47 | the property is composed. | 44 | the property is composed. | ||
Show All 13 Lines | 57 | protected: | |||
61 | virtual void childValueChanged(KProperty *child, const QVariant &value, bool rememberOldValue) = 0; | 58 | virtual void childValueChanged(KProperty *child, const QVariant &value, bool rememberOldValue) = 0; | ||
62 | 59 | | |||
63 | /*! This method emits the \a Set::propertyChanged() signal for all | 60 | /*! This method emits the \a Set::propertyChanged() signal for all | ||
64 | sets our parent-property is registered in. */ | 61 | sets our parent-property is registered in. */ | ||
65 | void emitPropertyChanged(); | 62 | void emitPropertyChanged(); | ||
66 | bool m_childValueChangedEnabled : 1; | 63 | bool m_childValueChangedEnabled : 1; | ||
67 | }; | 64 | }; | ||
68 | 65 | | |||
69 | class KPROPERTY_EXPORT KComposedPropertyCreatorInterface | 66 | class KPROPERTYCORE_EXPORT KComposedPropertyCreatorInterface | ||
70 | { | 67 | { | ||
71 | public: | 68 | public: | ||
72 | KComposedPropertyCreatorInterface(); | 69 | KComposedPropertyCreatorInterface(); | ||
73 | 70 | | |||
74 | virtual ~KComposedPropertyCreatorInterface(); | 71 | virtual ~KComposedPropertyCreatorInterface(); | ||
75 | 72 | | |||
76 | virtual KComposedPropertyInterface* createComposedProperty(KProperty *parent) const = 0; | 73 | virtual KComposedPropertyInterface* createComposedProperty(KProperty *parent) const = 0; | ||
77 | }; | 74 | }; | ||
78 | 75 | | |||
79 | //! An interface for editor widget creators. | | |||
80 | /*! Options can be set in the options attribute in order to customize | | |||
81 | widget creation process. Do this in the EditorCreatorInterface constructor. | | |||
82 | */ | | |||
83 | class KPROPERTY_EXPORT KPropertyEditorCreatorInterface | | |||
84 | { | | |||
85 | public: | | |||
86 | KPropertyEditorCreatorInterface(); | | |||
87 | | ||||
88 | virtual ~KPropertyEditorCreatorInterface(); | | |||
89 | | ||||
90 | virtual QWidget * createEditor( int type, QWidget *parent, | | |||
91 | const QStyleOptionViewItem & option, const QModelIndex & index ) const = 0; | | |||
92 | | ||||
93 | /*! Options for altering the editor widget creation process, | | |||
94 | used by KPropertyFactoryManager::createEditor(). */ | | |||
95 | class Options { | | |||
96 | public: | | |||
97 | Options(); | | |||
98 | /*! In order to have better look of the widget within the property editor view, | | |||
99 | we usually remove borders from the widget (see FactoryManager::createEditor()). | | |||
100 | and adding 1 pixel 'gray border' on the top. Default value is true. */ | | |||
101 | bool removeBorders; | | |||
102 | }; | | |||
103 | | ||||
104 | //! Options for altering the editor widget creation process | | |||
105 | Options options; | | |||
106 | }; | | |||
107 | | ||||
108 | class KPROPERTY_EXPORT KPropertyValuePainterInterface | | |||
109 | { | | |||
110 | public: | | |||
111 | KPropertyValuePainterInterface(); | | |||
112 | virtual ~KPropertyValuePainterInterface(); | | |||
113 | virtual void paint( QPainter * painter, | | |||
114 | const QStyleOptionViewItem & option, const QModelIndex & index ) const = 0; | | |||
115 | }; | | |||
116 | | ||||
117 | class KPROPERTY_EXPORT KPropertyValueDisplayInterface | | |||
118 | { | | |||
119 | public: | | |||
120 | KPropertyValueDisplayInterface(); | | |||
121 | virtual ~KPropertyValueDisplayInterface(); | | |||
122 | virtual QString displayTextForProperty( const KProperty* property ) const | | |||
123 | { return displayText(property->value()); } | | |||
124 | virtual QString displayText( const QVariant& value ) const | | |||
125 | { return value.toString(); } | | |||
126 | }; | | |||
127 | | ||||
128 | //! Label widget that can be used for displaying text-based read-only items | | |||
129 | //! Used in LabelCreator. | | |||
130 | class KPROPERTY_EXPORT KPropertyLabel : public QLabel | | |||
131 | { | | |||
132 | Q_OBJECT | | |||
133 | Q_PROPERTY(QVariant value READ value WRITE setValue USER true) | | |||
134 | public: | | |||
135 | KPropertyLabel(QWidget *parent, const KPropertyValueDisplayInterface *iface); | | |||
136 | QVariant value() const; | | |||
137 | Q_SIGNALS: | | |||
138 | void commitData( QWidget * editor ); | | |||
139 | public Q_SLOTS: | | |||
140 | void setValue(const QVariant& value); | | |||
141 | | ||||
142 | protected: | | |||
143 | virtual void paintEvent( QPaintEvent * event ); | | |||
144 | | ||||
145 | private: | | |||
146 | const KPropertyValueDisplayInterface *m_iface; | | |||
147 | QVariant m_value; | | |||
148 | }; | | |||
149 | | ||||
150 | //! Creator returning editor | | |||
151 | template<class Widget> | | |||
152 | class KPROPERTY_EXPORT KPropertyEditorCreator : public KPropertyEditorCreatorInterface, | | |||
153 | public KPropertyValueDisplayInterface, | | |||
154 | public KPropertyValuePainterInterface | | |||
155 | { | | |||
156 | public: | | |||
157 | KPropertyEditorCreator() : KPropertyEditorCreatorInterface() {} | | |||
158 | | ||||
159 | virtual ~KPropertyEditorCreator() {} | | |||
160 | | ||||
161 | virtual QWidget * createEditor( int type, QWidget *parent, | | |||
162 | const QStyleOptionViewItem & option, const QModelIndex & index ) const | | |||
163 | { | | |||
164 | Q_UNUSED(type); | | |||
165 | Q_UNUSED(option); | | |||
166 | Q_UNUSED(index); | | |||
167 | return new Widget(parent, this); | | |||
168 | } | | |||
169 | | ||||
170 | virtual void paint( QPainter * painter, | | |||
171 | const QStyleOptionViewItem & option, const QModelIndex & index ) const | | |||
172 | { | | |||
173 | painter->save(); | | |||
174 | QRect r(option.rect); | | |||
175 | r.setLeft(r.left()+1); | | |||
176 | painter->drawText( r, Qt::AlignLeft | Qt::AlignVCenter, | | |||
177 | displayText( index.data(Qt::EditRole) ) ); | | |||
178 | painter->restore(); | | |||
179 | } | | |||
180 | }; | | |||
181 | | ||||
182 | typedef KPropertyEditorCreator<KPropertyLabel> KPropertyLabelCreator; | | |||
183 | | ||||
184 | //! Creator returning composed property object | 76 | //! Creator returning composed property object | ||
185 | template<class ComposedProperty> | 77 | template<class ComposedProperty> | ||
186 | class KPROPERTY_EXPORT KComposedPropertyCreator : public KComposedPropertyCreatorInterface | 78 | class KPROPERTYCORE_EXPORT KComposedPropertyCreator : public KComposedPropertyCreatorInterface | ||
187 | { | 79 | { | ||
188 | public: | 80 | public: | ||
189 | KComposedPropertyCreator() : KComposedPropertyCreatorInterface() {} | 81 | KComposedPropertyCreator() : KComposedPropertyCreatorInterface() {} | ||
190 | 82 | | |||
191 | virtual ~KComposedPropertyCreator() {} | 83 | virtual ~KComposedPropertyCreator() {} | ||
192 | 84 | | |||
193 | virtual ComposedProperty* createComposedProperty(KProperty *parent) const { | 85 | virtual ComposedProperty* createComposedProperty(KProperty *parent) const { | ||
194 | return new ComposedProperty(parent); | 86 | return new ComposedProperty(parent); | ||
195 | } | 87 | } | ||
196 | }; | 88 | }; | ||
197 | 89 | | |||
198 | class KPROPERTY_EXPORT KPropertyFactory | 90 | class KPROPERTYCORE_EXPORT KPropertyFactory | ||
199 | { | 91 | { | ||
200 | public: | 92 | public: | ||
201 | KPropertyFactory(); | 93 | KPropertyFactory(); | ||
202 | virtual ~KPropertyFactory(); | 94 | virtual ~KPropertyFactory(); | ||
203 | QHash<int, KComposedPropertyCreatorInterface*> composedPropertyCreators() const; | 95 | QHash<int, KComposedPropertyCreatorInterface*> composedPropertyCreators() const; | ||
204 | QHash<int, KPropertyEditorCreatorInterface*> editorCreators() const; | | |||
205 | QHash<int, KPropertyValuePainterInterface*> valuePainters() const; | | |||
206 | QHash<int, KPropertyValueDisplayInterface*> valueDisplays() const; | | |||
207 | | ||||
208 | //! Adds editor creator @a creator for type @a type. | | |||
209 | //! The creator becomes owned by the factory. | | |||
210 | void addEditor(int type, KPropertyEditorCreatorInterface *creator); | | |||
211 | | ||||
212 | void addComposedPropertyCreator( int type, KComposedPropertyCreatorInterface* creator ); | 96 | void addComposedPropertyCreator( int type, KComposedPropertyCreatorInterface* creator ); | ||
213 | 97 | | |||
214 | void addPainter(int type, KPropertyValuePainterInterface *painter); | | |||
215 | | ||||
216 | void addDisplay(int type, KPropertyValueDisplayInterface *display); | | |||
217 | | ||||
218 | static void paintTopGridLine(QWidget *widget); | | |||
219 | static void setTopAndBottomBordersUsingStyleSheet(QWidget *widget, QWidget* parent, | | |||
220 | const QString& extraStyleSheet = QString()); | | |||
221 | | ||||
222 | protected: | 98 | protected: | ||
223 | void addEditorInternal(int type, KPropertyEditorCreatorInterface *editor, bool own = true); | | |||
224 | | ||||
225 | void addComposedPropertyCreatorInternal(int type, | 99 | void addComposedPropertyCreatorInternal(int type, | ||
226 | KComposedPropertyCreatorInterface* creator, bool own = true); | 100 | KComposedPropertyCreatorInterface* creator, bool own = true); | ||
227 | 101 | | |||
228 | //! Adds value painter @a painter for type @a type. | | |||
229 | //! The painter becomes owned by the factory. | | |||
230 | void addPainterInternal(int type, KPropertyValuePainterInterface *painter, bool own = true); | | |||
231 | | ||||
232 | //! Adds value-to-text converted @a painter for type @a type. | | |||
233 | //! The converter becomes owned by the factory. | | |||
234 | void addDisplayInternal(int type, KPropertyValueDisplayInterface *display, bool own = true); | | |||
235 | | ||||
236 | class Private; | 102 | class Private; | ||
237 | Private * const d; | 103 | Private * const d; | ||
238 | }; | 104 | }; | ||
239 | 105 | | |||
240 | class KProperty; | 106 | class KProperty; | ||
241 | class KCustomProperty; | 107 | class KCustomProperty; | ||
242 | 108 | | |||
243 | class KPROPERTY_EXPORT KPropertyFactoryManager : public QObject | 109 | class KPROPERTYCORE_EXPORT KPropertyFactoryManager : public QObject | ||
244 | { | 110 | { | ||
245 | Q_OBJECT | 111 | Q_OBJECT | ||
246 | public: | 112 | public: | ||
247 | bool isEditorForTypeAvailable( int type ) const; | 113 | bool isEditorForTypeAvailable( int type ) const; | ||
248 | 114 | | |||
249 | QWidget * createEditor( | | |||
250 | int type, | | |||
251 | QWidget *parent, | | |||
252 | const QStyleOptionViewItem & option, | | |||
253 | const QModelIndex & index ) const; | | |||
254 | | ||||
255 | bool paint( int type, | | |||
256 | QPainter * painter, | | |||
257 | const QStyleOptionViewItem & option, | | |||
258 | const QModelIndex & index ) const; | | |||
259 | | ||||
260 | KComposedPropertyInterface* createComposedProperty(KProperty *parent); | 115 | KComposedPropertyInterface* createComposedProperty(KProperty *parent); | ||
261 | 116 | | |||
262 | bool canConvertValueToText( int type ) const; | | |||
263 | | ||||
264 | bool canConvertValueToText( const KProperty* property ) const; | | |||
265 | | ||||
266 | QString convertValueToText( const KProperty* property ) const; | | |||
267 | | ||||
268 | //! Registers factory @a factory. It becomes owned by the manager. | 117 | //! Registers factory @a factory. It becomes owned by the manager. | ||
269 | void registerFactory(KPropertyFactory *factory); | 118 | void registerFactory(KPropertyFactory *factory); | ||
270 | 119 | | |||
271 | KCustomProperty* createCustomProperty( KProperty *parent ); | 120 | KCustomProperty* createCustomProperty( KProperty *parent ); | ||
272 | 121 | | |||
273 | /*! \return a pointer to a factory manager instance.*/ | 122 | /*! \return a pointer to a factory manager instance.*/ | ||
274 | static KPropertyFactoryManager* self(); | 123 | static KPropertyFactoryManager* self(); | ||
275 | 124 | | |||
Show All 9 Lines |