1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // VISU VISUGUI : GUI of VISU component
24 // File : VisuGUI_TransparencyDlg.cxx
25 // Author : Nicolas REJNERI
29 #include "VisuGUI_TransparencyDlg.h"
32 #include "VisuGUI_ViewTools.h"
33 #include "VisuGUI_Tools.h"
34 #include "VISU_Actor.h"
36 #include "SUIT_Desktop.h"
37 #include "SUIT_OverrideCursor.h"
38 #include "SUIT_Session.h"
39 #include "SUIT_MessageBox.h"
40 #include "SUIT_ResourceMgr.h"
42 #include "SALOME_ListIO.hxx"
43 #include "SALOME_ListIteratorOfListIO.hxx"
44 #include "SALOME_InteractiveObject.hxx"
46 #include "LightApp_Study.h"
47 #include "LightApp_SelectionMgr.h"
48 #include "LightApp_Application.h"
50 #include "SVTK_ViewWindow.h"
54 #include <QPushButton>
60 const int DEFAULT_OPACITY = 100;
61 const int UNDEF_OPACITY = -1;
63 //=================================================================================
64 // class : VisuGUI_TransparencyDlg()
67 //=================================================================================
68 VisuGUI_TransparencyDlg::VisuGUI_TransparencyDlg( VisuGUI* theModule,
70 : QDialog( VISU::GetDesktop( theModule ), Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
72 mySelectionMgr( VISU::GetSelectionMgr( theModule ) ),
73 myViewWindow( VISU::GetActiveViewWindow<SVTK_ViewWindow>(theModule) )
76 setAttribute( Qt::WA_DeleteOnClose );
78 setWindowTitle(tr("TRANSPARENCY_TITLE" ));
79 setSizeGripEnabled(TRUE);
80 QGridLayout* VisuGUI_TransparencyDlgLayout = new QGridLayout(this);
81 VisuGUI_TransparencyDlgLayout->setSpacing(6);
82 VisuGUI_TransparencyDlgLayout->setMargin(11);
84 /*************************************************************************/
85 QGroupBox* GroupC1 = new QGroupBox(this);
86 //GroupC1->setColumnLayout(0, Qt::Vertical);
87 //GroupC1->layout()->setSpacing(0);
88 //GroupC1->layout()->setMargin(0);
89 QGridLayout* GroupC1Layout = new QGridLayout(GroupC1);
90 GroupC1Layout->setAlignment(Qt::AlignTop);
91 GroupC1Layout->setSpacing(6);
92 GroupC1Layout->setMargin(11);
94 TextLabelTransparent = new QLabel(tr("TRANSPARENCY_TRANSPARENT" ), GroupC1);
95 TextLabelTransparent->setAlignment(Qt::AlignLeft);
96 GroupC1Layout->addWidget(TextLabelTransparent, 0, 0);
98 ValueLab = new QLabel(GroupC1);
99 ValueLab->setAlignment(Qt::AlignCenter);
100 ValueLab->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
101 QFont fnt = ValueLab->font(); fnt.setBold(true); ValueLab->setFont(fnt);
102 GroupC1Layout->addWidget(ValueLab, 0, 1);
104 TextLabelOpaque = new QLabel(tr("TRANSPARENCY_OPAQUE" ), GroupC1);
105 TextLabelOpaque->setAlignment(Qt::AlignRight);
106 GroupC1Layout->addWidget(TextLabelOpaque, 0, 2);
108 Slider1 = new QSlider( Qt::Horizontal, GroupC1 );
109 Slider1->setMinimum( 0 );
110 Slider1->setMaximum( 100 );
111 Slider1->setPageStep( 10 );
112 Slider1->setSingleStep( 1 );
113 Slider1->setFocusPolicy(Qt::NoFocus);
114 Slider1->setMinimumSize(300, 0);
115 Slider1->setTickPosition(QSlider::TicksAbove);
116 Slider1->setTickInterval(10);
117 Slider1->setTracking(true);
118 GroupC1Layout->addWidget(Slider1, 1, 0, 1, 3);
120 /*************************************************************************/
121 QGroupBox* GroupButtons = new QGroupBox(this);
122 //GroupButtons->setColumnLayout(0, Qt::Vertical);
123 //GroupButtons->layout()->setSpacing(0);
124 //GroupButtons->layout()->setMargin(0);
125 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons);
126 GroupButtonsLayout->setAlignment(Qt::AlignTop);
127 GroupButtonsLayout->setSpacing(6);
128 GroupButtonsLayout->setMargin(11);
130 buttonOk = new QPushButton(GroupButtons);
131 buttonOk->setText(tr("BUT_CLOSE"));
132 buttonOk->setAutoDefault(TRUE);
133 buttonOk->setDefault(TRUE);
135 buttonHelp = new QPushButton(GroupButtons);
136 buttonHelp->setText(tr("BUT_HELP"));
137 buttonHelp->setAutoDefault(TRUE);
139 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
140 GroupButtonsLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
141 GroupButtonsLayout->addWidget(buttonHelp, 0, 2);
143 VisuGUI_TransparencyDlgLayout->addWidget(GroupC1, 0, 0);
144 VisuGUI_TransparencyDlgLayout->addWidget(GroupButtons, 1, 0);
147 this->onSelectionChanged();
149 // signals and slots connections : after ValueHasChanged()
150 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
151 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
152 connect(Slider1, SIGNAL(valueChanged(int)), this, SLOT(SetTransparency()));
153 connect(Slider1, SIGNAL(sliderMoved(int)), this, SLOT(ValueHasChanged()));
154 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
157 //=================================================================================
158 // function : ~VisuGUI_TransparencyDlg()
160 //=================================================================================
161 VisuGUI_TransparencyDlg::~VisuGUI_TransparencyDlg()
163 // no need to delete child widgets, Qt does it all for us
166 //=======================================================================
167 // function : ClickOnOk()
169 //=======================================================================
170 void VisuGUI_TransparencyDlg::ClickOnOk()
175 //=======================================================================
176 // function : ClickOnHelp()
178 //=======================================================================
179 void VisuGUI_TransparencyDlg::ClickOnHelp()
181 QString aHelpFileName = "viewing_3d_presentations_page.html#width_opacity_anchor";
182 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
184 VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
185 app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
190 platform = "winapplication";
192 platform = "application";
194 SUIT_MessageBox::warning(0, tr("WRN_WARNING"),
195 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
196 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
201 //=================================================================================
202 // function : SetTransparency()
203 // purpose : Called when value of slider change
204 // : or the first time as initilisation
205 //=================================================================================
206 void VisuGUI_TransparencyDlg::SetTransparency()
209 SUIT_OverrideCursor wc;
210 float opacity = this->Slider1->value() / 100.;
213 mySelectionMgr->selectedObjects(aList);
215 SALOME_ListIteratorOfListIO anIter(aList);
216 for (; anIter.More(); anIter.Next()) {
217 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
218 VISU_Actor* anActor = VISU::FindActor(VISU::GetAppStudy(myModule), myViewWindow, anIO->getEntry());
220 anActor->SetOpacity(opacity);
222 VISU_ActorBase* anActor = VISU::FindActorBase(VISU::GetAppStudy(myModule), myViewWindow, anIO->getEntry());
224 anActor->SetOpacity(opacity);
227 myViewWindow->Repaint();
232 //=================================================================================
233 // function : ValueHasChanged()
234 // purpose : Called when user moves a slider
235 //=================================================================================
236 void VisuGUI_TransparencyDlg::ValueHasChanged()
238 ValueLab->setText(QString::number(this->Slider1->value()) + "%");
241 //=================================================================================
242 // function : onSelectionChanged()
243 // purpose : Called when selection is changed
244 //=================================================================================
245 void VisuGUI_TransparencyDlg::onSelectionChanged()
247 if ( myViewWindow ) {
248 int opacity = UNDEF_OPACITY;
251 mySelectionMgr->selectedObjects(aList);
253 SALOME_ListIteratorOfListIO It (aList);
254 for (; It.More(); It.Next()) {
255 Handle(SALOME_InteractiveObject) IO = It.Value();
257 int op = UNDEF_OPACITY;
258 VISU_Actor* anActor = VISU::FindActor(VISU::GetAppStudy(myModule), myViewWindow, IO->getEntry());
260 op = int(anActor->GetOpacity() * 100. + 0.5);
263 VISU_ActorBase* anActor = VISU::FindActorBase(VISU::GetAppStudy(myModule), myViewWindow, IO->getEntry());
265 op = int(anActor->GetOpacity() * 100. + 0.5);
267 if ( op != UNDEF_OPACITY ) {
268 if ( opacity == UNDEF_OPACITY )
270 else if ( opacity != op ) {
271 opacity = DEFAULT_OPACITY;
277 Slider1->setValue( opacity == UNDEF_OPACITY ? DEFAULT_OPACITY : opacity );
282 //=================================================================================
283 // function : keyPressEvent()
285 //=================================================================================
286 void VisuGUI_TransparencyDlg::keyPressEvent( QKeyEvent* e )
288 QDialog::keyPressEvent( e );
289 if ( e->isAccepted() )
292 if ( e->key() == Qt::Key_F1 )