Salome HOME
linear stream interpolator : insertPoints() : deny to add more points than needed
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_SIProgressIndicator.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROGUI_SIProgressIndicator.h"
20
21 #include <QProgressBar>
22 #include <QVBoxLayout>
23 #include <QApplication>
24
25 IMPLEMENT_STANDARD_RTTIEXT(HYDROGUI_SIProgressIndicator, Message_ProgressIndicator)
26
27 HYDROGUI_SIProgressIndicator::HYDROGUI_SIProgressIndicator( QWidget* theParent )
28 : QtxDialog( theParent, true, false, QtxDialog::Cancel ), myUserBreak(Standard_False)
29 {
30   setWindowTitle( tr( "STRICKLER_INTERPOLATION_TLT" ) );
31
32   QVBoxLayout* aLayout = new QVBoxLayout( mainFrame() );
33   aLayout->setMargin( 5 );
34   aLayout->setSpacing( 5 );
35
36   myBar = new QProgressBar( mainFrame() );
37
38   aLayout->addWidget( myBar );
39
40   setButtonText( Cancel, tr("CANCEL") );
41   setButtonPosition( Center, Cancel );
42   setMinimumWidth( 350 );
43 }
44
45 HYDROGUI_SIProgressIndicator::~HYDROGUI_SIProgressIndicator()
46 {
47 }
48
49 Standard_Boolean HYDROGUI_SIProgressIndicator::Show(const Standard_Boolean theForce)
50 {
51   Standard_Real aPosition = GetPosition();
52   Standard_Boolean isUserBreak = UserBreak();
53
54   bool isFinished = aPosition >= 1 || ( isUserBreak && GetNbScopes() < 2 );
55   if ( isFinished  ) {
56     if ( result() != Accepted ) {
57       QDialog::accept();
58     }
59   } else if (!isVisible()) {
60     open();
61   } 
62
63   if ( theForce ) {
64     if ( !isUserBreak ) {
65       int aNbSteps = myBar->maximum() - myBar->minimum();
66       int aValue = int( aPosition * aNbSteps );
67       myBar->setValue(aValue);
68     }
69
70     QApplication::processEvents();
71   }
72
73   return true;
74 }
75
76 Standard_Boolean HYDROGUI_SIProgressIndicator::UserBreak()
77 {
78   return myUserBreak;
79 }
80
81 void HYDROGUI_SIProgressIndicator::Reset()
82 {
83   Message_ProgressIndicator::Reset();
84   setButtonText( Cancel, tr("CANCEL") );
85   setButtonEnabled( true, Cancel );
86   myUserBreak = Standard_False;
87 }
88
89 void HYDROGUI_SIProgressIndicator::reject()
90 {
91   myUserBreak = Standard_True;
92   setButtonText( Cancel, tr("CANCELLING") );
93   setButtonEnabled( false, Cancel );
94   QApplication::processEvents();
95 }