Salome HOME
92732bd27d7785303a7ce5504ba897de10ec532d
[samples/atomsolv.git] / src / ATOMSOLVGUI / ATOMSOLVGUI_TransparencyDlg.cxx
1 // Copyright (C) 2007-2020  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "ATOMSOLVGUI_TransparencyDlg.h"
21 #include "ATOMSOLVGUI_Displayer.h"
22
23 #include <qframe.h>
24 #include <qlabel.h>
25 #include <qpushbutton.h>
26 #include <qslider.h>
27 #include <qlayout.h>
28 #include <qvariant.h>
29 #include <qtooltip.h>
30 #include <qwhatsthis.h>
31 #include <qapplication.h>
32 #include <qgroupbox.h>
33
34
35 ATOMSOLVGUI_TransparencyDlg::ATOMSOLVGUI_TransparencyDlg( QWidget* parent, const QStringList& entries )
36   :QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint )
37 {
38   myEntries = entries;
39
40   resize(152, 107); 
41   setWindowTitle(tr("TRANSPARENCY_DLG_TITLE"));
42   setSizeGripEnabled(true);
43   QGridLayout* lay = new QGridLayout(this); 
44   lay->setSpacing(6);
45   lay->setMargin(11);
46
47   /*************************************************************************/
48   QGroupBox* GroupButtons = new QGroupBox( this );
49   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons );
50   GroupButtonsLayout->setAlignment( Qt::AlignTop );
51   GroupButtonsLayout->setSpacing( 6 );
52   GroupButtonsLayout->setMargin( 11 );
53   
54   QPushButton* buttonOk = new QPushButton( GroupButtons );
55   buttonOk->setText( tr( "BUT_OK" ) );
56   buttonOk->setAutoDefault( true );
57   buttonOk->setDefault( true );
58
59   QPushButton* buttonHelp = new QPushButton( GroupButtons );
60   buttonHelp->setText( tr( "BUT_HELP" ) );
61   buttonHelp->setAutoDefault( true );
62   buttonHelp->setDefault( true );
63   
64   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
65   GroupButtonsLayout->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1 );
66   GroupButtonsLayout->addWidget( buttonHelp, 0, 2 );
67
68   /*************************************************************************/
69   QGroupBox* GroupC1 = new QGroupBox( this );
70   QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
71   GroupC1Layout->setAlignment( Qt::AlignTop );
72   GroupC1Layout->setSpacing( 6 );
73   GroupC1Layout->setMargin( 11 );
74   GroupC1Layout->setColumnMinimumWidth(1, 100);
75   
76   QLabel* TextLabelOpaque = new QLabel( GroupC1 );
77   TextLabelOpaque->setText( tr( "TRANSPARENCY_TRANSPARENT"  ) );
78   TextLabelOpaque->setAlignment( Qt::AlignLeft );
79   GroupC1Layout->addWidget( TextLabelOpaque, 0, 0 );
80   GroupC1Layout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
81   
82   QLabel* TextLabelTransparent = new QLabel( GroupC1 );
83   TextLabelTransparent->setText( tr( "TRANSPARENCY_OPAQUE"  ) );
84   TextLabelTransparent->setAlignment( Qt::AlignRight );
85   GroupC1Layout->addWidget( TextLabelTransparent, 0, 2 );
86   
87   mySlider = new QSlider( Qt::Horizontal, GroupC1 );
88   mySlider->setMinimum( 0 );
89   mySlider->setMaximum( 10 );
90   GroupC1Layout->addWidget( mySlider, 0, 1 );
91   /*************************************************************************/
92   
93   lay->addWidget(GroupC1, 0,  0);
94   lay->addWidget(GroupButtons, 1, 0);
95     
96   if ( myEntries.count() == 1 ) {
97     int value = (int)(ATOMSOLVGUI_Displayer().getTransparency( myEntries[ 0 ] ) * 10.);
98     if ( value > 0 )
99       mySlider->setValue( value );
100   }
101   ValueHasChanged(mySlider->value());
102
103   // signals and slots connections : after ValueHasChanged()
104   connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
105   connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
106   connect(mySlider, SIGNAL(valueChanged(int)), this, SLOT(ValueHasChanged(int)));
107 }
108
109 //=================================================================================
110 // function : ClickOnHelp()
111 // purpose  :
112 //=================================================================================
113 void ATOMSOLVGUI_TransparencyDlg::ClickOnHelp()
114 {
115   // display a help in browser for example..
116   // not implemented yet..
117 }
118
119 //=================================================================================
120 // function : ValueHasChanged()
121 // purpose  : Called when value of slider change
122 //          : or the first time as initilisation
123 //=================================================================================
124 void ATOMSOLVGUI_TransparencyDlg::ValueHasChanged( int newValue )
125 {
126   ATOMSOLVGUI_Displayer().setTransparency( myEntries, (float)mySlider->value() * .1 );
127 }