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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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"
39 #include "SALOME_ListIO.hxx"
40 #include "SALOME_ListIteratorOfListIO.hxx"
41 #include "SALOME_InteractiveObject.hxx"
43 #include "LightApp_Study.h"
44 #include "LightApp_SelectionMgr.h"
46 #include "SVTK_ViewWindow.h"
50 #include <qpushbutton.h>
53 #include <qgroupbox.h>
57 //=================================================================================
58 // class : VisuGUI_TransparencyDlg()
61 //=================================================================================
62 VisuGUI_TransparencyDlg::VisuGUI_TransparencyDlg( VisuGUI* theModule,
66 : QDialog( VISU::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
67 WStyle_Title | WStyle_SysMenu | WDestructiveClose ),
68 mySelectionMgr( VISU::GetSelectionMgr( theModule ) ),
69 myViewWindow( VISU::GetViewWindow( theModule ) )
72 setName("VisuGUI_TransparencyDlg");
73 setCaption(tr("TRANSPARENCY_TITLE" ));
74 setSizeGripEnabled(TRUE);
75 QGridLayout* VisuGUI_TransparencyDlgLayout = new QGridLayout(this);
76 VisuGUI_TransparencyDlgLayout->setSpacing(6);
77 VisuGUI_TransparencyDlgLayout->setMargin(11);
79 /*************************************************************************/
80 QGroupBox* GroupC1 = new QGroupBox(this, "GroupC1");
81 GroupC1->setColumnLayout(0, Qt::Vertical);
82 GroupC1->layout()->setSpacing(0);
83 GroupC1->layout()->setMargin(0);
84 QGridLayout* GroupC1Layout = new QGridLayout(GroupC1->layout());
85 GroupC1Layout->setAlignment(Qt::AlignTop);
86 GroupC1Layout->setSpacing(6);
87 GroupC1Layout->setMargin(11);
89 TextLabelTransparent = new QLabel(GroupC1, "TextLabelTransparent");
90 TextLabelTransparent->setText(tr("TRANSPARENCY_TRANSPARENT" ));
91 TextLabelTransparent->setAlignment(AlignLeft);
92 GroupC1Layout->addWidget(TextLabelTransparent, 0, 0);
94 ValueLab = new QLabel(GroupC1, "ValueLab");
95 ValueLab->setAlignment(AlignCenter);
96 ValueLab->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
97 QFont fnt = ValueLab->font(); fnt.setBold(true); ValueLab->setFont(fnt);
98 GroupC1Layout->addWidget(ValueLab, 0, 1);
100 TextLabelOpaque = new QLabel(GroupC1, "TextLabelOpaque");
101 TextLabelOpaque->setText(tr("TRANSPARENCY_OPAQUE" ));
102 TextLabelOpaque->setAlignment(AlignRight);
103 GroupC1Layout->addWidget(TextLabelOpaque, 0, 2);
105 Slider1 = new QSlider(0, 10, 1, 5, Horizontal, GroupC1, "Slider1");
106 Slider1->setFocusPolicy(QWidget::NoFocus);
107 Slider1->setMinimumSize(300, 0);
108 Slider1->setTickmarks(QSlider::Above);
109 Slider1->setTickInterval(10);
110 Slider1->setTracking(true);
111 Slider1->setMinValue(0);
112 Slider1->setMaxValue(100);
113 Slider1->setLineStep(1);
114 Slider1->setPageStep(10);
115 GroupC1Layout->addMultiCellWidget(Slider1, 1, 1, 0, 2);
117 /*************************************************************************/
118 QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons");
119 GroupButtons->setColumnLayout(0, Qt::Vertical);
120 GroupButtons->layout()->setSpacing(0);
121 GroupButtons->layout()->setMargin(0);
122 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
123 GroupButtonsLayout->setAlignment(Qt::AlignTop);
124 GroupButtonsLayout->setSpacing(6);
125 GroupButtonsLayout->setMargin(11);
127 buttonOk = new QPushButton(GroupButtons, "buttonOk");
128 buttonOk->setText(tr("BUT_CLOSE"));
129 buttonOk->setAutoDefault(TRUE);
130 buttonOk->setDefault(TRUE);
131 GroupButtonsLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 0);
132 GroupButtonsLayout->addWidget(buttonOk, 0, 1);
133 GroupButtonsLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 2);
135 VisuGUI_TransparencyDlgLayout->addWidget(GroupC1, 0, 0);
136 VisuGUI_TransparencyDlgLayout->addWidget(GroupButtons, 1, 0);
139 this->onSelectionChanged();
141 // signals and slots connections : after ValueHasChanged()
142 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
143 connect(Slider1, SIGNAL(valueChanged(int)), this, SLOT(SetTransparency()));
144 connect(Slider1, SIGNAL(sliderMoved(int)), this, SLOT(ValueHasChanged()));
145 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
148 //=================================================================================
149 // function : ~VisuGUI_TransparencyDlg()
151 //=================================================================================
152 VisuGUI_TransparencyDlg::~VisuGUI_TransparencyDlg()
154 // no need to delete child widgets, Qt does it all for us
157 //=======================================================================
158 // function : ClickOnOk()
160 //=======================================================================
161 void VisuGUI_TransparencyDlg::ClickOnOk()
166 //=================================================================================
167 // function : SetTransparency()
168 // purpose : Called when value of slider change
169 // : or the first time as initilisation
170 //=================================================================================
171 void VisuGUI_TransparencyDlg::SetTransparency()
174 SUIT_OverrideCursor wc;
175 float opacity = this->Slider1->value() / 100.;
178 mySelectionMgr->selectedObjects(aList);
180 SALOME_ListIteratorOfListIO It (aList);
181 for (;It.More(); It.Next()) {
182 Handle(SALOME_InteractiveObject) IOS = It.Value();
183 VISU_Actor* anActor = VISU::FindActor(myViewWindow, IOS->getEntry());
185 anActor->SetOpacity(opacity);
187 myViewWindow->Repaint();
192 //=================================================================================
193 // function : ValueHasChanged()
194 // purpose : Called when user moves a slider
195 //=================================================================================
196 void VisuGUI_TransparencyDlg::ValueHasChanged()
198 ValueLab->setText(QString::number(this->Slider1->value()) + "%");
201 //=================================================================================
202 // function : onSelectionChanged()
203 // purpose : Called when selection is changed
204 //=================================================================================
205 void VisuGUI_TransparencyDlg::onSelectionChanged()
211 mySelectionMgr->selectedObjects(aList);
213 if (aList.Extent() == 1) {
214 Handle(SALOME_InteractiveObject) FirstIOS = aList.First();
215 if (!FirstIOS.IsNull()) {
216 VISU_Actor* anActor = VISU::FindActor(myViewWindow, FirstIOS->getEntry());
218 opacity = int(anActor->GetOpacity() * 100. + 0.5);
220 } else if (aList.Extent() > 1) {
221 SALOME_ListIteratorOfListIO It (aList);
223 for (; It.More(); It.Next()) {
224 Handle(SALOME_InteractiveObject) IO = It.Value();
226 VISU_Actor* anActor = VISU::FindActor(myViewWindow, IO->getEntry());
228 int op = int(anActor->GetOpacity() * 100. + 0.5);
231 else if (setOp != op) {
242 Slider1->setValue(opacity);