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>
35 ListItemF<T>::ListItemF( T* theT, SUIT_DataObject* obj ) :
45 void ListItemF<T>::paintC( QPainter* p, QColorGroup& cg, int c, int w, int align )
47 // QColorGroup colorGrp( cg );
50 if ( myObject->color( SUIT_DataObject::Text ).isValid() )
51 cg.setColor( QColorGroup::Text, myObject->color( SUIT_DataObject::Text ) );
52 if ( myObject->color( SUIT_DataObject::Base ).isValid() )
53 cg.setColor( QColorGroup::Base, myObject->color( SUIT_DataObject::Base ) );
54 if ( myObject->color( SUIT_DataObject::Foreground ).isValid() )
55 cg.setColor( QColorGroup::Foreground, myObject->color( SUIT_DataObject::Foreground ) );
56 if ( myObject->color( SUIT_DataObject::Background ).isValid() )
57 cg.setColor( QColorGroup::Background, myObject->color( SUIT_DataObject::Background ) );
58 if ( myObject->color( SUIT_DataObject::Highlight ).isValid() )
59 cg.setColor( QColorGroup::Highlight, myObject->color( SUIT_DataObject::Highlight ) );
60 if ( myObject->color( SUIT_DataObject::HighlightedText ).isValid() )
61 cg.setColor( QColorGroup::HighlightedText, myObject->color( SUIT_DataObject::HighlightedText ) );
65 p->fillRect( 0, 0, w, myT->height(), cg.brush( QColorGroup::Base ) );
66 //int itemW = myT.width( p->fontMetrics(), myT.listView(), c );
68 //myT.paintCell( p, colorGrp, c, itemW, align );
75 void ListItemF<T>::paintFoc( QPainter* p, QColorGroup& cg, const QRect& r )
78 rect.setWidth( myT->width( p->fontMetrics(), myT->listView(), 0 ) );
79 //myT.paintFocus( p, cg, rect );
84 \param s - selected state
87 void ListItemF<T>::setSel( bool s )
89 QListView* lv = myT->listView();
90 if ( s && lv && lv->inherits( "OB_ListView" ) )
92 OB_ListView* objlv = (OB_ListView*)lv;
93 s = s && objlv->isOk( myT );
96 //myT.setSelected( s );
100 Updates name and pixmap of item
103 void ListItemF<T>::update()
105 SUIT_DataObject* obj = dataObject();
109 QString n = obj->name();
110 if( myT->text( 0 )!=n )
111 myT->setText( 0, n );
113 QPixmap p = obj->icon();
114 int aIconW = p.width();
120 double aScale = 20.0 / aIconW;
121 aM.scale( aScale, aScale );
122 myT->setPixmap( 0, p.xForm( aM ) );
125 myT->setPixmap( 0, p );
128 myT->setDragEnabled( obj->isDragable() );
129 myT->setDropEnabled( true );
135 OB_ListItem::OB_ListItem( SUIT_DataObject* obj, QListView* parent )
136 : ListItemF<QListViewItem>( this, obj ),
137 QListViewItem(parent)
145 OB_ListItem::OB_ListItem( SUIT_DataObject* obj, QListViewItem* parent )
146 : ListItemF<QListViewItem>( this, obj ),
147 QListViewItem(parent)
155 OB_ListItem::OB_ListItem( SUIT_DataObject* obj, QListView* parent, QListViewItem* after )
156 : ListItemF<QListViewItem>( this, obj),
157 QListViewItem(parent, after )
165 OB_ListItem::OB_ListItem( SUIT_DataObject* obj, QListViewItem* parent, QListViewItem* after )
166 : ListItemF<QListViewItem>( this,obj),
167 QListViewItem(parent, after )
175 OB_ListItem::~OB_ListItem()
180 Sets selection state of item
183 void OB_ListItem::setSelected( bool s )
186 QListViewItem::setSelected( s );
192 \param cg - color group
193 \param r - focus rectangle
195 void OB_ListItem::paintFocus( QPainter* p, const QColorGroup& cg, const QRect& r )
197 QColorGroup col_group( cg );
198 paintFoc( p, col_group, r );
201 if ( listView() && !listView()->allColumnsShowFocus() )
202 R.setWidth( width( p->fontMetrics(), listView(), 0 ) );
204 QListViewItem::paintFocus( p, col_group, R );
210 \param cg - color group
212 \param w - width of item
213 \param align - alignment
215 void OB_ListItem::paintCell( QPainter* p, const QColorGroup& cg, int c, int w, int align )
217 QColorGroup col_group( cg );
218 paintC( p, col_group, c ,w, align );
221 if ( listView() && !listView()->allColumnsShowFocus() )
222 W = width( p->fontMetrics(), listView(), c );
224 QListViewItem::paintCell( p, col_group, c, min( W, w ), align );
228 \return custom RTTI info
230 int OB_ListItem::RTTI()
236 \return custom RTTI info
238 int OB_ListItem::rtti() const
245 \param column - column index
246 \param text - new text
248 void OB_ListItem::setText( int column, const QString& text )
250 QListViewItem::setText( column, text );
251 QFontMetrics fm = listView()->fontMetrics();
252 int necessary = width( fm, listView(), column ),
253 current = listView()->columnWidth( column );
255 if( listView()->columnWidthMode( column )==QListView::Maximum && necessary>current )
256 listView()->setColumnWidth( column, necessary );
262 OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListView* parent, Type type )
263 : ListItemF<QCheckListItem>( this, obj),
264 QCheckListItem( parent, "", type )
272 OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListViewItem* parent, Type type )
273 : ListItemF<QCheckListItem>( this, obj),
274 QCheckListItem( parent, "", type )
282 OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListView* parent, QListViewItem* after, Type type )
283 : ListItemF<QCheckListItem>( this, obj),
284 #if defined(QT_VERSION) && QT_VERSION >= 0x030101
285 QCheckListItem( parent, after, "", type )
287 QCheckListItem( parent, "", type )
296 OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListViewItem* parent, QListViewItem* after, Type type )
297 : ListItemF<QCheckListItem>( this, obj),
298 #if defined(QT_VERSION) && QT_VERSION >= 0x030101
299 QCheckListItem( parent, after, "", type )
301 QCheckListItem( parent, "", type )
310 OB_CheckListItem::~OB_CheckListItem()
315 Sets selection state of item
318 void OB_CheckListItem::setSelected( bool s )
321 QCheckListItem::setSelected( s );
327 \param cg - color group
328 \param r - focus rectangle
330 void OB_CheckListItem::paintFocus( QPainter* p, const QColorGroup& cg, const QRect& r )
332 QColorGroup col_group( cg );
333 paintFoc( p, col_group, r );
336 if ( listView() && !listView()->allColumnsShowFocus() )
337 R.setWidth( width( p->fontMetrics(), listView(), 0 ) );
339 QCheckListItem::paintFocus( p, col_group, R );
345 \param cg - color group
347 \param w - width of item
348 \param align - alignment
350 void OB_CheckListItem::paintCell( QPainter* p, const QColorGroup& cg, int c, int w, int align )
352 QColorGroup col_group( cg );
353 paintC( p, col_group, c ,w, align );
356 if ( listView() && !listView()->allColumnsShowFocus() )
357 W = width( p->fontMetrics(), listView(), c );
359 QCheckListItem::paintCell( p, col_group, c, min( W, w ), align );
363 \return custom RTTI info
365 int OB_CheckListItem::RTTI()
367 return OB_ListItem::RTTI() + 1;
371 \return custom RTTI info
373 int OB_CheckListItem::rtti() const
379 SLOT: called if checked state is changed, changes corresponding state of SUIT object
381 void OB_CheckListItem::stateChange( bool on )
383 QCheckListItem::stateChange( on );
386 dataObject()->setOn( on );