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_ListView.h"
21 #include "OB_Filter.h"
22 #include "OB_ListItem.h"
24 #include <SUIT_DataObject.h>
26 #include <qdragobject.h>
28 OB_ListView::OB_ListView( QWidget* parent, const char* name, WFlags f )
29 : QtxListView( parent, name, f ),
34 OB_ListView::OB_ListView( const int state, QWidget* parent, const char* name, WFlags f )
35 : QtxListView( state, parent, name, f ),
40 OB_ListView::~OB_ListView()
45 OB_Filter* OB_ListView::filter() const
50 void OB_ListView::setFilter( OB_Filter* f )
59 bool OB_ListView::isOk( QListViewItem* item ) const
62 SUIT_DataObject* obj = dataObject( item );
63 if ( obj && filter() )
64 ok = filter()->isOk( obj );
68 QDragObject* OB_ListView::dragObject()
72 for ( QListViewItemIterator it( this ); it.current(); ++it )
73 if ( it.current()->isSelected() )
74 myItems.append( it.current() );
76 return new QTextDrag( "", this );
79 void OB_ListView::dragEnterEvent( QDragEnterEvent* e )
84 void OB_ListView::dragMoveEvent( QDragMoveEvent* e )
86 QListViewItem* item = dropItem( e );
88 if ( isDropAccepted( item ) )
90 setCurrentItem( item );
97 void OB_ListView::dropEvent( QDropEvent* e )
99 QListViewItem* item = dropItem( e );
100 if ( isDropAccepted( item ) )
103 emit dropped( myItems, item, e->action() );
108 void OB_ListView::keyPressEvent( QKeyEvent* ke )
110 if ( ( ke->key() == Qt::Key_Plus || ke->key() == Qt::Key_Minus ) && ke->state() & ControlButton )
112 bool isOpen = ke->key() == Qt::Key_Plus;
113 for ( QListViewItemIterator it( this ); it.current(); ++it )
114 if ( it.current()->childCount() )
115 it.current()->setOpen( isOpen );
118 QtxListView::keyPressEvent( ke );
121 QListViewItem* OB_ListView::dropItem( QDropEvent* e ) const
123 QListViewItem* item = 0;
125 item = itemAt( QPoint( e->pos().x() - viewport()->x(), e->pos().y() - viewport()->y() ) );
130 SUIT_DataObject* OB_ListView::dataObject( QListViewItem* item ) const
135 SUIT_DataObject* obj = 0;
137 if ( dynamic_cast<OB_ListItem*>( item ) )
138 obj = dynamic_cast<OB_ListItem*>( item )->dataObject();
139 else if ( dynamic_cast<OB_CheckListItem*>( item ) )
140 obj = dynamic_cast<OB_CheckListItem*>( item )->dataObject();
145 bool OB_ListView::isDropAccepted( QListViewItem* item ) const
149 for ( QPtrListIterator<QListViewItem> it( myItems ); it.current() && res; ++it )
150 res = res && isDropAccepted( it.current(), item );
155 bool OB_ListView::isDropAccepted( QListViewItem* drag, QListViewItem* drop ) const
157 SUIT_DataObject* dragObj = dataObject( drag );
158 SUIT_DataObject* dropObj = dataObject( drop );
160 if ( !dragObj || !dropObj )
163 return dropObj->isDropAccepted( dragObj );
166 void OB_ListView::setColumnWidth( int col, int width )
168 int max = columnMaxWidth( col );
169 if( max>0 && width>max )
171 QListView::setColumnWidth( col, width );
174 int OB_ListView::columnMaxWidth( const int col ) const
177 if( myMaxColWidth.contains( col ) )
178 res = myMaxColWidth[col];
179 else if( myMaxColRatio.contains( col ) )
180 res = int( myMaxColRatio[col]*height() );
184 void OB_ListView::setColumnMaxWidth( const int col, const int w )
186 myMaxColWidth.insert( col, w );
189 double OB_ListView::columnMaxRatio( const int col ) const
192 if( myMaxColRatio.contains( col ) )
193 res = myMaxColRatio[col];
197 void OB_ListView::setColumnMaxRatio( const int col, const double r )
199 myMaxColRatio.insert( col, r );