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),
73 mySelectionMgr(VISU::GetSelectionMgr(theModule)),
74 myViewWindow(VISU::GetActiveViewWindow<SVTK_ViewWindow>(theModule))
77 setName("VisuGUI_TransparencyDlg");
78 setCaption(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, "GroupC1");
86 GroupC1->setColumnLayout(0, Qt::Vertical);
87 GroupC1->layout()->setSpacing(0);
88 GroupC1->layout()->setMargin(0);
89 QGridLayout* GroupC1Layout = new QGridLayout(GroupC1->layout());
90 GroupC1Layout->setAlignment(Qt::AlignTop);
91 GroupC1Layout->setSpacing(6);
92 GroupC1Layout->setMargin(11);
94 TextLabelTransparent = new QLabel(GroupC1, "TextLabelTransparent");
95 TextLabelTransparent->setText(tr("TRANSPARENCY_TRANSPARENT" ));
96 TextLabelTransparent->setAlignment(AlignLeft);
97 GroupC1Layout->addWidget(TextLabelTransparent, 0, 0);
99 ValueLab = new QLabel(GroupC1, "ValueLab");
100 ValueLab->setAlignment(AlignCenter);
101 ValueLab->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
102 QFont fnt = ValueLab->font(); fnt.setBold(true); ValueLab->setFont(fnt);
103 GroupC1Layout->addWidget(ValueLab, 0, 1);
105 TextLabelOpaque = new QLabel(GroupC1, "TextLabelOpaque");
106 TextLabelOpaque->setText(tr("TRANSPARENCY_OPAQUE" ));
107 TextLabelOpaque->setAlignment(AlignRight);
108 GroupC1Layout->addWidget(TextLabelOpaque, 0, 2);
110 Slider1 = new QSlider(0, 10, 1, 5, Horizontal, GroupC1, "Slider1");
111 Slider1->setFocusPolicy(QWidget::NoFocus);
112 Slider1->setMinimumSize(300, 0);
113 Slider1->setTickmarks(QSlider::Above);
114 Slider1->setTickInterval(10);
115 Slider1->setTracking(true);
116 Slider1->setMinValue(0);
117 Slider1->setMaxValue(100);
118 Slider1->setLineStep(1);
119 Slider1->setPageStep(10);
120 GroupC1Layout->addMultiCellWidget(Slider1, 1, 1, 0, 2);
122 /*************************************************************************/
123 QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons");
124 GroupButtons->setColumnLayout(0, Qt::Vertical);
125 GroupButtons->layout()->setSpacing(0);
126 GroupButtons->layout()->setMargin(0);
127 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
128 GroupButtonsLayout->setAlignment(Qt::AlignTop);
129 GroupButtonsLayout->setSpacing(6);
130 GroupButtonsLayout->setMargin(11);
132 buttonOk = new QPushButton(GroupButtons, "buttonOk");
133 buttonOk->setText(tr("BUT_CLOSE"));
134 buttonOk->setAutoDefault(TRUE);
135 buttonOk->setDefault(TRUE);
137 buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
138 buttonHelp->setText(tr("BUT_HELP"));
139 buttonHelp->setAutoDefault(TRUE);
141 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
142 GroupButtonsLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
143 GroupButtonsLayout->addWidget(buttonHelp, 0, 2);
145 VisuGUI_TransparencyDlgLayout->addWidget(GroupC1, 0, 0);
146 VisuGUI_TransparencyDlgLayout->addWidget(GroupButtons, 1, 0);
149 this->onSelectionChanged();
151 // signals and slots connections : after ValueHasChanged()
152 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
153 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
154 connect(Slider1, SIGNAL(valueChanged(int)), this, SLOT(SetTransparency()));
155 connect(Slider1, SIGNAL(sliderMoved(int)), this, SLOT(ValueHasChanged()));
156 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
159 //=================================================================================
160 // function : ~VisuGUI_TransparencyDlg()
162 //=================================================================================
163 VisuGUI_TransparencyDlg::~VisuGUI_TransparencyDlg()
165 // no need to delete child widgets, Qt does it all for us
168 //=======================================================================
169 // function : ClickOnOk()
171 //=======================================================================
172 void VisuGUI_TransparencyDlg::ClickOnOk()
177 //=======================================================================
178 // function : ClickOnHelp()
180 //=======================================================================
181 void VisuGUI_TransparencyDlg::ClickOnHelp()
183 QString aHelpFileName = "viewing_3d_presentations_intro_page.html#width_opacity_anchor";
184 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
186 VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
187 app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
192 platform = "winapplication";
194 platform = "application";
196 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
197 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
198 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
199 QObject::tr("BUT_OK"));
203 //=================================================================================
204 // function : SetTransparency()
205 // purpose : Called when value of slider change
206 // : or the first time as initilisation
207 //=================================================================================
208 void VisuGUI_TransparencyDlg::SetTransparency()
211 SUIT_OverrideCursor wc;
212 float opacity = this->Slider1->value() / 100.;
215 mySelectionMgr->selectedObjects(aList);
217 SALOME_ListIteratorOfListIO anIter(aList);
218 for (; anIter.More(); anIter.Next()) {
219 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
220 VISU_Actor* anActor = VISU::FindActor(VISU::GetAppStudy(myModule), myViewWindow, anIO->getEntry());
222 anActor->SetOpacity(opacity);
224 myViewWindow->Repaint();
229 //=================================================================================
230 // function : ValueHasChanged()
231 // purpose : Called when user moves a slider
232 //=================================================================================
233 void VisuGUI_TransparencyDlg::ValueHasChanged()
235 ValueLab->setText(QString::number(this->Slider1->value()) + "%");
238 //=================================================================================
239 // function : onSelectionChanged()
240 // purpose : Called when selection is changed
241 //=================================================================================
242 void VisuGUI_TransparencyDlg::onSelectionChanged()
248 mySelectionMgr->selectedObjects(aList);
250 if (aList.Extent() == 1) {
251 Handle(SALOME_InteractiveObject) FirstIOS = aList.First();
252 if (!FirstIOS.IsNull()) {
253 VISU_Actor* anActor = VISU::FindActor(VISU::GetAppStudy(myModule), myViewWindow, FirstIOS->getEntry());
255 opacity = int(anActor->GetOpacity() * 100. + 0.5);
257 } else if (aList.Extent() > 1) {
258 SALOME_ListIteratorOfListIO It (aList);
260 for (; It.More(); It.Next()) {
261 Handle(SALOME_InteractiveObject) IO = It.Value();
263 VISU_Actor* anActor = VISU::FindActor(VISU::GetAppStudy(myModule), myViewWindow, IO->getEntry());
265 int op = int(anActor->GetOpacity() * 100. + 0.5);
268 else if (setOp != op) {
279 Slider1->setValue(opacity);
284 //=================================================================================
285 // function : keyPressEvent()
287 //=================================================================================
288 void VisuGUI_TransparencyDlg::keyPressEvent( QKeyEvent* e )
290 QDialog::keyPressEvent( e );
291 if ( e->isAccepted() )
294 if ( e->key() == Key_F1 )