]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROGUI/HYDROGUI_ZLevelsDlg.cxx
Salome HOME
merge master 2015/06/04
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ZLevelsDlg.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROGUI_ZLevelsDlg.h"
20
21 #include "HYDROGUI_OrderedListWidget.h"
22 #include "HYDROGUI_Module.h"
23 #include "HYDROGUI_ListSelector.h"
24
25 #include "LightApp_Application.h"
26 #include "LightApp_SelectionMgr.h"
27
28 #include <QCheckBox>
29 #include <QLayout>
30 #include <QPushButton>
31
32
33 /**
34   Constructor.
35   @param theParent the parent widget
36 */
37 HYDROGUI_ZLevelsDlg::HYDROGUI_ZLevelsDlg( QWidget* theParent, HYDROGUI_Module* theModule )
38 : QDialog( theParent )
39 {
40   // Change windows flags to remove minimize button
41   Qt::WindowFlags aFlags = windowFlags();
42   aFlags |= Qt::CustomizeWindowHint;
43   aFlags &= ~Qt::WindowMinimizeButtonHint;
44   aFlags &= ~Qt::WindowMaximizeButtonHint;
45   setWindowFlags( aFlags );
46
47   // Dialog title
48   setWindowTitle( tr( "CHANGE_LAYER_ORDER" ) );
49
50   // Main layout
51   QVBoxLayout* aMainLayout = new QVBoxLayout( this );
52   aMainLayout->setMargin( 5 );
53   aMainLayout->setSpacing( 5 );
54
55   // Ordered list widget
56   myListWidget = new HYDROGUI_OrderedListWidget( this );
57
58   // "All objects" check box
59   myAllObjects = new QCheckBox( tr( "ALL_OBJECTS" ) );
60
61   // Apply and close buttons
62   myApply = new QPushButton( tr("APPLY") );
63   myApply->setDefault( true );
64   myClose = new QPushButton( tr("CLOSE") );
65   
66   // Layout
67   // apply and close buttons
68   QHBoxLayout* aDlgButtonsLayout = new QHBoxLayout(); 
69   aDlgButtonsLayout->addWidget( myApply );
70   aDlgButtonsLayout->addWidget( myClose );
71   aDlgButtonsLayout->addStretch();
72   // main
73   aMainLayout->addWidget( myListWidget );
74   aMainLayout->addWidget( myAllObjects );
75   aMainLayout->addLayout( aDlgButtonsLayout );
76
77   // Connections
78   connect( myAllObjects, SIGNAL( stateChanged( int ) ), this, SLOT( onStateChanged() ) );
79
80   connect( myApply, SIGNAL( clicked() ), this, SIGNAL( applyOrder() ) );
81   connect( myClose, SIGNAL( clicked() ), this, SLOT( reject() ) );
82
83   // Initialize
84   onStateChanged();
85
86   // Create selector
87   if ( theModule ) {
88     HYDROGUI_ListSelector* aListSelector = 
89       new HYDROGUI_ListSelector( myListWidget, theModule->getApp()->selectionMgr() );
90     aListSelector->setAutoBlock( true );
91   }
92 }
93
94 /**
95   Destructor.
96 */
97 HYDROGUI_ZLevelsDlg::~HYDROGUI_ZLevelsDlg()
98 {
99 }
100
101 /**
102   Set the list of objects (which supposed to be ordered by the dialog).
103   @param theObjects the list of objects
104 */
105 void HYDROGUI_ZLevelsDlg::setObjects( const HYDROGUI_ListModel::Object2VisibleList& theObjects )
106 {
107   myListWidget->setObjects( theObjects );
108 }
109
110 /**
111   Returns the ordered list of objects.
112   @return the list of objects
113 */
114 QList<Handle(HYDROData_Entity)> HYDROGUI_ZLevelsDlg::getObjects() const
115 {
116   return myListWidget->getObjects();
117 }
118
119 /**
120   Slot called on "All objects" check box state change.
121 */
122 void HYDROGUI_ZLevelsDlg::onStateChanged()
123 {
124   bool isAll = myAllObjects->isChecked();
125
126   QString aToolTip = isAll ? tr( "ALL_OBJECTS_CHECKED_TLT" ) :
127                              tr( "ALL_OBJECTS_UNCHECKED_TLT" );
128   myAllObjects->setToolTip( aToolTip );
129
130   myListWidget->setHiddenObjectsShown( isAll );
131 }