Salome HOME
Update SALOME about image for series 6x
[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-2010 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 scriptName, 
25                                     Status        status  ) 
26      : QListViewItem( parent, productName ), myScript( scriptName )
27 {
28   setStatus( status );
29 }
30 // ================================================================
31 /*!
32  *  ProgressViewItem::setStatus
33  *  Sets new status for the item
34  */
35 // ================================================================
36 void ProgressViewItem::setStatus( Status status )
37
38   myStatus = status; 
39   switch ( myStatus ) {
40   case Waiting:
41     setText( 1, ProgressView::tr( "Waiting" ) );    break;
42   case Processing:
43     setText( 1, ProgressView::tr( "Processing" ) ); break;
44   case Completed:
45     setText( 1, ProgressView::tr( "Completed" ) );  break;
46   case Aborted:
47     setText( 1, ProgressView::tr( "Aborted" ) );    break;
48   default:
49     break;
50   }
51   repaint(); 
52 }
53 // ================================================================
54 /*!
55  *  ProgressViewItem::paintCell
56  *  Paints the cell of the list view item
57  */
58 // ================================================================
59 void ProgressViewItem::paintCell( QPainter*          painter, 
60                                   const QColorGroup& cg, 
61                                   int                column, 
62                                   int                width, 
63                                   int                align ) 
64 {
65   QColorGroup acg( cg );
66   if ( column == 1 ) {
67     switch ( myStatus ) {
68     case Waiting:
69       acg.setColor( QColorGroup::Text, ( ( ProgressView* )listView() )->getWaitingColor() ); break;
70     case Processing:
71       acg.setColor( QColorGroup::Text, ( ( ProgressView* )listView() )->getProcessingColor() ); break;
72     case Completed:
73       acg.setColor( QColorGroup::Text, ( ( ProgressView* )listView() )->getCompletedColor() ); break;
74     case Aborted:
75       acg.setColor( QColorGroup::Text, ( ( ProgressView* )listView() )->getWaitingColor() ); break;
76     default:
77       break;
78     }
79   }
80   QListViewItem::paintCell( painter, acg, column, width, align );
81 }
82
83
84 // ================================================================
85 /*!
86  *  ProgressView::ProgressView
87  *  Constructor
88  */
89 // ================================================================
90 ProgressView::ProgressView( QWidget* parent ) : QListView( parent ) 
91 {
92   addColumn( tr( "Product" ) ); addColumn( tr( "Status" ) );
93   header()->hide();
94   setSelectionMode( QListView::NoSelection );
95   setSorting( -1 );
96   setResizeMode( QListView::AllColumns );
97   setFocusPolicy( QWidget::NoFocus );
98   setColors( QColor( "red" ), QColor( "orange" ), QColor( "green" ) );
99 }
100 // ================================================================
101 /*!
102  *  ProgressView::setColors
103  *  Sets status colors
104  */
105 // ================================================================
106 void ProgressView::setColors( QColor wColor, QColor pColor, QColor cColor ) {
107   myWaitingColor    = wColor;
108   myProcessingColor = pColor;
109   myCompletedColor  = cColor;
110   repaint();
111 }
112 // ================================================================
113 /*!
114  *  ProgressView::addProduct
115  *  Adds product item
116  */
117 // ================================================================
118 ProgressViewItem* ProgressView::addProduct( const QString product, const QString script ) {
119   QListViewItem* lastItem = this->lastItem();
120   ProgressViewItem* newItem = new ProgressViewItem( this, product, script );
121   if ( lastItem )
122     newItem->moveItem( lastItem );
123   return newItem;
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 /*!
187   To get visibility status of an item in the progress list view
188 */
189 bool ProgressView::isVisible( const QString product ) {
190   return findItem( product )->isVisible();
191 }
192