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