Salome HOME
Merge branch 'BR_IMPROVEMENTS' of ssh://git.salome-platform.org/modules/hydro into...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ZLevelsDlg.cxx
1 // Copyright (C) 2007-2015  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, or (at your option) any later version.
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 #include "HYDROGUI_ZLevelsDlg.h"
24
25 #include "HYDROGUI_OrderedListWidget.h"
26 #include "HYDROGUI_Module.h"
27 #include "HYDROGUI_ListSelector.h"
28
29 #include "LightApp_Application.h"
30 #include "LightApp_SelectionMgr.h"
31
32 #include <QCheckBox>
33 #include <QLayout>
34 #include <QPushButton>
35
36
37 /**
38   Constructor.
39   @param theParent the parent widget
40 */
41 HYDROGUI_ZLevelsDlg::HYDROGUI_ZLevelsDlg( QWidget* theParent, HYDROGUI_Module* theModule )
42 : QDialog( theParent )
43 {
44   // Change windows flags to remove minimize button
45   Qt::WindowFlags aFlags = windowFlags();
46   aFlags |= Qt::CustomizeWindowHint;
47   aFlags &= ~Qt::WindowMinimizeButtonHint;
48   aFlags &= ~Qt::WindowMaximizeButtonHint;
49   setWindowFlags( aFlags );
50
51   // Dialog title
52   setWindowTitle( tr( "CHANGE_LAYER_ORDER" ) );
53
54   // Main layout
55   QVBoxLayout* aMainLayout = new QVBoxLayout( this );
56   aMainLayout->setMargin( 5 );
57   aMainLayout->setSpacing( 5 );
58
59   // Ordered list widget
60   myListWidget = new HYDROGUI_OrderedListWidget( this );
61
62   // "All objects" check box
63   myAllObjects = new QCheckBox( tr( "ALL_OBJECTS" ) );
64
65   // Apply and close buttons
66   myApplyAndClose = new QPushButton( tr("APPLY_AND_CLOSE") );
67   myApplyAndClose->setDefault( true );
68   myApply = new QPushButton( tr("APPLY") );
69   myClose = new QPushButton( tr("CLOSE") );
70   
71   // Layout
72   // apply and close buttons
73   QHBoxLayout* aDlgButtonsLayout = new QHBoxLayout(); 
74   aDlgButtonsLayout->addWidget( myApplyAndClose );
75   aDlgButtonsLayout->addWidget( myApply );
76   aDlgButtonsLayout->addWidget( myClose );
77   aDlgButtonsLayout->addStretch();
78   // main
79   aMainLayout->addWidget( myListWidget );
80   aMainLayout->addWidget( myAllObjects );
81   aMainLayout->addLayout( aDlgButtonsLayout );
82
83   // Connections
84   connect( myAllObjects, SIGNAL( stateChanged( int ) ), this, SLOT( onStateChanged() ) );
85
86   connect( myApplyAndClose, SIGNAL( clicked() ), this, SIGNAL( applyOrderAndClose() ) );
87   connect( myApply, SIGNAL( clicked() ), this, SIGNAL( applyOrder() ) );
88   connect( myClose, SIGNAL( clicked() ), this, SLOT( reject() ) );
89
90   // Initialize
91   onStateChanged();
92
93   // Create selector
94   if ( theModule ) {
95     HYDROGUI_ListSelector* aListSelector = 
96       new HYDROGUI_ListSelector( myListWidget, theModule->getApp()->selectionMgr() );
97     aListSelector->setAutoBlock( true );
98   }
99 }
100
101 /**
102   Destructor.
103 */
104 HYDROGUI_ZLevelsDlg::~HYDROGUI_ZLevelsDlg()
105 {
106 }
107
108 /**
109   Set the list of objects (which supposed to be ordered by the dialog).
110   @param theObjects the list of objects
111 */
112 void HYDROGUI_ZLevelsDlg::setObjects( const HYDROGUI_ListModel::Object2VisibleList& theObjects )
113 {
114   myListWidget->setObjects( theObjects );
115 }
116
117 /**
118   Returns the ordered list of objects.
119   @return the list of objects
120 */
121 QList<Handle(HYDROData_Entity)> HYDROGUI_ZLevelsDlg::getObjects() const
122 {
123   return myListWidget->getObjects();
124 }
125
126 /**
127   Slot called on "All objects" check box state change.
128 */
129 void HYDROGUI_ZLevelsDlg::onStateChanged()
130 {
131   bool isAll = myAllObjects->isChecked();
132
133   QString aToolTip = isAll ? tr( "ALL_OBJECTS_CHECKED_TLT" ) :
134                              tr( "ALL_OBJECTS_UNCHECKED_TLT" );
135   myAllObjects->setToolTip( aToolTip );
136
137   myListWidget->setHiddenObjectsShown( isAll );
138 }