X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FObjBrowser%2FOB_ListItem.cxx;h=fb821308f2d2d6c8bcf8c9f87f5b3f19d3356762;hb=5819a9fbf57639884c8f841187c763e3fae3bf29;hp=81fa6b7471c426b3907a891274ad34dae39354c7;hpb=81d25a47b06dc8195fd850bfc4d0d9b98f2d48e3;p=modules%2Fgui.git diff --git a/src/ObjBrowser/OB_ListItem.cxx b/src/ObjBrowser/OB_ListItem.cxx index 81fa6b747..fb821308f 100755 --- a/src/ObjBrowser/OB_ListItem.cxx +++ b/src/ObjBrowser/OB_ListItem.cxx @@ -1,3 +1,21 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ +// #include "OB_ListItem.h" #include "OB_ListView.h" @@ -7,135 +25,77 @@ #include #include +#include +using namespace std; + /*! Class: ListItem Descr: base template class */ -template -ListItem::ListItem( SUIT_DataObject* obj, QListView* parent ) -: T( parent ), -myObject( obj ) -{ - update(); -} - -template -ListItem::ListItem( SUIT_DataObject* obj, QListViewItem* parent ) -: T( parent ), -myObject( obj ) -{ - update(); -} template -ListItem::ListItem( SUIT_DataObject* obj, QListView* parent, QListViewItem* after ) -: T( parent, after ), +ListItemF::ListItemF( T& theT, SUIT_DataObject* obj ) : +myT( theT ), myObject( obj ) { - update(); } template -ListItem::ListItem( SUIT_DataObject* obj, QListViewItem* parent, QListViewItem* after ) -: T( parent, after ), -myObject( obj ) -{ - update(); -} - -template -ListItem::ListItem( SUIT_DataObject* obj, QListView* parent, int type ) -: T( parent, "", (typename T::Type)type ), -myObject( obj ) -{ - update(); -} - -template -ListItem::ListItem( SUIT_DataObject* obj, QListViewItem* parent, int type ) -: T( parent, "", (typename T::Type)type ), -myObject( obj ) -{ - update(); -} - -template -ListItem::ListItem( SUIT_DataObject* obj, QListView* parent, QListViewItem* after, int type ) -#if defined(QT_VERSION) && QT_VERSION >= 0x030101 -: T( parent, after, "", (typename T::Type)type ), -#else -: T( parent, "", (typename T::Type)type ), -#endif -myObject( obj ) -{ - update(); -} - -template -ListItem::ListItem( SUIT_DataObject* obj, QListViewItem* parent, QListViewItem* after, int type ) -#if defined(QT_VERSION) && QT_VERSION >= 0x030101 -: T( parent, after, "", (typename T::Type)type ), -#else -: T( parent, "", (typename T::Type)type ), -#endif -myObject( obj ) -{ - update(); -} - -template -void ListItem::paintCell( QPainter* p, const QColorGroup& cg, int c, int w, int align ) +void ListItemF::paintC( QPainter* p, QColorGroup& cg, int c, int w, int align ) { - QColorGroup colorGrp( cg ); +// QColorGroup colorGrp( cg ); if ( myObject ) { if ( myObject->color( SUIT_DataObject::Text ).isValid() ) - colorGrp.setColor( QColorGroup::Text, myObject->color( SUIT_DataObject::Text ) ); + cg.setColor( QColorGroup::Text, myObject->color( SUIT_DataObject::Text ) ); if ( myObject->color( SUIT_DataObject::Base ).isValid() ) - colorGrp.setColor( QColorGroup::Base, myObject->color( SUIT_DataObject::Base ) ); + cg.setColor( QColorGroup::Base, myObject->color( SUIT_DataObject::Base ) ); if ( myObject->color( SUIT_DataObject::Foreground ).isValid() ) - colorGrp.setColor( QColorGroup::Foreground, myObject->color( SUIT_DataObject::Foreground ) ); + cg.setColor( QColorGroup::Foreground, myObject->color( SUIT_DataObject::Foreground ) ); if ( myObject->color( SUIT_DataObject::Background ).isValid() ) - colorGrp.setColor( QColorGroup::Background, myObject->color( SUIT_DataObject::Background ) ); + cg.setColor( QColorGroup::Background, myObject->color( SUIT_DataObject::Background ) ); if ( myObject->color( SUIT_DataObject::Highlight ).isValid() ) - colorGrp.setColor( QColorGroup::Highlight, myObject->color( SUIT_DataObject::Highlight ) ); + cg.setColor( QColorGroup::Highlight, myObject->color( SUIT_DataObject::Highlight ) ); + if ( myObject->color( SUIT_DataObject::HighlightedText ).isValid() ) + cg.setColor( QColorGroup::HighlightedText, myObject->color( SUIT_DataObject::HighlightedText ) ); } - p->fillRect( 0, 0, w, this->height(), colorGrp.brush( QColorGroup::Base ) ); - int itemW = width( p->fontMetrics(), this->listView(), c ); + p->fillRect( 0, 0, w, myT.height(), cg.brush( QColorGroup::Base ) ); + //int itemW = myT.width( p->fontMetrics(), myT.listView(), c ); - T::paintCell( p, colorGrp, c, itemW, align ); + //myT.paintCell( p, colorGrp, c, itemW, align ); } template -void ListItem::paintFocus( QPainter* p, const QColorGroup& cg, const QRect& r ) +void ListItemF::paintFoc( QPainter* p, QColorGroup& cg, const QRect& r ) { QRect rect = r; - rect.setWidth( width( p->fontMetrics(), this->listView(), 0 ) ); - T::paintFocus( p, cg, rect ); + rect.setWidth( myT.width( p->fontMetrics(), myT.listView(), 0 ) ); + //myT.paintFocus( p, cg, rect ); } template -void ListItem::setSelected( bool s ) +void ListItemF::setSel( bool s ) { - if ( s && listView() && listView()->inherits( "OB_ListView" ) ) + QListView* lv = myT.listView(); + if ( s && lv && lv->inherits( "OB_ListView" ) ) { - OB_ListView* oblv = (OB_ListView*)listView(); - s = s && oblv->isOk( this ); + OB_ListView* objlv = (OB_ListView*)lv; + s = s && objlv->isOk( &myT ); } - QListViewItem::setSelected( s ); + //myT.setSelected( s ); } template -void ListItem::update() +void ListItemF::update() { SUIT_DataObject* obj = dataObject(); if ( !obj ) return; - setText( 0, obj->name() ); + myT.setText( 0, obj->name() ); int aIconW = obj->icon().width(); if ( aIconW > 0 ) @@ -145,14 +105,14 @@ void ListItem::update() QWMatrix aM; double aScale = 20.0 / aIconW; aM.scale( aScale, aScale ); - setPixmap( 0, obj->icon().xForm( aM ) ); + myT.setPixmap( 0, obj->icon().xForm( aM ) ); } else - setPixmap( 0, obj->icon() ); + myT.setPixmap( 0, obj->icon() ); } - this->setDragEnabled( obj->isDragable() ); - this->setDropEnabled( true ); + myT.setDragEnabled( obj->isDragable() ); + myT.setDropEnabled( true ); } /*! @@ -161,29 +121,67 @@ void ListItem::update() */ OB_ListItem::OB_ListItem( SUIT_DataObject* obj, QListView* parent ) -: ListItem( obj, parent ) +: ListItemF( *this, obj ), + QListViewItem(parent) { + update(); } OB_ListItem::OB_ListItem( SUIT_DataObject* obj, QListViewItem* parent ) -: ListItem( obj, parent ) +: ListItemF( *this, obj), + QListViewItem(parent) { + update(); } OB_ListItem::OB_ListItem( SUIT_DataObject* obj, QListView* parent, QListViewItem* after ) -: ListItem( obj, parent, after ) +: ListItemF( *this, obj), +QListViewItem(parent, after ) { + update(); } OB_ListItem::OB_ListItem( SUIT_DataObject* obj, QListViewItem* parent, QListViewItem* after ) -: ListItem( obj, parent, after ) +: ListItemF( *this,obj), +QListViewItem(parent, after ) { + update(); } OB_ListItem::~OB_ListItem() { } +void OB_ListItem::setSelected( bool s ) +{ + setSel( s ); + QListViewItem::setSelected( s ); +} + +void OB_ListItem::paintFocus( QPainter* p, const QColorGroup& cg, const QRect& r ) +{ + QColorGroup col_group( cg ); + paintFoc( p, col_group, r ); + + QRect R( r ); + if ( listView() && !listView()->allColumnsShowFocus() ) + R.setWidth( width( p->fontMetrics(), listView(), 0 ) ); + + QListViewItem::paintFocus( p, col_group, R ); +} + +void OB_ListItem::paintCell( QPainter* p, const QColorGroup& cg, int c, int w, int align ) +{ + QColorGroup col_group( cg ); + paintC( p, col_group, c ,w, align ); + + int W = w; + if ( listView() && !listView()->allColumnsShowFocus() ) + W = width( p->fontMetrics(), listView(), c ); + + QListViewItem::paintCell( p, col_group, c, W, align ); +} + int OB_ListItem::RTTI() { return 1000; @@ -200,29 +198,75 @@ int OB_ListItem::rtti() const */ OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListView* parent, Type type ) -: ListItem( obj, parent, type ) +: ListItemF( *this, obj), +QCheckListItem( parent, "", type ) { + update(); } OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListViewItem* parent, Type type ) -: ListItem( obj, parent, type ) +: ListItemF( *this, obj), +QCheckListItem( parent, "", type ) { + update(); } OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListView* parent, QListViewItem* after, Type type ) -: ListItem( obj, parent, after, type ) +: ListItemF( *this, obj), +#if defined(QT_VERSION) && QT_VERSION >= 0x030101 + QCheckListItem( parent, after, "", type ) +#else + QCheckListItem( parent, "", type ) +#endif { + update(); } OB_CheckListItem::OB_CheckListItem( SUIT_DataObject* obj, QListViewItem* parent, QListViewItem* after, Type type ) -: ListItem( obj, parent, after, type ) +: ListItemF( *this, obj), +#if defined(QT_VERSION) && QT_VERSION >= 0x030101 + QCheckListItem( parent, after, "", type ) +#else + QCheckListItem( parent, "", type ) +#endif { + update(); } OB_CheckListItem::~OB_CheckListItem() { } +void OB_CheckListItem::setSelected( bool s ) +{ + setSel( s ); + QCheckListItem::setSelected( s ); +} + +void OB_CheckListItem::paintFocus( QPainter* p, const QColorGroup& cg, const QRect& r ) +{ + QColorGroup col_group( cg ); + paintFoc( p, col_group, r ); + + QRect R( r ); + if ( listView() && !listView()->allColumnsShowFocus() ) + R.setWidth( width( p->fontMetrics(), listView(), 0 ) ); + + QCheckListItem::paintFocus( p, col_group, R ); +} + +void OB_CheckListItem::paintCell( QPainter* p, const QColorGroup& cg, int c, int w, int align ) +{ + QColorGroup col_group( cg ); + paintC( p, col_group, c ,w, align ); + + int W = w; + if ( listView() && !listView()->allColumnsShowFocus() ) + W = width( p->fontMetrics(), listView(), c ); + + QCheckListItem::paintCell( p, col_group, c, W, align ); +} + int OB_CheckListItem::RTTI() { return OB_ListItem::RTTI() + 1;