Salome HOME
Merge from BR_WIN_INDUS_514 branch 21/03/2011 (Windows industrialization)
[modules/visu.git] / src / VISUGUI / VisuGUI_TransparencyDlg.cxx
index ca3d9f275c5e36d9907805d6b1d86f1f1836be6a..6ea3a861ede334e754154ca8a51caad3ab1828a5 100644 (file)
@@ -1,6 +1,6 @@
-//  VISU VISUGUI : GUI of VISU component
+//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
 //  This library is free software; you can redistribute it and/or
 //
 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
-//
-//
+
+//  VISU VISUGUI : GUI of VISU component
 //  File   : VisuGUI_TransparencyDlg.cxx
 //  Author : Nicolas REJNERI
 //  Module : VISU
 //  $Header$
-
+//
 #include "VisuGUI_TransparencyDlg.h"
 
 #include "VisuGUI.h"
 #include "SVTK_ViewWindow.h"
 
 // QT Includes
-#include <qlabel.h>
-#include <qpushbutton.h>
-#include <qslider.h>
-#include <qlayout.h>
-#include <qgroupbox.h>
+#include <QLabel>
+#include <QPushButton>
+#include <QSlider>
+#include <QLayout>
+#include <QGroupBox>
+#include <QKeyEvent>
 
-using namespace std;
+const int DEFAULT_OPACITY = 100;
+const int UNDEF_OPACITY = -1;
 
 //=================================================================================
 // class    : VisuGUI_TransparencyDlg()
 // purpose  :
 //
 //=================================================================================
-VisuGUI_TransparencyDlg::VisuGUI_TransparencyDlg (VisuGUI* theModule,
-                                                  const char* name,
-                                                  bool modal,
-                                                  WFlags fl)
-  : QDialog(VISU::GetDesktop(theModule), name, modal, WStyle_Customize | WStyle_NormalBorder |
-            WStyle_Title | WStyle_SysMenu | WDestructiveClose),
+VisuGUI_TransparencyDlg::VisuGUI_TransparencyDlg( VisuGUI* theModule,
+                                                  bool modal )
+  : QDialog( VISU::GetDesktop( theModule ), Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
     myModule(theModule),
-    mySelectionMgr(VISU::GetSelectionMgr(theModule)),
-    myViewWindow(VISU::GetActiveViewWindow<SVTK_ViewWindow>(theModule))
+    mySelectionMgr( VISU::GetSelectionMgr( theModule ) ),
+    myViewWindow( VISU::GetActiveViewWindow<SVTK_ViewWindow>(theModule) )
 {
-  if (!name)
-    setName("VisuGUI_TransparencyDlg");
-  setCaption(tr("TRANSPARENCY_TITLE" ));
+  setModal( modal );
+  setAttribute( Qt::WA_DeleteOnClose );
+    
+  setWindowTitle(tr("TRANSPARENCY_TITLE" ));
   setSizeGripEnabled(TRUE);
   QGridLayout* VisuGUI_TransparencyDlgLayout = new QGridLayout(this);
   VisuGUI_TransparencyDlgLayout->setSpacing(6);
   VisuGUI_TransparencyDlgLayout->setMargin(11);
 
   /*************************************************************************/
-  QGroupBox* GroupC1 = new QGroupBox(this, "GroupC1");
-  GroupC1->setColumnLayout(0, Qt::Vertical);
-  GroupC1->layout()->setSpacing(0);
-  GroupC1->layout()->setMargin(0);
-  QGridLayout* GroupC1Layout = new QGridLayout(GroupC1->layout());
+  QGroupBox* GroupC1 = new QGroupBox(this);
+  //GroupC1->setColumnLayout(0, Qt::Vertical);
+  //GroupC1->layout()->setSpacing(0);
+  //GroupC1->layout()->setMargin(0);
+  QGridLayout* GroupC1Layout = new QGridLayout(GroupC1);
   GroupC1Layout->setAlignment(Qt::AlignTop);
   GroupC1Layout->setSpacing(6);
   GroupC1Layout->setMargin(11);
 
-  TextLabelTransparent = new QLabel(GroupC1, "TextLabelTransparent");
-  TextLabelTransparent->setText(tr("TRANSPARENCY_TRANSPARENT" ));
-  TextLabelTransparent->setAlignment(AlignLeft);
-  GroupC1Layout->addWidget(TextLabelTransparent, 0, 0);
+  TextLabelTransparent = new QLabel(tr("TRANSPARENCY_TRANSPARENT" ), GroupC1);
+  TextLabelTransparent->setAlignment(Qt::AlignRight);
+  GroupC1Layout->addWidget(TextLabelTransparent, 0, 2);
 
-  ValueLab = new QLabel(GroupC1, "ValueLab");
-  ValueLab->setAlignment(AlignCenter);
+  ValueLab = new QLabel(GroupC1);
+  ValueLab->setAlignment(Qt::AlignCenter);
   ValueLab->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
   QFont fnt = ValueLab->font(); fnt.setBold(true); ValueLab->setFont(fnt);
   GroupC1Layout->addWidget(ValueLab, 0, 1);
 
-  TextLabelOpaque = new QLabel(GroupC1, "TextLabelOpaque");
-  TextLabelOpaque->setText(tr("TRANSPARENCY_OPAQUE" ));
-  TextLabelOpaque->setAlignment(AlignRight);
-  GroupC1Layout->addWidget(TextLabelOpaque, 0, 2);
+  TextLabelOpaque = new QLabel(tr("TRANSPARENCY_OPAQUE" ), GroupC1);
+  TextLabelOpaque->setAlignment(Qt::AlignLeft);
+  GroupC1Layout->addWidget(TextLabelOpaque, 0, 1);
 
-  Slider1 = new QSlider(0, 10, 1, 5, Horizontal, GroupC1, "Slider1");
-  Slider1->setFocusPolicy(QWidget::NoFocus);
+  Slider1 = new QSlider( Qt::Horizontal, GroupC1 );
+  Slider1->setMinimum( 0 );
+  Slider1->setMaximum( 100 );
+  Slider1->setPageStep( 10 );
+  Slider1->setSingleStep( 1 );  
+  Slider1->setFocusPolicy(Qt::NoFocus);
   Slider1->setMinimumSize(300, 0);
-  Slider1->setTickmarks(QSlider::Above);
+  Slider1->setTickPosition(QSlider::TicksAbove);
   Slider1->setTickInterval(10);
   Slider1->setTracking(true);
-  Slider1->setMinValue(0);
-  Slider1->setMaxValue(100);
-  Slider1->setLineStep(1);
-  Slider1->setPageStep(10);
-  GroupC1Layout->addMultiCellWidget(Slider1, 1, 1, 0, 2);
+  GroupC1Layout->addWidget(Slider1, 1, 0, 1, 3);
 
   /*************************************************************************/
-  QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons");
-  GroupButtons->setColumnLayout(0, Qt::Vertical);
-  GroupButtons->layout()->setSpacing(0);
-  GroupButtons->layout()->setMargin(0);
-  QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
+  QGroupBox* GroupButtons = new QGroupBox(this);
+  //GroupButtons->setColumnLayout(0, Qt::Vertical);
+  //GroupButtons->layout()->setSpacing(0);
+  //GroupButtons->layout()->setMargin(0);
+  QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons);
   GroupButtonsLayout->setAlignment(Qt::AlignTop);
   GroupButtonsLayout->setSpacing(6);
   GroupButtonsLayout->setMargin(11);
 
-  buttonOk = new QPushButton(GroupButtons, "buttonOk");
+  buttonOk = new QPushButton(GroupButtons);
   buttonOk->setText(tr("BUT_CLOSE"));
   buttonOk->setAutoDefault(TRUE);
   buttonOk->setDefault(TRUE);
 
-  buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
+  buttonHelp = new QPushButton(GroupButtons);
   buttonHelp->setText(tr("BUT_HELP"));
   buttonHelp->setAutoDefault(TRUE);
 
@@ -180,23 +178,23 @@ void VisuGUI_TransparencyDlg::ClickOnOk()
 //=======================================================================
 void VisuGUI_TransparencyDlg::ClickOnHelp()
 {
-  QString aHelpFileName = "viewing_3d_presentations_intro_page.html#width_opacity_anchor";
+  QString aHelpFileName = "viewing_3d_presentations_page.html#width_opacity_anchor";
   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
   if (app) {
     VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
     app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
   }
   else {
-    QString platform;
+                QString platform;
 #ifdef WIN32
-    platform = "winapplication";
+                platform = "winapplication";
 #else
-    platform = "application";
+                platform = "application";
 #endif
-    SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
-                          QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
-                          arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
-                          QObject::tr("BUT_OK"));
+    SUIT_MessageBox::warning(0, tr("WRN_WARNING"),
+                             tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
+                             arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
+                             tr("BUT_OK"));
   }
 }
 
@@ -209,7 +207,7 @@ void VisuGUI_TransparencyDlg::SetTransparency()
 {
   if( myViewWindow ) {
     SUIT_OverrideCursor wc;
-    float opacity = this->Slider1->value() / 100.;
+    float opacity = (100 - this->Slider1->value() ) / 100.;
 
     SALOME_ListIO aList;
     mySelectionMgr->selectedObjects(aList);
@@ -220,6 +218,11 @@ void VisuGUI_TransparencyDlg::SetTransparency()
       VISU_Actor* anActor = VISU::FindActor(VISU::GetAppStudy(myModule), myViewWindow, anIO->getEntry());
       if (anActor)
         anActor->SetOpacity(opacity);
+      else {
+        VISU_ActorBase* anActor = VISU::FindActorBase(VISU::GetAppStudy(myModule), myViewWindow, anIO->getEntry());
+       if (anActor)
+         anActor->SetOpacity(opacity);
+      }
     }
     myViewWindow->Repaint();
   }
@@ -241,42 +244,37 @@ void VisuGUI_TransparencyDlg::ValueHasChanged()
 //=================================================================================
 void VisuGUI_TransparencyDlg::onSelectionChanged()
 {
-  if( myViewWindow ) {
-    int opacity = 100;
+  if ( myViewWindow ) {
+    int opacity = UNDEF_OPACITY;
 
     SALOME_ListIO aList;
     mySelectionMgr->selectedObjects(aList);
 
-    if (aList.Extent() == 1) {
-      Handle(SALOME_InteractiveObject) FirstIOS = aList.First();
-      if (!FirstIOS.IsNull()) {
-       VISU_Actor* anActor = VISU::FindActor(VISU::GetAppStudy(myModule), myViewWindow, FirstIOS->getEntry());
-       if (anActor)
-         opacity = int(anActor->GetOpacity() * 100. + 0.5);
-      }
-    } else if (aList.Extent() > 1) {
-      SALOME_ListIteratorOfListIO It (aList);
-      int setOp = -1;
-      for (; It.More(); It.Next()) {
-       Handle(SALOME_InteractiveObject) IO = It.Value();
-       if (!IO.IsNull()) {
-         VISU_Actor* anActor = VISU::FindActor(VISU::GetAppStudy(myModule), myViewWindow, IO->getEntry());
-         if (anActor) {
-           int op = int(anActor->GetOpacity() * 100. + 0.5);
-           if (setOp < 0)
-             setOp = op;
-           else if (setOp != op) {
-             setOp = 100;
-             break;
-           }
+    SALOME_ListIteratorOfListIO It (aList);
+    for (; It.More(); It.Next()) {
+      Handle(SALOME_InteractiveObject) IO = It.Value();
+      if (!IO.IsNull()) {
+       int op = UNDEF_OPACITY;
+       VISU_Actor* anActor = VISU::FindActor(VISU::GetAppStudy(myModule), myViewWindow, IO->getEntry());
+       if (anActor) {
+         op = int(anActor->GetOpacity() * 100. + 0.5);
+       }
+       else {
+         VISU_ActorBase* anActor = VISU::FindActorBase(VISU::GetAppStudy(myModule), myViewWindow, IO->getEntry());
+         if (anActor)
+           op = int(anActor->GetOpacity() * 100. + 0.5);
+       }
+       if ( op != UNDEF_OPACITY ) {
+         if ( opacity == UNDEF_OPACITY )
+           opacity = op;
+         else if ( opacity != op ) {
+           opacity = DEFAULT_OPACITY;
+           break;
          }
        }
       }
-      if (setOp >= 0)
-       opacity = setOp;
-    } else {
     }
-    Slider1->setValue(opacity);
+    Slider1->setValue( 100 - ( opacity == UNDEF_OPACITY ? DEFAULT_OPACITY : opacity ) );
   }
   ValueHasChanged();
 }
@@ -291,7 +289,7 @@ void VisuGUI_TransparencyDlg::keyPressEvent( QKeyEvent* e )
   if ( e->isAccepted() )
     return;
 
-  if ( e->key() == Key_F1 )
+  if ( e->key() == Qt::Key_F1 )
     {
       e->accept();
       ClickOnHelp();