Salome HOME
Initialisation de la base KERNEL avec la version operationnelle de KERNEL_SRC issue...
[modules/kernel.git] / src / SALOMEGUI / QAD_ObjectBrowserItem.cxx
1 using namespace std;
2 //  File      : QAD_ObjectBrowserItem.cxx
3 //  Created   : Thu Jun 14 17:07:42 2001
4 //  Author    : Nicolas REJNERI
5 //  Project   : SALOME
6 //  Module    : SALOMEGUI
7 //  Copyright : Open CASCADE
8 //  $Header$
9
10 #include "QAD_ObjectBrowserItem.h"
11
12 #include <qcolor.h>
13 #include <qlistview.h>
14 #include <qpixmap.h>
15 #include <qstringlist.h>
16 #include <qpainter.h>
17
18 /*!
19   Constructors
20 */
21 QAD_ObjectBrowserItem::QAD_ObjectBrowserItem( QListView *theParent )
22   : QListViewItem(theParent)
23 {
24   myType = BlackItem;
25   myCurrent = false;
26 }
27 QAD_ObjectBrowserItem::QAD_ObjectBrowserItem( QListView* theParent, QAD_ObjectBrowserItem* after )
28   : QListViewItem(theParent, after)
29 {
30   myType = BlackItem;
31   myCurrent = false;
32 }
33 QAD_ObjectBrowserItem::QAD_ObjectBrowserItem( QAD_ObjectBrowserItem *theParent )
34   : QListViewItem(theParent)           
35 {
36   myType = BlackItem;
37   myCurrent = false;
38 }
39 QAD_ObjectBrowserItem::QAD_ObjectBrowserItem( QAD_ObjectBrowserItem *theParent, QAD_ObjectBrowserItem* after )
40   : QListViewItem(theParent, after)
41 {
42   myType = BlackItem;
43   myCurrent = false;
44 }
45
46 /*!
47   Destructor
48 */
49 QAD_ObjectBrowserItem::~QAD_ObjectBrowserItem()
50 {
51 }
52
53 /*!
54   Sets type
55 */
56 void QAD_ObjectBrowserItem::setType( int type )
57 {
58   myType = type;
59   repaint();
60 }
61
62 /*!
63   Sets text color
64 */
65 void QAD_ObjectBrowserItem::setTextColor( const QColor& color )
66 {
67   myTextColor = color;
68   repaint();
69 }
70
71 /*!
72   Sets text highlight color
73 */
74 void QAD_ObjectBrowserItem::setTextHighlightColor(const QColor& color)
75 {  
76   myTextHighlightColor = color;
77 }
78
79 /*!
80   Gets item name
81 */
82 QString QAD_ObjectBrowserItem::getName() const
83 {
84   return QListViewItem::text( 0 );
85 }
86
87 /*!
88   Sets name
89 */
90 void  QAD_ObjectBrowserItem::setName( const QString& name )
91 {
92   setText( 0, name );
93 }
94
95 /*!
96   Gets value
97 */
98 QString QAD_ObjectBrowserItem::getValue() const
99 {
100   return QListViewItem::text( 1 );
101 }
102
103 /*!
104   Sets value
105 */
106 void QAD_ObjectBrowserItem::setValue( const QString& value )
107 {
108   setText( 1, value );
109 }
110
111 /*!
112   Gets entry
113 */
114 QString QAD_ObjectBrowserItem::getEntry() const
115 {
116   return QListViewItem::text( 2 );
117 }
118
119 /*!
120   Sets entry
121 */
122 void QAD_ObjectBrowserItem::setEntry( const QString& entry )
123 {
124   setText( 2, entry );
125 }
126
127 /*!
128   Gets IOR
129 */
130 QString QAD_ObjectBrowserItem::getIOR() const
131 {
132   return QListViewItem::text( 3 );
133 }
134
135 /*!
136   Sets IOR
137 */
138   void QAD_ObjectBrowserItem::setIOR( const QString& IOR )
139 {
140   setText( 3, IOR );
141 }
142
143 /*!
144   Gets reference
145 */
146 QString QAD_ObjectBrowserItem::getReference() const
147 {
148   return QListViewItem::text( 4 );
149 }
150
151 /*!
152   Sets reference
153 */
154 void QAD_ObjectBrowserItem::setReference( const QString& ref )
155 {
156   setText( 4, ref );
157 }
158 /*!
159   Returns true if this item is current (for UseCase browser - it is bold)
160 */
161 bool QAD_ObjectBrowserItem::isCurrent() const
162 {
163   return myCurrent;
164 }
165 /*!
166   Sets this item to be current (for UseCase browser - it is bold)
167 */
168 void QAD_ObjectBrowserItem::setCurrent( bool on )
169 {
170   myCurrent = on;
171   repaint();
172 }
173
174 /*!
175   Paints cell [ redefined ]
176 */
177 void QAD_ObjectBrowserItem::paintCell( QPainter*          thePainter,
178                                        const QColorGroup& theColorGroup,
179                                        int                theColumn,
180                                        int                theWidth,
181                                        int                theAlignment )
182
183   QColorGroup aColorGroup(theColorGroup);
184   QColor      aColor          = aColorGroup.text();
185   QColor      aColorHighlight = aColorGroup.highlight();
186   
187   switch (myType)
188     {
189     case 1 :
190       {
191         aColorGroup.setColor(QColorGroup::Text,       Qt::blue);
192         aColorGroup.setColor(QColorGroup::Highlight,  Qt::blue);
193         break;
194       }
195     case 2 :
196       {
197         aColorGroup.setColor(QColorGroup::Text,       Qt::red);
198         aColorGroup.setColor(QColorGroup::Highlight,  Qt::red);
199         break;
200       }
201     default :
202       {
203         aColorGroup.setColor(QColorGroup::Text,       Qt::black);
204         aColorGroup.setColor(QColorGroup::Highlight,  Qt::black);
205         break;
206       }
207     }
208       
209   if (myTextColor.isValid())
210     aColorGroup.setColor(QColorGroup::Text,       myTextColor);
211   if (myTextHighlightColor.isValid())
212     aColorGroup.setColor(QColorGroup::Highlight,  myTextHighlightColor);
213   if (myCurrent) { // UseCase's current entry 
214     QFont font = thePainter->font();
215     font.setBold(true); 
216     thePainter->setFont(font);
217   }
218   
219   QListViewItem::paintCell(thePainter,
220                            aColorGroup,
221                            theColumn,
222                            theWidth,
223                            theAlignment);
224   aColorGroup.setColor(QColorGroup::Text,       aColor);
225   aColorGroup.setColor(QColorGroup::Highlight,  aColorHighlight);
226 }
227
228 /*!
229   Returns item's column text
230   Overrided to protect access outside
231 */
232 QString QAD_ObjectBrowserItem::text( int column ) const
233 {
234   return QListViewItem::text( column );
235 }
236
237 /*!
238   Compares two item to sort list view data by column
239 */
240 int QAD_ObjectBrowserItem::compare( QListViewItem* i, int col, bool ascending ) const
241 {
242   // Additional check is necessary for Entry or Reference entry (2 and 4) columns
243   if ( ( col == 2 || col == 4 ) && !key( col, ascending ).isEmpty() && !i->key( col, ascending ).isEmpty() ) { 
244     QStringList mylist = QStringList::split( ":", key( col, ascending ),    false );
245     QStringList ilist  = QStringList::split( ":", i->key( col, ascending ), false );
246     if ( mylist.count() != ilist.count() || mylist.count() == 0 )
247       return ( mylist.count() < ilist.count() ) ? -1 : 1;
248     for ( int i = 0; i < mylist.count(); i++ ) {
249       if ( mylist[i].toInt() < ilist[i].toInt() )
250         return -1;
251       else if ( mylist[i].toInt() > ilist[i].toInt() )
252         return 1;
253     }
254     return 0;
255   }
256   return QListViewItem::compare( i, col, ascending );
257 }