]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_TransparencyDlg.cxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/visu.git] / src / VISUGUI / VisuGUI_TransparencyDlg.cxx
1 //  VISU VISUGUI : GUI of VISU component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : VisuGUI_TransparencyDlg.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : VISU
27 //  $Header$
28
29 #include "VisuGUI_TransparencyDlg.h"
30
31 #include "VisuGUI.h"
32 #include "VisuGUI_ViewTools.h"
33 #include "VisuGUI_Tools.h"
34 #include "VISU_Actor.h"
35
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"
41
42 #include "SALOME_ListIO.hxx"
43 #include "SALOME_ListIteratorOfListIO.hxx"
44 #include "SALOME_InteractiveObject.hxx"
45
46 #include "LightApp_Study.h"
47 #include "LightApp_SelectionMgr.h"
48 #include "LightApp_Application.h"
49
50 #include "SVTK_ViewWindow.h"
51
52 // QT Includes
53 #include <qlabel.h>
54 #include <qpushbutton.h>
55 #include <qslider.h>
56 #include <qlayout.h>
57 #include <qgroupbox.h>
58
59 using namespace std;
60
61 //=================================================================================
62 // class    : VisuGUI_TransparencyDlg()
63 // purpose  :
64 //
65 //=================================================================================
66 VisuGUI_TransparencyDlg::VisuGUI_TransparencyDlg (VisuGUI* theModule,
67                                                   const char* name,
68                                                   bool modal,
69                                                   WFlags fl)
70   : QDialog(VISU::GetDesktop(theModule), name, modal, WStyle_Customize | WStyle_NormalBorder |
71             WStyle_Title | WStyle_SysMenu | WDestructiveClose),
72     myModule(theModule),
73     mySelectionMgr(VISU::GetSelectionMgr(theModule)),
74     myViewWindow(VISU::GetActiveViewWindow<SVTK_ViewWindow>(theModule))
75 {
76   if (!name)
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);
83
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);
93
94   TextLabelTransparent = new QLabel(GroupC1, "TextLabelTransparent");
95   TextLabelTransparent->setText(tr("TRANSPARENCY_TRANSPARENT" ));
96   TextLabelTransparent->setAlignment(AlignLeft);
97   GroupC1Layout->addWidget(TextLabelTransparent, 0, 0);
98
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);
104
105   TextLabelOpaque = new QLabel(GroupC1, "TextLabelOpaque");
106   TextLabelOpaque->setText(tr("TRANSPARENCY_OPAQUE" ));
107   TextLabelOpaque->setAlignment(AlignRight);
108   GroupC1Layout->addWidget(TextLabelOpaque, 0, 2);
109
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);
121
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);
131
132   buttonOk = new QPushButton(GroupButtons, "buttonOk");
133   buttonOk->setText(tr("BUT_CLOSE"));
134   buttonOk->setAutoDefault(TRUE);
135   buttonOk->setDefault(TRUE);
136
137   buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
138   buttonHelp->setText(tr("BUT_HELP"));
139   buttonHelp->setAutoDefault(TRUE);
140
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);
144
145   VisuGUI_TransparencyDlgLayout->addWidget(GroupC1,      0, 0);
146   VisuGUI_TransparencyDlgLayout->addWidget(GroupButtons, 1, 0);
147
148   // Initial state
149   this->onSelectionChanged();
150
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()));
157 }
158
159 //=================================================================================
160 // function : ~VisuGUI_TransparencyDlg()
161 // purpose  :
162 //=================================================================================
163 VisuGUI_TransparencyDlg::~VisuGUI_TransparencyDlg()
164 {
165   // no need to delete child widgets, Qt does it all for us
166 }
167
168 //=======================================================================
169 // function : ClickOnOk()
170 // purpose  :
171 //=======================================================================
172 void VisuGUI_TransparencyDlg::ClickOnOk()
173 {
174   close();
175 }
176
177 //=======================================================================
178 // function : ClickOnHelp()
179 // purpose  :
180 //=======================================================================
181 void VisuGUI_TransparencyDlg::ClickOnHelp()
182 {
183   QString aHelpFileName = "viewing_3d_presentations_intro_page.html#width_opacity_anchor";
184   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
185   if (app) {
186     VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
187     app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
188   }
189   else {
190     QString platform;
191 #ifdef WIN32
192     platform = "winapplication";
193 #else
194     platform = "application";
195 #endif
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"));
200   }
201 }
202
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()
209 {
210   if( myViewWindow ) {
211     SUIT_OverrideCursor wc;
212     float opacity = this->Slider1->value() / 100.;
213
214     SALOME_ListIO aList;
215     mySelectionMgr->selectedObjects(aList);
216
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());
221       if (anActor)
222         anActor->SetOpacity(opacity);
223     }
224     myViewWindow->Repaint();
225   }
226   ValueHasChanged();
227 }
228
229 //=================================================================================
230 // function : ValueHasChanged()
231 // purpose  : Called when user moves a slider
232 //=================================================================================
233 void VisuGUI_TransparencyDlg::ValueHasChanged()
234 {
235   ValueLab->setText(QString::number(this->Slider1->value()) + "%");
236 }
237
238 //=================================================================================
239 // function : onSelectionChanged()
240 // purpose  : Called when selection is changed
241 //=================================================================================
242 void VisuGUI_TransparencyDlg::onSelectionChanged()
243 {
244   if( myViewWindow ) {
245     int opacity = 100;
246
247     SALOME_ListIO aList;
248     mySelectionMgr->selectedObjects(aList);
249
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());
254         if (anActor)
255           opacity = int(anActor->GetOpacity() * 100. + 0.5);
256       }
257     } else if (aList.Extent() > 1) {
258       SALOME_ListIteratorOfListIO It (aList);
259       int setOp = -1;
260       for (; It.More(); It.Next()) {
261         Handle(SALOME_InteractiveObject) IO = It.Value();
262         if (!IO.IsNull()) {
263           VISU_Actor* anActor = VISU::FindActor(VISU::GetAppStudy(myModule), myViewWindow, IO->getEntry());
264           if (anActor) {
265             int op = int(anActor->GetOpacity() * 100. + 0.5);
266             if (setOp < 0)
267               setOp = op;
268             else if (setOp != op) {
269               setOp = 100;
270               break;
271             }
272           }
273         }
274       }
275       if (setOp >= 0)
276         opacity = setOp;
277     } else {
278     }
279     Slider1->setValue(opacity);
280   }
281   ValueHasChanged();
282 }
283
284 //=================================================================================
285 // function : keyPressEvent()
286 // purpose  :
287 //=================================================================================
288 void VisuGUI_TransparencyDlg::keyPressEvent( QKeyEvent* e )
289 {
290   QDialog::keyPressEvent( e );
291   if ( e->isAccepted() )
292     return;
293
294   if ( e->key() == Key_F1 )
295     {
296       e->accept();
297       ClickOnHelp();
298     }
299 }