Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/visu.git] / src / VISUGUI / VisuGUI_InputPanel.cxx
1 //  Copyright (C) 2007-2008  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 //  VISU VISUGUI : GUI of VISU component
23 //  File   : VisuGUI_InputPanel.cxx
24 //  Author : Oleg Uvarov
25 //  Module : VISU
26 //
27 #include "VisuGUI_InputPanel.h"
28 #include "VisuGUI_BasePanel.h"
29
30 #include <QVBoxLayout>
31
32 /*!
33  * \brief Constructor creates enmpty docable window with invisible QVBox
34           to be used as container of child widgets
35  */
36 VisuGUI_InputPanel::VisuGUI_InputPanel( QWidget* theParent )
37 : QtxDockWidget( tr( "WINDOW_TITLE" ), theParent ),
38   myCurrentPanel( 0 )
39 {
40   myGrp = new QWidget( this );
41   new QVBoxLayout( myGrp );
42   setWidget( myGrp );
43 }
44
45 /*!
46  * \brief Destructor: VisuGUI_InputPanel
47  */
48 VisuGUI_InputPanel::~VisuGUI_InputPanel()
49 {
50 }
51
52 /*!
53   \brief Shows thePanel in input panel. If there is visible 
54          panel then it is hidden 
55   \param thePanel widget
56 */
57 void VisuGUI_InputPanel::showPanel( VisuGUI_BasePanel* thePanel )
58 {
59   if ( !thePanel )
60     return;
61
62   setUpdatesEnabled( false );
63
64   if ( myCurrentPanel )
65     myCurrentPanel->hide();
66
67   if( isEmpty() )
68     show();
69
70   if ( !myPanels.contains( thePanel ) )
71   {
72     myPanels.insert( thePanel, true );
73     thePanel->setParent( myGrp );
74     myGrp->layout()->addWidget( thePanel );
75     connect( thePanel, SIGNAL( bpClose() ), this, SLOT( onClosePanel() ) );
76   }
77
78   thePanel->show();
79   myCurrentPanel = thePanel;
80   myPanels[ thePanel ] = true;
81
82   setUpdatesEnabled( true );
83   repaint();
84 }
85
86 /*!
87   \brief Hides thePanel in input panel. 
88   \param thePanel widget
89 */
90 void VisuGUI_InputPanel::hidePanel( VisuGUI_BasePanel* thePanel )
91 {
92   if ( !thePanel || myCurrentPanel != thePanel )
93     return;
94
95   thePanel->hide();
96   myCurrentPanel = 0;
97   myPanels[ thePanel ] = false;
98
99   if( isEmpty() )
100     hide();
101 }
102
103 /*!
104   \brief Hide all children panels
105 */
106 void VisuGUI_InputPanel::clear()
107 {
108   if ( myCurrentPanel )
109     hidePanel( myCurrentPanel );
110 }
111
112 /*!
113   \brief Returns true if no panels are shown
114 */
115 bool VisuGUI_InputPanel::isEmpty() const
116 {
117   QMap<VisuGUI_BasePanel*, bool>::const_iterator it = myPanels.begin(), itEnd = myPanels.end();
118   for( ; it != itEnd; ++it )
119   {
120     if( it.value() )
121       return false;
122   }
123   return true;
124 }
125
126 /*!
127   \brief Returns true if the panel is shown
128 */
129 bool VisuGUI_InputPanel::isShown( VisuGUI_BasePanel* thePanel ) const
130 {
131   return myPanels[ thePanel ];
132 }
133
134 /*!
135   \brief Close panel which emits signal close().
136 */
137 void VisuGUI_InputPanel::onClosePanel()
138 {
139   if( VisuGUI_BasePanel* aPanel = dynamic_cast<VisuGUI_BasePanel*>( sender() ) )
140     hidePanel( aPanel );
141 }