Salome HOME
- Fix bugs
[tools/install.git] / src / SALOME_ProgressView.cxx
1 //  File      : SALOME_ProgressView.cxx
2 //  Created   : Thu Dec 18 12:01:00 2002
3 //  Author    : Vadim SANDLER
4 //  Project   : PAL/SALOME
5 //  Module    : InstallWizard
6 //  Copyright : 2004 CEA
7 //  $Header$ 
8
9 #include "SALOME_ProgressView.hxx"
10
11 #include <qheader.h>
12
13 // ================================================================
14 /*!
15  *  ProgressViewItem::ProgressViewItem
16  *  Constructor
17  *  <parent>      - parent progress view
18  *  <productName> - full name of the product
19  *  <smbName>     - alias for he product used by the script
20  *  <status>      - initial status of the product, default is 'Waiting'
21 */
22 // ================================================================
23 ProgressViewItem::ProgressViewItem( ProgressView* parent, 
24                                     QString       productName, 
25                                     const QString installType, 
26                                     const QString scriptName, 
27                                     Status        status  ) 
28      : QListViewItem( parent, productName, installType ), myScript( scriptName )
29 {
30   setStatus( status );
31 }
32 // ================================================================
33 /*!
34  *  ProgressViewItem::setStatus
35  *  Sets new status for the item
36  */
37 // ================================================================
38 void ProgressViewItem::setStatus( Status status )
39
40   myStatus = status; 
41   switch ( myStatus ) {
42   case Waiting:
43     setText( 2, ProgressView::tr( "Waiting" ) );    break;
44   case Processing:
45     setText( 2, ProgressView::tr( "Processing" ) ); break;
46   case Completed:
47     setText( 2, ProgressView::tr( "Completed" ) );  break;
48   case Aborted:
49     setText( 2, ProgressView::tr( "Aborted" ) );  break;
50   default:
51     break;
52   }
53   repaint(); 
54 }
55 // ================================================================
56 /*!
57  *  ProgressViewItem::paintCell
58  *  Paints the cell of the list view item
59  */
60 // ================================================================
61 void ProgressViewItem::paintCell( QPainter*          painter, 
62                                   const QColorGroup& cg, 
63                                   int                column, 
64                                   int                width, 
65                                   int                align ) 
66 {
67   QColorGroup acg( cg );
68   if ( column == 2 ) {
69     switch ( myStatus ) {
70     case Waiting:
71       acg.setColor( QColorGroup::Text, ( ( ProgressView* )listView() )->getWaitingColor() ); break;
72     case Processing:
73       acg.setColor( QColorGroup::Text, ( ( ProgressView* )listView() )->getProcessingColor() ); break;
74     case Completed:
75       acg.setColor( QColorGroup::Text, ( ( ProgressView* )listView() )->getCompletedColor() ); break;
76     case Aborted:
77       acg.setColor( QColorGroup::Text, ( ( ProgressView* )listView() )->getWaitingColor() ); break;
78     default:
79       break;
80     }
81   }
82   QListViewItem::paintCell( painter, acg, column, width, align );
83 }
84
85
86 // ================================================================
87 /*!
88  *  ProgressView::ProgressView
89  *  Constructor
90  */
91 // ================================================================
92 ProgressView::ProgressView( QWidget* parent ) : QListView( parent ) 
93 {
94   addColumn( tr( "Product" ) ); addColumn( tr( "Type" ) ); addColumn( tr( "Status" ) );
95   header()->hide();
96   setSelectionMode( QListView::NoSelection );
97   setSorting( -1 );
98   setResizeMode( QListView::AllColumns );
99   setFocusPolicy( QWidget::NoFocus );
100   setColors( QColor( "red" ), QColor( "orange" ), QColor( "green" ) );
101 }
102 // ================================================================
103 /*!
104  *  ProgressView::setColors
105  *  Sets status colors
106  */
107 // ================================================================
108 void ProgressView::setColors( QColor wColor, QColor pColor, QColor cColor ) {
109   myWaitingColor    = wColor;
110   myProcessingColor = pColor;
111   myCompletedColor  = cColor;
112   repaint();
113 }
114 // ================================================================
115 /*!
116  *  ProgressView::addProduct
117  *  Adds product item
118  */
119 // ================================================================
120 void ProgressView::addProduct( const QString product, const QString type, const QString script ) {
121   QListViewItem* lastItem = this->lastItem();
122   ProgressViewItem* newItem = new ProgressViewItem( this, product, type, script );
123   if ( lastItem )
124     newItem->moveItem( lastItem );
125 }
126 // ================================================================
127 /*!
128  *  ProgressView::findStatus
129  *  Finds the first item with given status
130  */
131 // ================================================================
132 QString ProgressView::findStatus( Status status ) {
133   ProgressViewItem* item = ( ProgressViewItem* )firstChild();
134   while( item ) {
135     if ( item->getStatus() == status )
136       return item->getProduct();
137     item = ( ProgressViewItem* )( item->nextSibling() );
138   }
139   return QString::null;
140 }
141 // ================================================================
142 /*!
143  *  ProgressView::findStatus
144  *  Sets new status for the product item
145  */
146 // ================================================================
147 void ProgressView::setStatus( const QString product, Status status ) {
148   ProgressViewItem* item = findItem( product );
149   if ( item ) {
150     item->setStatus( status );
151     repaint();
152   }
153 }
154 /*!
155   Scrolls the view to make item visible if necessary
156 */
157 void ProgressView::ensureVisible( const QString product )  {
158   ProgressViewItem* item = findItem( product );
159   if ( item ) {
160     ensureItemVisible( item );
161   }
162 }
163 /*!
164   Finds the item by the product name
165 */
166 ProgressViewItem* ProgressView::findItem( const QString product ) {
167   ProgressViewItem* item = ( ProgressViewItem* )firstChild();
168   while( item ) {
169     if ( item->getProduct() == product )
170       return item;
171     item = ( ProgressViewItem* )( item->nextSibling() );
172   }
173   return 0;
174 }
175 /*!
176   Gets the product script
177 */
178 QString ProgressView::getScript( const QString product ) {
179   ProgressViewItem* item = ( ProgressViewItem* )firstChild();
180   while( item ) {
181     if ( item->getProduct() == product )
182       return item->getScript();
183     item = ( ProgressViewItem* )( item->nextSibling() );
184   }
185   return QString::null;
186 }
187