]> SALOME platform Git repositories - samples/atomsolv.git/blob - src/ATOMSOLVGUI/ATOMSOLVGUI_TransparencyDlg.cxx
Salome HOME
120942a07fb41157d0419c2d310e41425923c150
[samples/atomsolv.git] / src / ATOMSOLVGUI / ATOMSOLVGUI_TransparencyDlg.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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 #include "ATOMSOLVGUI_TransparencyDlg.h"
23 #include "ATOMSOLVGUI_Displayer.h"
24
25 #include <qframe.h>
26 #include <qlabel.h>
27 #include <qpushbutton.h>
28 #include <qslider.h>
29 #include <qlayout.h>
30 #include <qvariant.h>
31 #include <qtooltip.h>
32 #include <qwhatsthis.h>
33 #include <qapplication.h>
34 #include <qgroupbox.h>
35
36
37 ATOMSOLVGUI_TransparencyDlg::ATOMSOLVGUI_TransparencyDlg( QWidget* parent, const QStringList& entries )
38   :QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint )
39 {
40   myEntries = entries;
41
42   resize(152, 107); 
43   setWindowTitle(tr("TRANSPARENCY_DLG_TITLE"));
44   setSizeGripEnabled(TRUE);
45   QGridLayout* lay = new QGridLayout(this); 
46   lay->setSpacing(6);
47   lay->setMargin(11);
48
49   /*************************************************************************/
50   QGroupBox* GroupButtons = new QGroupBox( this );
51   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons );
52   GroupButtonsLayout->setAlignment( Qt::AlignTop );
53   GroupButtonsLayout->setSpacing( 6 );
54   GroupButtonsLayout->setMargin( 11 );
55   
56   QPushButton* buttonOk = new QPushButton( GroupButtons );
57   buttonOk->setText( tr( "BUT_OK" ) );
58   buttonOk->setAutoDefault( TRUE );
59   buttonOk->setDefault( TRUE );
60
61   QPushButton* buttonHelp = new QPushButton( GroupButtons );
62   buttonHelp->setText( tr( "BUT_HELP" ) );
63   buttonHelp->setAutoDefault( TRUE );
64   buttonHelp->setDefault( TRUE );
65   
66   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
67   GroupButtonsLayout->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1 );
68   GroupButtonsLayout->addWidget( buttonHelp, 0, 2 );
69
70   /*************************************************************************/
71   QGroupBox* GroupC1 = new QGroupBox( this );
72   QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
73   GroupC1Layout->setAlignment( Qt::AlignTop );
74   GroupC1Layout->setSpacing( 6 );
75   GroupC1Layout->setMargin( 11 );
76   GroupC1Layout->setColumnMinimumWidth(1, 100);
77   
78   QLabel* TextLabelOpaque = new QLabel( GroupC1 );
79   TextLabelOpaque->setText( tr( "TRANSPARENCY_TRANSPARENT"  ) );
80   TextLabelOpaque->setAlignment( Qt::AlignLeft );
81   GroupC1Layout->addWidget( TextLabelOpaque, 0, 0 );
82   GroupC1Layout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
83   
84   QLabel* TextLabelTransparent = new QLabel( GroupC1 );
85   TextLabelTransparent->setText( tr( "TRANSPARENCY_OPAQUE"  ) );
86   TextLabelTransparent->setAlignment( Qt::AlignRight );
87   GroupC1Layout->addWidget( TextLabelTransparent, 0, 2 );
88   
89   mySlider = new QSlider( Qt::Horizontal, GroupC1 );
90   mySlider->setMinimum( 0 );
91   mySlider->setMaximum( 10 );
92   GroupC1Layout->addWidget( mySlider, 0, 1 );
93   /*************************************************************************/
94   
95   lay->addWidget(GroupC1, 0,  0);
96   lay->addWidget(GroupButtons, 1, 0);
97     
98   if ( myEntries.count() == 1 ) {
99     int value = (int)(ATOMSOLVGUI_Displayer().getTransparency( myEntries[ 0 ] ) * 10.);
100     if ( value > 0 )
101       mySlider->setValue( value );
102   }
103   ValueHasChanged(mySlider->value());
104
105   // signals and slots connections : after ValueHasChanged()
106   connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
107   connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
108   connect(mySlider, SIGNAL(valueChanged(int)), this, SLOT(ValueHasChanged(int)));
109 }
110
111 //=================================================================================
112 // function : ClickOnHelp()
113 // purpose  :
114 //=================================================================================
115 void ATOMSOLVGUI_TransparencyDlg::ClickOnHelp()
116 {
117   // display a help in browser for example..
118   // not implemented yet..
119 }
120
121 //=================================================================================
122 // function : ValueHasChanged()
123 // purpose  : Called when value of slider change
124 //          : or the first time as initilisation
125 //=================================================================================
126 void ATOMSOLVGUI_TransparencyDlg::ValueHasChanged( int newValue )
127 {
128   ATOMSOLVGUI_Displayer().setTransparency( myEntries, (float)mySlider->value() * .1 );
129 }