Salome HOME
Copyrights update
[modules/gui.git] / src / LightApp / LightApp_WidgetContainer.cxx
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
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/
18 //
19 #include "LightApp_WidgetContainer.h"
20
21 #include <qobjectlist.h>
22 #include <qwidgetstack.h>
23
24 /*!
25   Constructor.
26 */
27 LightApp_WidgetContainer::LightApp_WidgetContainer( const int type, QWidget* parent )
28 : QDockWindow( QDockWindow::InDock, parent ),
29 myType( type )
30 {
31   setWidget( myStack = new QWidgetStack( this ) );
32   myStack->show();
33 }
34
35 /*!
36   Destructor.
37 */
38 LightApp_WidgetContainer::~LightApp_WidgetContainer()
39 {
40 }
41
42 /*!
43   Checks: is widget container is empty?
44 */
45 bool LightApp_WidgetContainer::isEmpty() const
46 {
47   const QObjectList* lst = myStack->children();
48   if ( !lst )
49     return true;
50
51   bool res = true;
52   for ( QObjectListIt it( *lst ); it.current() && res; ++it )
53   {
54     if ( it.current()->isWidgetType() && myStack->id( (QWidget*)it.current() ) != -1 )
55       res = false;
56   }
57   return res;
58 }
59
60 /*!
61   Gets type of widget container.
62 */
63 int LightApp_WidgetContainer::type() const
64 {
65   return myType;
66 }
67
68 /*!
69   Checks: is container contains widget with id \a id.
70 */
71 bool LightApp_WidgetContainer::contains( const int id ) const
72 {
73   return myStack->widget( id ) != 0;
74 }
75
76 /*!
77  * Insert widget(\a wid with id \a id) to container.And return id of widget in stack.
78  *\warning remove widget with id = \a id , if it was in container.
79  */
80 int LightApp_WidgetContainer::insert( const int id, QWidget* wid )
81 {
82   if ( id == -1 || !wid )
83     return -1;
84
85   if ( contains( id ) )
86     remove( id );
87
88   int stackId = myStack->addWidget( wid, id );
89   if ( !myStack->visibleWidget() )
90     myStack->raiseWidget( wid );
91
92   setCaption( myStack->visibleWidget() ? myStack->visibleWidget()->caption() : QString::null );
93
94   return stackId;
95 }
96
97 /*!
98   Remove widget(\a wid) from stack.
99 */
100 void LightApp_WidgetContainer::remove( const int id )
101 {
102   remove( myStack->widget( id ) );
103
104   setCaption( myStack->visibleWidget() ? myStack->visibleWidget()->caption() : QString::null );
105 }
106
107 /*!
108   Remove widget(\a wid) from stack.
109 */
110 void LightApp_WidgetContainer::remove( QWidget* wid )
111 {
112   myStack->removeWidget( wid );
113
114   setCaption( myStack->visibleWidget() ? myStack->visibleWidget()->caption() : QString::null );
115 }
116
117 /*!
118   Raise widget with id = \a id.
119 */
120 void LightApp_WidgetContainer::activate( const int id )
121 {
122   myStack->raiseWidget( id );
123
124   setCaption( myStack->visibleWidget() ? myStack->visibleWidget()->caption() : QString::null );
125 }
126
127 /*!
128   Raise widget (\a wid).
129 */
130 void LightApp_WidgetContainer::activate( QWidget* wid )
131 {
132   myStack->raiseWidget( wid );
133
134   setCaption( myStack->visibleWidget() ? myStack->visibleWidget()->caption() : QString::null );
135 }
136
137 /*!
138   Gets widget from container list(stack) by id = \a id.
139 */
140 QWidget* LightApp_WidgetContainer::widget( const int id ) const
141 {
142   return myStack->widget( id );
143 }
144
145 /*!
146   Gets visible widget.
147 */
148 QWidget* LightApp_WidgetContainer::active() const
149 {
150   return myStack->visibleWidget();
151 }