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