1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
19 #include "OB_ListItem.h"
21 #include "OB_ListView.h"
23 #include <SUIT_DataObject.h>
33 Descr: base template class
37 ListItemF<T>::ListItemF( T& theT, SUIT_DataObject* obj ) :
44 void ListItemF<T>::paintC( QPainter* p, QColorGroup& cg, int c, int w, int align )
46 // QColorGroup colorGrp( cg );
49 if ( myObject->color( SUIT_DataObject::Text ).isValid() )
50 cg.setColor( QColorGroup::Text, myObject->color( SUIT_DataObject::Text ) );
51 if ( myObject->color( SUIT_DataObject::Base ).isValid() )
52 cg.setColor( QColorGroup::Base, myObject->color( SUIT_DataObject::Base ) );
53 if ( myObject->color( SUIT_DataObject::Foreground ).isValid() )
54 cg.setColor( QColorGroup::Foreground, myObject->color( SUIT_DataObject::Foreground ) );
55 if ( myObject->color( SUIT_DataObject::Background ).isValid() )
56 cg.setColor( QColorGroup::Background, myObject->color( SUIT_DataObject::Background ) );
57 if ( myObject->color( SUIT_DataObject::Highlight ).isValid() )
58 cg.setColor( QColorGroup::Highlight, myObject->color( SUIT_DataObject::Highlight ) );
59 if ( myObject->color( SUIT_DataObject::HighlightedText ).isValid() )
60 cg.setColor( QColorGroup::HighlightedText, myObject->color( SUIT_DataObject::HighlightedText ) );
64 p->fillRect( 0, 0, w, myT.height(), cg.brush( QColorGroup::Base ) );
65 //int itemW = myT.width( p->fontMetrics(), myT.listView(), c );
67 //myT.paintCell( p, colorGrp, c, itemW, align );
71 void ListItemF<T>::paintFoc( QPainter* p, QColorGroup& cg, const QRect& r )
74 rect.setWidth( myT.width( p->fontMetrics(), myT.listView(), 0 ) );
75 //myT.paintFocus( p, cg, rect );
79 void ListItemF<T>::setSel( bool s )
81 QListView* lv = myT.listView();
82 if ( s && lv && lv->inherits( "OB_ListView" ) )
84 OB_ListView* objlv = (OB_ListView*)lv;
85 s = s && objlv->isOk( &myT );
88 //myT.setSelected( s );
92 void ListItemF<T>::update()
94 SUIT_DataObject* obj = dataObject();
98 myT.setText( 0, obj->name() );
100 int aIconW = obj->icon().width();
106 double aScale = 20.0 / aIconW;
107 aM.scale( aScale, aScale );
108 myT.setPixmap( 0, obj->icon().xForm( aM ) );
111 myT.setPixmap( 0, obj->icon() );
114 myT.setDragEnabled( obj->isDragable() );
115 myT.setDropEnabled( true );
120 Descr: List view item for OB_Browser.
123 OB_ListItem::OB_ListItem( SUIT_DataObject* obj, QListView* parent )
124 : ListItemF<QListViewItem>( *this, obj ),
125 QListViewItem(parent)
130 OB_ListItem::OB_ListItem( SUIT_DataObject* obj, QListViewItem* parent )
131 : ListItemF<QListViewItem>( *this, obj),
132 QListViewItem(parent)
137 OB_ListItem::OB_ListItem( SUIT_DataObject* obj, QListView* parent, QListViewItem* after )
138 : ListItemF<QListViewItem>( *this, obj),
139 QListViewItem(parent, after )
144 OB_ListItem::OB_ListItem( SUIT_DataObject* obj, QListViewItem* parent, QListViewItem* after )
145 : ListItemF<QListViewItem>( *this,obj),
146 QListViewItem(parent, after )
151 OB_ListItem::~OB_ListItem()
155 void OB_ListItem::setSelected( bool s )
158 QListViewItem::setSelected( s );
161 void OB_ListItem::paintFocus( QPainter* p, const QColorGroup& cg, const QRect& r )
163 QColorGroup col_group( cg );
164 paintFoc( p, col_group, r );
167 if ( listView() && !listView()->allColumnsShowFocus() )
168 R.setWidth( width( p->fontMetrics(), listView(), 0 ) );
170 QListViewItem::paintFocus( p, col_group, R );
173 void OB_ListItem::paintCell( QPainter* p, const QColorGroup& cg, int c, int w, int align )
175 QColorGroup col_group( cg );
176 paintC( p, col_group, c ,w, align );
179 if ( listView() && !listView()->allColumnsShowFocus() )
180 W = width( p->fontMetrics(), listView(), c );
182 QListViewItem::paintCell( p, col_group, c, W, align );
185 int OB_ListItem::RTTI()
190 int OB_ListItem::rtti() const
196 Class: OB_CheckListItem
197 Descr: Check list view item for OB_Browser.
200 OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListView* parent, Type type )
201 : ListItemF<QCheckListItem>( *this, obj),
202 QCheckListItem( parent, "", type )
207 OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListViewItem* parent, Type type )
208 : ListItemF<QCheckListItem>( *this, obj),
209 QCheckListItem( parent, "", type )
214 OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListView* parent, QListViewItem* after, Type type )
215 : ListItemF<QCheckListItem>( *this, obj),
216 #if defined(QT_VERSION) && QT_VERSION >= 0x030101
217 QCheckListItem( parent, after, "", type )
219 QCheckListItem( parent, "", type )
225 OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListViewItem* parent, QListViewItem* after, Type type )
226 : ListItemF<QCheckListItem>( *this, obj),
227 #if defined(QT_VERSION) && QT_VERSION >= 0x030101
228 QCheckListItem( parent, after, "", type )
230 QCheckListItem( parent, "", type )
236 OB_CheckListItem::~OB_CheckListItem()
240 void OB_CheckListItem::setSelected( bool s )
243 QCheckListItem::setSelected( s );
246 void OB_CheckListItem::paintFocus( QPainter* p, const QColorGroup& cg, const QRect& r )
248 QColorGroup col_group( cg );
249 paintFoc( p, col_group, r );
252 if ( listView() && !listView()->allColumnsShowFocus() )
253 R.setWidth( width( p->fontMetrics(), listView(), 0 ) );
255 QCheckListItem::paintFocus( p, col_group, R );
258 void OB_CheckListItem::paintCell( QPainter* p, const QColorGroup& cg, int c, int w, int align )
260 QColorGroup col_group( cg );
261 paintC( p, col_group, c ,w, align );
264 if ( listView() && !listView()->allColumnsShowFocus() )
265 W = width( p->fontMetrics(), listView(), c );
267 QCheckListItem::paintCell( p, col_group, c, W, align );
270 int OB_CheckListItem::RTTI()
272 return OB_ListItem::RTTI() + 1;
275 int OB_CheckListItem::rtti() const
280 void OB_CheckListItem::stateChange( bool on )
282 QCheckListItem::stateChange( on );
285 dataObject()->setOn( on );