Salome HOME
refs #1833: progress dialog for Strickler coefficient interpolation.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ProgressIndicator.cxx
diff --git a/src/HYDROGUI/HYDROGUI_ProgressIndicator.cxx b/src/HYDROGUI/HYDROGUI_ProgressIndicator.cxx
new file mode 100644 (file)
index 0000000..f143b73
--- /dev/null
@@ -0,0 +1,95 @@
+// Copyright (C) 2014-2015  EDF-R&D
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "HYDROGUI_ProgressIndicator.h"
+
+#include <QProgressBar>
+#include <QVBoxLayout>
+#include <QApplication>
+
+IMPLEMENT_STANDARD_RTTIEXT(HYDROGUI_ProgressIndicator, Message_ProgressIndicator)
+
+HYDROGUI_ProgressIndicator::HYDROGUI_ProgressIndicator( QWidget* theParent, const QString& theName )
+: QtxDialog( theParent, true, false, QtxDialog::Cancel ), myUserBreak(false)
+{
+  setWindowTitle( theName );
+
+  QVBoxLayout* aLayout = new QVBoxLayout( mainFrame() );
+  aLayout->setMargin( 5 );
+  aLayout->setSpacing( 5 );
+
+  myBar = new QProgressBar( mainFrame() );
+
+  aLayout->addWidget( myBar );
+
+  setButtonText( Cancel, tr("CANCEL") );
+  setButtonPosition( Center, Cancel );
+  setMinimumWidth( 350 );
+}
+
+HYDROGUI_ProgressIndicator::~HYDROGUI_ProgressIndicator()
+{
+}
+
+Standard_Boolean HYDROGUI_ProgressIndicator::Show(const Standard_Boolean theForce)
+{
+  Standard_Real aPosition = GetPosition();
+  Standard_Boolean isUserBreak = UserBreak();
+
+  bool isFinished = aPosition >= 1 || ( isUserBreak && GetNbScopes() < 2 );
+  if ( isFinished  ) {
+    if ( result() != Accepted ) {
+      QDialog::accept();
+    }
+  } else if (!isVisible()) {
+    open();
+  } 
+
+  if ( theForce ) {
+    if ( !isUserBreak ) {
+      int aNbSteps = myBar->maximum() - myBar->minimum();
+      int aValue = int( aPosition * aNbSteps );
+      myBar->setValue(aValue);
+    }
+
+    QApplication::processEvents();
+  }
+
+  return true;
+}
+
+Standard_Boolean HYDROGUI_ProgressIndicator::UserBreak()
+{
+  return myUserBreak;
+}
+
+void HYDROGUI_ProgressIndicator::Reset()
+{
+  Message_ProgressIndicator::Reset();
+  setButtonText( Cancel, tr("CANCEL") );
+  setButtonEnabled( true, Cancel );
+  myUserBreak = false;
+}
+
+void HYDROGUI_ProgressIndicator::reject()
+{
+  myUserBreak = true;
+  setButtonText( Cancel, tr("CANCELLING") );
+  setButtonEnabled( false, Cancel );
+  QApplication::processEvents();
+}
\ No newline at end of file