]> SALOME platform Git repositories - modules/gui.git/blob - src/ObjBrowser/OB_ListItem.cxx
Salome HOME
no message
[modules/gui.git] / src / ObjBrowser / OB_ListItem.cxx
1 #include "OB_ListItem.h"
2
3 #include "OB_ListView.h"
4
5 #include <SUIT_DataObject.h>
6
7 #include <qpainter.h>
8 #include <qwmatrix.h>
9
10 /*!
11     Class: ListItem
12     Descr: base template class
13 */
14 template<class T>
15 ListItem<T>::ListItem( SUIT_DataObject* obj, QListView* parent )
16 : T( parent ),
17 myObject( obj )
18 {
19   update();
20 }
21
22 template<class T>
23 ListItem<T>::ListItem( SUIT_DataObject* obj, QListViewItem* parent )
24 : T( parent ),
25 myObject( obj )
26 {
27   update();
28 }
29
30 template<class T>
31 ListItem<T>::ListItem( SUIT_DataObject* obj, QListView* parent, QListViewItem* after )
32 : T( parent, after ),
33 myObject( obj )
34 {
35   update();
36 }
37
38 template<class T>
39 ListItem<T>::ListItem( SUIT_DataObject* obj, QListViewItem* parent, QListViewItem* after )
40 : T( parent, after ),
41 myObject( obj )
42 {
43   update();
44 }
45
46 template<class T>
47 ListItem<T>::ListItem( SUIT_DataObject* obj, QListView* parent, int type )
48 : T( parent, "", (typename T::Type)type ),
49 myObject( obj )
50 {
51   update();
52 }
53
54 template<class T>
55 ListItem<T>::ListItem( SUIT_DataObject* obj, QListViewItem* parent, int type )
56 : T( parent, "", (typename T::Type)type ),
57 myObject( obj )
58 {
59   update();
60 }
61
62 template<class T>
63 ListItem<T>::ListItem( SUIT_DataObject* obj, QListView* parent, QListViewItem* after, int type )
64 #if defined(QT_VERSION) && QT_VERSION >= 0x030101
65 : T( parent, after, "", (typename T::Type)type ),
66 #else
67 : T( parent, "", (typename T::Type)type ),
68 #endif
69 myObject( obj )
70 {
71   update();
72 }
73
74 template<class T>
75 ListItem<T>::ListItem( SUIT_DataObject* obj, QListViewItem* parent, QListViewItem* after, int type )
76 #if defined(QT_VERSION) && QT_VERSION >= 0x030101
77 : T( parent, after, "", (typename T::Type)type ),
78 #else
79 : T( parent, "", (typename T::Type)type ),
80 #endif
81 myObject( obj )
82 {
83   update();
84 }
85
86 template<class T>
87 void ListItem<T>::paintCell( QPainter* p, const QColorGroup& cg, int c, int w, int align )
88
89   QColorGroup colorGrp( cg );
90   if ( myObject )
91   {
92     if ( myObject->color( SUIT_DataObject::Text ).isValid() )
93       colorGrp.setColor( QColorGroup::Text, myObject->color( SUIT_DataObject::Text ) );
94     if ( myObject->color( SUIT_DataObject::Base ).isValid() )
95       colorGrp.setColor( QColorGroup::Base, myObject->color( SUIT_DataObject::Base ) );
96     if ( myObject->color( SUIT_DataObject::Foreground ).isValid() )
97       colorGrp.setColor( QColorGroup::Foreground, myObject->color( SUIT_DataObject::Foreground ) );
98     if ( myObject->color( SUIT_DataObject::Background ).isValid() )
99       colorGrp.setColor( QColorGroup::Background, myObject->color( SUIT_DataObject::Background ) );
100     if ( myObject->color( SUIT_DataObject::Highlight ).isValid() )
101       colorGrp.setColor( QColorGroup::Highlight, myObject->color( SUIT_DataObject::Highlight ) );
102   }
103
104   
105   p->fillRect( 0, 0, w, this->height(), colorGrp.brush( QColorGroup::Base ) );
106   int itemW = width( p->fontMetrics(), this->listView(), c );
107     
108   T::paintCell( p, colorGrp, c, itemW,  align );
109 }
110
111 template<class T>
112 void ListItem<T>::paintFocus( QPainter* p, const QColorGroup& cg, const QRect& r )
113 {
114   QRect rect = r;
115   rect.setWidth( width( p->fontMetrics(), this->listView(), 0 ) );
116   T::paintFocus( p, cg, rect );
117 }
118
119 template<class T>
120 void ListItem<T>::setSelected( bool s )
121 {
122   if ( s && listView() && listView()->inherits( "OB_ListView" ) )
123   {
124     OB_ListView* oblv = (OB_ListView*)listView();
125     s = s && oblv->isOk( this );
126   }
127
128   QListViewItem::setSelected( s );
129 }
130
131 template<class T>
132 void ListItem<T>::update()
133 {
134   SUIT_DataObject* obj = dataObject();
135   if ( !obj )
136     return;
137
138   setText( 0, obj->name() );
139
140   int aIconW = obj->icon().width();
141   if ( aIconW > 0 )
142   {
143     if ( aIconW > 20 )
144     {
145       QWMatrix aM;
146       double aScale = 20.0 / aIconW;
147       aM.scale( aScale, aScale );
148       setPixmap( 0, obj->icon().xForm( aM ) );
149     }
150     else
151       setPixmap( 0, obj->icon() );
152   }
153
154   this->setDragEnabled( obj->isDragable() );
155   this->setDropEnabled( true );
156 }
157
158 /*!
159     Class: OB_ListItem
160     Descr: List view item for OB_Browser.
161 */
162
163 OB_ListItem::OB_ListItem( SUIT_DataObject* obj, QListView* parent )
164 : ListItem<QListViewItem>( obj, parent )
165 {
166 }
167
168 OB_ListItem::OB_ListItem( SUIT_DataObject* obj, QListViewItem* parent )
169 : ListItem<QListViewItem>( obj, parent )
170 {
171 }
172
173 OB_ListItem::OB_ListItem( SUIT_DataObject* obj, QListView* parent, QListViewItem* after )
174 : ListItem<QListViewItem>( obj, parent, after )
175 {
176 }
177
178 OB_ListItem::OB_ListItem( SUIT_DataObject* obj, QListViewItem* parent, QListViewItem* after )
179 : ListItem<QListViewItem>( obj, parent, after )
180 {
181 }
182
183 OB_ListItem::~OB_ListItem()
184 {
185 }
186
187 int OB_ListItem::RTTI()
188 {
189   return 1000;
190 }
191
192 int OB_ListItem::rtti() const
193 {
194   return RTTI();
195 }
196
197 /*!
198     Class: OB_CheckListItem
199     Descr: Check list view item for OB_Browser.
200 */
201
202 OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListView* parent, Type type )
203 : ListItem<QCheckListItem>( obj, parent, type )
204 {
205 }
206
207 OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListViewItem* parent, Type type )
208 : ListItem<QCheckListItem>( obj, parent, type )
209 {
210 }
211
212 OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListView* parent, QListViewItem* after, Type type )
213 : ListItem<QCheckListItem>( obj, parent, after, type )
214 {
215 }
216
217 OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListViewItem* parent, QListViewItem* after, Type type )
218 : ListItem<QCheckListItem>( obj, parent, after, type )
219 {
220 }
221
222 OB_CheckListItem::~OB_CheckListItem()
223 {
224 }
225
226 int OB_CheckListItem::RTTI()
227 {
228   return OB_ListItem::RTTI() + 1;
229 }
230
231 int OB_CheckListItem::rtti() const
232 {
233   return RTTI();
234 }
235
236 void OB_CheckListItem::stateChange( bool on )
237 {
238   QCheckListItem::stateChange( on );
239
240   if ( dataObject() )
241     dataObject()->setOn( on );
242 }