1 // Copyright (C) 2007-2008 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
22 // VISU VISUGUI : GUI of VISU component
23 // File : VisuGUI_TransparencyDlg.cxx
24 // Author : Nicolas REJNERI
28 #include "VisuGUI_TransparencyDlg.h"
31 #include "VisuGUI_ViewTools.h"
32 #include "VisuGUI_Tools.h"
33 #include "VISU_Actor.h"
35 #include "SUIT_Desktop.h"
36 #include "SUIT_OverrideCursor.h"
37 #include "SUIT_Session.h"
38 #include "SUIT_MessageBox.h"
39 #include "SUIT_ResourceMgr.h"
41 #include "SALOME_ListIO.hxx"
42 #include "SALOME_ListIteratorOfListIO.hxx"
43 #include "SALOME_InteractiveObject.hxx"
45 #include "LightApp_Study.h"
46 #include "LightApp_SelectionMgr.h"
47 #include "LightApp_Application.h"
49 #include "SVTK_ViewWindow.h"
53 #include <QPushButton>
61 //=================================================================================
62 // class : VisuGUI_TransparencyDlg()
65 //=================================================================================
66 VisuGUI_TransparencyDlg::VisuGUI_TransparencyDlg( VisuGUI* theModule,
68 : QDialog( VISU::GetDesktop( theModule ), Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
70 mySelectionMgr( VISU::GetSelectionMgr( theModule ) ),
71 myViewWindow( VISU::GetActiveViewWindow<SVTK_ViewWindow>(theModule) )
74 setAttribute( Qt::WA_DeleteOnClose );
76 setWindowTitle(tr("TRANSPARENCY_TITLE" ));
77 setSizeGripEnabled(TRUE);
78 QGridLayout* VisuGUI_TransparencyDlgLayout = new QGridLayout(this);
79 VisuGUI_TransparencyDlgLayout->setSpacing(6);
80 VisuGUI_TransparencyDlgLayout->setMargin(11);
82 /*************************************************************************/
83 QGroupBox* GroupC1 = new QGroupBox(this);
84 //GroupC1->setColumnLayout(0, Qt::Vertical);
85 //GroupC1->layout()->setSpacing(0);
86 //GroupC1->layout()->setMargin(0);
87 QGridLayout* GroupC1Layout = new QGridLayout(GroupC1);
88 GroupC1Layout->setAlignment(Qt::AlignTop);
89 GroupC1Layout->setSpacing(6);
90 GroupC1Layout->setMargin(11);
92 TextLabelTransparent = new QLabel(tr("TRANSPARENCY_TRANSPARENT" ), GroupC1);
93 TextLabelTransparent->setAlignment(Qt::AlignLeft);
94 GroupC1Layout->addWidget(TextLabelTransparent, 0, 0);
96 ValueLab = new QLabel(GroupC1);
97 ValueLab->setAlignment(Qt::AlignCenter);
98 ValueLab->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
99 QFont fnt = ValueLab->font(); fnt.setBold(true); ValueLab->setFont(fnt);
100 GroupC1Layout->addWidget(ValueLab, 0, 1);
102 TextLabelOpaque = new QLabel(tr("TRANSPARENCY_OPAQUE" ), GroupC1);
103 TextLabelOpaque->setAlignment(Qt::AlignRight);
104 GroupC1Layout->addWidget(TextLabelOpaque, 0, 2);
106 Slider1 = new QSlider( Qt::Horizontal, GroupC1 );
107 Slider1->setMinimum( 0 );
108 Slider1->setMaximum( 100 );
109 Slider1->setPageStep( 10 );
110 Slider1->setSingleStep( 1 );
111 Slider1->setFocusPolicy(Qt::NoFocus);
112 Slider1->setMinimumSize(300, 0);
113 Slider1->setTickPosition(QSlider::TicksAbove);
114 Slider1->setTickInterval(10);
115 Slider1->setTracking(true);
116 GroupC1Layout->addWidget(Slider1, 1, 0, 1, 3);
118 /*************************************************************************/
119 QGroupBox* GroupButtons = new QGroupBox(this);
120 //GroupButtons->setColumnLayout(0, Qt::Vertical);
121 //GroupButtons->layout()->setSpacing(0);
122 //GroupButtons->layout()->setMargin(0);
123 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons);
124 GroupButtonsLayout->setAlignment(Qt::AlignTop);
125 GroupButtonsLayout->setSpacing(6);
126 GroupButtonsLayout->setMargin(11);
128 buttonOk = new QPushButton(GroupButtons);
129 buttonOk->setText(tr("BUT_CLOSE"));
130 buttonOk->setAutoDefault(TRUE);
131 buttonOk->setDefault(TRUE);
133 buttonHelp = new QPushButton(GroupButtons);
134 buttonHelp->setText(tr("BUT_HELP"));
135 buttonHelp->setAutoDefault(TRUE);
137 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
138 GroupButtonsLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
139 GroupButtonsLayout->addWidget(buttonHelp, 0, 2);
141 VisuGUI_TransparencyDlgLayout->addWidget(GroupC1, 0, 0);
142 VisuGUI_TransparencyDlgLayout->addWidget(GroupButtons, 1, 0);
145 this->onSelectionChanged();
147 // signals and slots connections : after ValueHasChanged()
148 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
149 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
150 connect(Slider1, SIGNAL(valueChanged(int)), this, SLOT(SetTransparency()));
151 connect(Slider1, SIGNAL(sliderMoved(int)), this, SLOT(ValueHasChanged()));
152 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
155 //=================================================================================
156 // function : ~VisuGUI_TransparencyDlg()
158 //=================================================================================
159 VisuGUI_TransparencyDlg::~VisuGUI_TransparencyDlg()
161 // no need to delete child widgets, Qt does it all for us
164 //=======================================================================
165 // function : ClickOnOk()
167 //=======================================================================
168 void VisuGUI_TransparencyDlg::ClickOnOk()
173 //=======================================================================
174 // function : ClickOnHelp()
176 //=======================================================================
177 void VisuGUI_TransparencyDlg::ClickOnHelp()
179 QString aHelpFileName = "viewing_3d_presentations_page.html#width_opacity_anchor";
180 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
182 VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
183 app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
188 platform = "winapplication";
190 platform = "application";
192 SUIT_MessageBox::warning(0, tr("WRN_WARNING"),
193 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
194 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
199 //=================================================================================
200 // function : SetTransparency()
201 // purpose : Called when value of slider change
202 // : or the first time as initilisation
203 //=================================================================================
204 void VisuGUI_TransparencyDlg::SetTransparency()
207 SUIT_OverrideCursor wc;
208 float opacity = this->Slider1->value() / 100.;
211 mySelectionMgr->selectedObjects(aList);
213 SALOME_ListIteratorOfListIO anIter(aList);
214 for (; anIter.More(); anIter.Next()) {
215 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
216 VISU_Actor* anActor = VISU::FindActor(VISU::GetAppStudy(myModule), myViewWindow, anIO->getEntry());
218 anActor->SetOpacity(opacity);
220 VISU_ActorBase* anActor = VISU::FindActorBase(VISU::GetAppStudy(myModule), myViewWindow, anIO->getEntry());
222 anActor->SetOpacity(opacity);
225 myViewWindow->Repaint();
230 //=================================================================================
231 // function : ValueHasChanged()
232 // purpose : Called when user moves a slider
233 //=================================================================================
234 void VisuGUI_TransparencyDlg::ValueHasChanged()
236 ValueLab->setText(QString::number(this->Slider1->value()) + "%");
239 //=================================================================================
240 // function : onSelectionChanged()
241 // purpose : Called when selection is changed
242 //=================================================================================
243 void VisuGUI_TransparencyDlg::onSelectionChanged()
249 mySelectionMgr->selectedObjects(aList);
251 if (aList.Extent() == 1) {
252 Handle(SALOME_InteractiveObject) FirstIOS = aList.First();
253 if (!FirstIOS.IsNull()) {
254 VISU_Actor* anActor = VISU::FindActor(VISU::GetAppStudy(myModule), myViewWindow, FirstIOS->getEntry());
256 opacity = int(anActor->GetOpacity() * 100. + 0.5);
258 } else if (aList.Extent() > 1) {
259 SALOME_ListIteratorOfListIO It (aList);
261 for (; It.More(); It.Next()) {
262 Handle(SALOME_InteractiveObject) IO = It.Value();
264 VISU_Actor* anActor = VISU::FindActor(VISU::GetAppStudy(myModule), myViewWindow, IO->getEntry());
266 int op = int(anActor->GetOpacity() * 100. + 0.5);
269 else if (setOp != op) {
280 Slider1->setValue(opacity);
285 //=================================================================================
286 // function : keyPressEvent()
288 //=================================================================================
289 void VisuGUI_TransparencyDlg::keyPressEvent( QKeyEvent* e )
291 QDialog::keyPressEvent( e );
292 if ( e->isAccepted() )
295 if ( e->key() == Qt::Key_F1 )