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>
62 //=================================================================================
63 // class : VisuGUI_TransparencyDlg()
66 //=================================================================================
67 VisuGUI_TransparencyDlg::VisuGUI_TransparencyDlg( VisuGUI* theModule,
69 : QDialog( VISU::GetDesktop( theModule ), Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
71 mySelectionMgr( VISU::GetSelectionMgr( theModule ) ),
72 myViewWindow( VISU::GetActiveViewWindow<SVTK_ViewWindow>(theModule) )
75 setAttribute( Qt::WA_DeleteOnClose );
77 setWindowTitle(tr("TRANSPARENCY_TITLE" ));
78 setSizeGripEnabled(TRUE);
79 QGridLayout* VisuGUI_TransparencyDlgLayout = new QGridLayout(this);
80 VisuGUI_TransparencyDlgLayout->setSpacing(6);
81 VisuGUI_TransparencyDlgLayout->setMargin(11);
83 /*************************************************************************/
84 QGroupBox* GroupC1 = new QGroupBox(this);
85 //GroupC1->setColumnLayout(0, Qt::Vertical);
86 //GroupC1->layout()->setSpacing(0);
87 //GroupC1->layout()->setMargin(0);
88 QGridLayout* GroupC1Layout = new QGridLayout(GroupC1);
89 GroupC1Layout->setAlignment(Qt::AlignTop);
90 GroupC1Layout->setSpacing(6);
91 GroupC1Layout->setMargin(11);
93 TextLabelTransparent = new QLabel(tr("TRANSPARENCY_TRANSPARENT" ), GroupC1);
94 TextLabelTransparent->setAlignment(Qt::AlignLeft);
95 GroupC1Layout->addWidget(TextLabelTransparent, 0, 0);
97 ValueLab = new QLabel(GroupC1);
98 ValueLab->setAlignment(Qt::AlignCenter);
99 ValueLab->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
100 QFont fnt = ValueLab->font(); fnt.setBold(true); ValueLab->setFont(fnt);
101 GroupC1Layout->addWidget(ValueLab, 0, 1);
103 TextLabelOpaque = new QLabel(tr("TRANSPARENCY_OPAQUE" ), GroupC1);
104 TextLabelOpaque->setAlignment(Qt::AlignRight);
105 GroupC1Layout->addWidget(TextLabelOpaque, 0, 2);
107 Slider1 = new QSlider( Qt::Horizontal, GroupC1 );
108 Slider1->setMinimum( 0 );
109 Slider1->setMaximum( 100 );
110 Slider1->setPageStep( 10 );
111 Slider1->setSingleStep( 1 );
112 Slider1->setFocusPolicy(Qt::NoFocus);
113 Slider1->setMinimumSize(300, 0);
114 Slider1->setTickPosition(QSlider::TicksAbove);
115 Slider1->setTickInterval(10);
116 Slider1->setTracking(true);
117 GroupC1Layout->addWidget(Slider1, 1, 0, 1, 3);
119 /*************************************************************************/
120 QGroupBox* GroupButtons = new QGroupBox(this);
121 //GroupButtons->setColumnLayout(0, Qt::Vertical);
122 //GroupButtons->layout()->setSpacing(0);
123 //GroupButtons->layout()->setMargin(0);
124 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons);
125 GroupButtonsLayout->setAlignment(Qt::AlignTop);
126 GroupButtonsLayout->setSpacing(6);
127 GroupButtonsLayout->setMargin(11);
129 buttonOk = new QPushButton(GroupButtons);
130 buttonOk->setText(tr("BUT_CLOSE"));
131 buttonOk->setAutoDefault(TRUE);
132 buttonOk->setDefault(TRUE);
134 buttonHelp = new QPushButton(GroupButtons);
135 buttonHelp->setText(tr("BUT_HELP"));
136 buttonHelp->setAutoDefault(TRUE);
138 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
139 GroupButtonsLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
140 GroupButtonsLayout->addWidget(buttonHelp, 0, 2);
142 VisuGUI_TransparencyDlgLayout->addWidget(GroupC1, 0, 0);
143 VisuGUI_TransparencyDlgLayout->addWidget(GroupButtons, 1, 0);
146 this->onSelectionChanged();
148 // signals and slots connections : after ValueHasChanged()
149 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
150 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
151 connect(Slider1, SIGNAL(valueChanged(int)), this, SLOT(SetTransparency()));
152 connect(Slider1, SIGNAL(sliderMoved(int)), this, SLOT(ValueHasChanged()));
153 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
156 //=================================================================================
157 // function : ~VisuGUI_TransparencyDlg()
159 //=================================================================================
160 VisuGUI_TransparencyDlg::~VisuGUI_TransparencyDlg()
162 // no need to delete child widgets, Qt does it all for us
165 //=======================================================================
166 // function : ClickOnOk()
168 //=======================================================================
169 void VisuGUI_TransparencyDlg::ClickOnOk()
174 //=======================================================================
175 // function : ClickOnHelp()
177 //=======================================================================
178 void VisuGUI_TransparencyDlg::ClickOnHelp()
180 QString aHelpFileName = "viewing_3d_presentations_page.html#width_opacity_anchor";
181 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
183 VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
184 app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
189 platform = "winapplication";
191 platform = "application";
193 SUIT_MessageBox::warning(0, tr("WRN_WARNING"),
194 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
195 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
200 //=================================================================================
201 // function : SetTransparency()
202 // purpose : Called when value of slider change
203 // : or the first time as initilisation
204 //=================================================================================
205 void VisuGUI_TransparencyDlg::SetTransparency()
208 SUIT_OverrideCursor wc;
209 float opacity = this->Slider1->value() / 100.;
212 mySelectionMgr->selectedObjects(aList);
214 SALOME_ListIteratorOfListIO anIter(aList);
215 for (; anIter.More(); anIter.Next()) {
216 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
217 VISU_Actor* anActor = VISU::FindActor(VISU::GetAppStudy(myModule), myViewWindow, anIO->getEntry());
219 anActor->SetOpacity(opacity);
221 VISU_ActorBase* anActor = VISU::FindActorBase(VISU::GetAppStudy(myModule), myViewWindow, anIO->getEntry());
223 anActor->SetOpacity(opacity);
226 myViewWindow->Repaint();
231 //=================================================================================
232 // function : ValueHasChanged()
233 // purpose : Called when user moves a slider
234 //=================================================================================
235 void VisuGUI_TransparencyDlg::ValueHasChanged()
237 ValueLab->setText(QString::number(this->Slider1->value()) + "%");
240 //=================================================================================
241 // function : onSelectionChanged()
242 // purpose : Called when selection is changed
243 //=================================================================================
244 void VisuGUI_TransparencyDlg::onSelectionChanged()
250 mySelectionMgr->selectedObjects(aList);
252 if (aList.Extent() == 1) {
253 Handle(SALOME_InteractiveObject) FirstIOS = aList.First();
254 if (!FirstIOS.IsNull()) {
255 VISU_Actor* anActor = VISU::FindActor(VISU::GetAppStudy(myModule), myViewWindow, FirstIOS->getEntry());
257 opacity = int(anActor->GetOpacity() * 100. + 0.5);
259 } else if (aList.Extent() > 1) {
260 SALOME_ListIteratorOfListIO It (aList);
262 for (; It.More(); It.Next()) {
263 Handle(SALOME_InteractiveObject) IO = It.Value();
265 VISU_Actor* anActor = VISU::FindActor(VISU::GetAppStudy(myModule), myViewWindow, IO->getEntry());
267 int op = int(anActor->GetOpacity() * 100. + 0.5);
270 else if (setOp != op) {
281 Slider1->setValue(opacity);
286 //=================================================================================
287 // function : keyPressEvent()
289 //=================================================================================
290 void VisuGUI_TransparencyDlg::keyPressEvent( QKeyEvent* e )
292 QDialog::keyPressEvent( e );
293 if ( e->isAccepted() )
296 if ( e->key() == Qt::Key_F1 )