]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROGUI/HYDROGUI_SIProgressIndicator.cxx
Salome HOME
allow SMESH publishing in GUI
[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 //#define _DEVDEBUG_
25 #include "HYDRO_trace.hxx"
26
27 IMPLEMENT_STANDARD_RTTIEXT(HYDROGUI_SIProgressIndicator, Message_ProgressIndicator)
28
29 HYDROGUI_SIProgressIndicator::HYDROGUI_SIProgressIndicator( QWidget* theParent )
30 : QtxDialog( theParent, true, false, QtxDialog::Cancel ), myUserBreak(Standard_False)
31 {
32   setWindowTitle( tr( "STRICKLER_INTERPOLATION_TLT" ) );
33
34   QVBoxLayout* aLayout = new QVBoxLayout( mainFrame() );
35   aLayout->setMargin( 5 );
36   aLayout->setSpacing( 5 );
37
38   myBar = new QProgressBar( mainFrame() );
39
40   aLayout->addWidget( myBar );
41
42   setButtonText( Cancel, tr("CANCEL") );
43   setButtonPosition( Center, Cancel );
44   setMinimumWidth( 350 );
45 }
46
47 HYDROGUI_SIProgressIndicator::~HYDROGUI_SIProgressIndicator()
48 {
49 }
50
51 Standard_Boolean HYDROGUI_SIProgressIndicator::Show(const Standard_Boolean theForce)
52 {
53   //DEBTRACE("...");
54   Standard_Real aPosition = GetPosition();
55   myCount++;
56   if (theForce)
57       DEBTRACE("aPosition=" << aPosition << " myCount:" <<myCount);
58   Standard_Boolean isUserBreak = UserBreak();
59
60   bool isFinished = aPosition >= 1 || ( isUserBreak && GetNbScopes() < 2 );
61   if ( isFinished && theForce ) { // theForce == true : call from main thread, Qt display safe
62     if ( result() != Accepted ) {
63       QDialog::accept();
64     }
65   } else if (!isVisible() && theForce) { // theForce == true : call from main thread, Qt display safe
66     open();
67   } 
68
69   if ( theForce ) {
70     if ( !isUserBreak ) {
71       int aNbSteps = myBar->maximum() - myBar->minimum();
72       int aValue = int( aPosition * aNbSteps );
73       myBar->setValue(aValue);
74     }
75
76     QApplication::processEvents();
77   }
78
79   return true;
80 }
81
82 Standard_Boolean HYDROGUI_SIProgressIndicator::UserBreak()
83 {
84   return myUserBreak;
85 }
86
87 void HYDROGUI_SIProgressIndicator::Reset()
88 {
89   Message_ProgressIndicator::Reset();
90   setButtonText( Cancel, tr("CANCEL") );
91   setButtonEnabled( true, Cancel );
92   myUserBreak = Standard_False;
93   myCount = 0;
94 }
95
96 void HYDROGUI_SIProgressIndicator::reject()
97 {
98   myUserBreak = Standard_True;
99   setButtonText( Cancel, tr("CANCELLING") );
100   setButtonEnabled( false, Cancel );
101   QApplication::processEvents();
102 }