1 // VISU VISUGUI : GUI of VISU component
3 // Copyright (C) 2003 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
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.h>
57 #include <qgroupbox.h>
61 //=================================================================================
62 // class : VisuGUI_TransparencyDlg()
65 //=================================================================================
66 VisuGUI_TransparencyDlg::VisuGUI_TransparencyDlg( VisuGUI* theModule,
70 : QDialog( VISU::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
71 WStyle_Title | WStyle_SysMenu | WDestructiveClose ),
72 mySelectionMgr( VISU::GetSelectionMgr( theModule ) ),
73 myViewWindow( VISU::GetActiveViewWindow<SVTK_ViewWindow>(theModule) )
76 setName("VisuGUI_TransparencyDlg");
77 setCaption(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, "GroupC1");
85 GroupC1->setColumnLayout(0, Qt::Vertical);
86 GroupC1->layout()->setSpacing(0);
87 GroupC1->layout()->setMargin(0);
88 QGridLayout* GroupC1Layout = new QGridLayout(GroupC1->layout());
89 GroupC1Layout->setAlignment(Qt::AlignTop);
90 GroupC1Layout->setSpacing(6);
91 GroupC1Layout->setMargin(11);
93 TextLabelTransparent = new QLabel(GroupC1, "TextLabelTransparent");
94 TextLabelTransparent->setText(tr("TRANSPARENCY_TRANSPARENT" ));
95 TextLabelTransparent->setAlignment(AlignLeft);
96 GroupC1Layout->addWidget(TextLabelTransparent, 0, 0);
98 ValueLab = new QLabel(GroupC1, "ValueLab");
99 ValueLab->setAlignment(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(GroupC1, "TextLabelOpaque");
105 TextLabelOpaque->setText(tr("TRANSPARENCY_OPAQUE" ));
106 TextLabelOpaque->setAlignment(AlignRight);
107 GroupC1Layout->addWidget(TextLabelOpaque, 0, 2);
109 Slider1 = new QSlider(0, 10, 1, 5, Horizontal, GroupC1, "Slider1");
110 Slider1->setFocusPolicy(QWidget::NoFocus);
111 Slider1->setMinimumSize(300, 0);
112 Slider1->setTickmarks(QSlider::Above);
113 Slider1->setTickInterval(10);
114 Slider1->setTracking(true);
115 Slider1->setMinValue(0);
116 Slider1->setMaxValue(100);
117 Slider1->setLineStep(1);
118 Slider1->setPageStep(10);
119 GroupC1Layout->addMultiCellWidget(Slider1, 1, 1, 0, 2);
121 /*************************************************************************/
122 QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons");
123 GroupButtons->setColumnLayout(0, Qt::Vertical);
124 GroupButtons->layout()->setSpacing(0);
125 GroupButtons->layout()->setMargin(0);
126 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
127 GroupButtonsLayout->setAlignment(Qt::AlignTop);
128 GroupButtonsLayout->setSpacing(6);
129 GroupButtonsLayout->setMargin(11);
131 buttonOk = new QPushButton(GroupButtons, "buttonOk");
132 buttonOk->setText(tr("BUT_CLOSE"));
133 buttonOk->setAutoDefault(TRUE);
134 buttonOk->setDefault(TRUE);
136 buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
137 buttonHelp->setText(tr("BUT_HELP"));
138 buttonHelp->setAutoDefault(TRUE);
140 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
141 GroupButtonsLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
142 GroupButtonsLayout->addWidget(buttonHelp, 0, 2);
144 VisuGUI_TransparencyDlgLayout->addWidget(GroupC1, 0, 0);
145 VisuGUI_TransparencyDlgLayout->addWidget(GroupButtons, 1, 0);
148 this->onSelectionChanged();
150 // signals and slots connections : after ValueHasChanged()
151 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
152 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
153 connect(Slider1, SIGNAL(valueChanged(int)), this, SLOT(SetTransparency()));
154 connect(Slider1, SIGNAL(sliderMoved(int)), this, SLOT(ValueHasChanged()));
155 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
158 //=================================================================================
159 // function : ~VisuGUI_TransparencyDlg()
161 //=================================================================================
162 VisuGUI_TransparencyDlg::~VisuGUI_TransparencyDlg()
164 // no need to delete child widgets, Qt does it all for us
167 //=======================================================================
168 // function : ClickOnOk()
170 //=======================================================================
171 void VisuGUI_TransparencyDlg::ClickOnOk()
176 //=======================================================================
177 // function : ClickOnHelp()
179 //=======================================================================
180 void VisuGUI_TransparencyDlg::ClickOnHelp()
182 QString aHelpFileName = "/files/changing_visualization_parameters_of_the_presenetation.htm#Changing3";
183 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
185 VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
186 app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
189 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
190 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
191 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(aHelpFileName),
192 QObject::tr("BUT_OK"));
196 //=================================================================================
197 // function : SetTransparency()
198 // purpose : Called when value of slider change
199 // : or the first time as initilisation
200 //=================================================================================
201 void VisuGUI_TransparencyDlg::SetTransparency()
204 SUIT_OverrideCursor wc;
205 float opacity = this->Slider1->value() / 100.;
208 mySelectionMgr->selectedObjects(aList);
210 SALOME_ListIteratorOfListIO It (aList);
211 for (;It.More(); It.Next()) {
212 Handle(SALOME_InteractiveObject) IOS = It.Value();
213 VISU_Actor* anActor = VISU::FindActor(myViewWindow, IOS->getEntry());
215 anActor->SetOpacity(opacity);
217 myViewWindow->Repaint();
222 //=================================================================================
223 // function : ValueHasChanged()
224 // purpose : Called when user moves a slider
225 //=================================================================================
226 void VisuGUI_TransparencyDlg::ValueHasChanged()
228 ValueLab->setText(QString::number(this->Slider1->value()) + "%");
231 //=================================================================================
232 // function : onSelectionChanged()
233 // purpose : Called when selection is changed
234 //=================================================================================
235 void VisuGUI_TransparencyDlg::onSelectionChanged()
241 mySelectionMgr->selectedObjects(aList);
243 if (aList.Extent() == 1) {
244 Handle(SALOME_InteractiveObject) FirstIOS = aList.First();
245 if (!FirstIOS.IsNull()) {
246 VISU_Actor* anActor = VISU::FindActor(myViewWindow, FirstIOS->getEntry());
248 opacity = int(anActor->GetOpacity() * 100. + 0.5);
250 } else if (aList.Extent() > 1) {
251 SALOME_ListIteratorOfListIO It (aList);
253 for (; It.More(); It.Next()) {
254 Handle(SALOME_InteractiveObject) IO = It.Value();
256 VISU_Actor* anActor = VISU::FindActor(myViewWindow, IO->getEntry());
258 int op = int(anActor->GetOpacity() * 100. + 0.5);
261 else if (setOp != op) {
272 Slider1->setValue(opacity);