Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/gui.git] / src / SUIT / SUIT_Desktop.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/ or email : webmaster.salome@opencascade.com
18 //
19 #include "SUIT_Desktop.h"
20
21 #include "SUIT_Tools.h"
22 #include "SUIT_ViewWindow.h"
23
24 #include <QtxLogoMgr.h>
25 #include <QtxActionMenuMgr.h>
26 #include <QtxActionToolMgr.h>
27
28 /*!\class SUIT_Desktop
29  * Provide desktop management:\n
30  * \li menu manager
31  * \li tool manager
32  * \li windows
33  */
34
35 /*!
36   Constructor.
37 */
38 SUIT_Desktop::SUIT_Desktop()
39 : QtxMainWindow()
40 {
41   myMenuMgr = new QtxActionMenuMgr( this );
42   myToolMgr = new QtxActionToolMgr( this );
43   myLogoMgr = new QtxLogoMgr( menuBar() );
44 }
45
46 /*!
47   Destructor.
48 */
49 SUIT_Desktop::~SUIT_Desktop()
50 {
51 }
52
53 /*!
54   Emit on event \a e.
55 */
56 bool SUIT_Desktop::event( QEvent* e )
57 {
58   if ( !e )
59     return false;
60
61   switch ( e->type() )
62   {
63   case QEvent::WindowActivate:
64     emit activated();
65     break;
66   case QEvent::WindowDeactivate:
67     emit deactivated();
68     break;
69   }
70
71   return QMainWindow::event( e );
72 }
73
74 /*!
75   Close event \a e.
76 */
77 void SUIT_Desktop::closeEvent( QCloseEvent* e )
78 {
79   emit closing( this, e );
80   e->ignore();
81 }
82
83 /*!
84   Child event.
85 */
86 void SUIT_Desktop::childEvent( QChildEvent* e )
87 {
88   if ( e->type() == QEvent::ChildInserted && parentArea() &&
89        e->child()->isWidgetType() && e->child()->inherits( "SUIT_ViewWindow" ) )
90   {
91     QWidget* wid = (QWidget*)e->child();
92     bool vis = wid->isVisibleTo( wid->parentWidget() );
93     wid->reparent( parentArea(), QPoint( 0, 0 ), vis );
94     wid->setShown( vis );
95   }
96   else
97     QtxMainWindow::childEvent( e );
98 }
99
100 /*!
101   Gets menu manager.
102 */
103 QtxActionMenuMgr* SUIT_Desktop::menuMgr() const
104 {
105   return myMenuMgr;
106 }
107
108 /*!
109   Gets tool manager.
110 */
111 QtxActionToolMgr* SUIT_Desktop::toolMgr() const
112 {
113   return myToolMgr;
114 }
115
116 /*!
117   Returns the count of the existed logos.
118 */
119 int SUIT_Desktop::logoCount() const
120 {
121   if ( !myLogoMgr )
122     return 0;
123   else
124     return myLogoMgr->count();
125 }
126
127 /*!
128   Adds new logo to the menu bar area.
129   Obsolete. Not should be used.
130   Use SUIT_Desktop::logoInsert();
131 */
132 void SUIT_Desktop::addLogo( const QString& id, const QPixmap& pix )
133 {
134   logoInsert( id, pix );
135 }
136
137 /*!
138   Removes a logo.
139   Obsolete. Not should be used.
140   Use SUIT_Desktop::logoRemove();
141 */
142 void SUIT_Desktop::removeLogo( const QString& id )
143 {
144   logoRemove( id );
145 }
146
147 /*!
148   Adds new logo to the menu bar area
149 */
150 void SUIT_Desktop::logoInsert( const QString& logoID, const QPixmap& logo, const int idx )
151 {
152   if ( myLogoMgr )
153     myLogoMgr->insert( logoID, logo, idx );
154 }
155
156 /*!
157   Removes a logo
158 */
159 void SUIT_Desktop::logoRemove( const QString& logoID )
160 {
161   if ( myLogoMgr )
162     myLogoMgr->remove( logoID );
163 }
164
165 /*!
166   Removes all logos 
167 */
168 void SUIT_Desktop::logoClear()
169 {
170   if ( myLogoMgr )
171     myLogoMgr->clear();
172 }
173
174 /*!
175   Emits activated signal
176 */
177 void SUIT_Desktop::emitActivated()
178 {
179   emit activated();
180 }
181
182 /*!
183   Emits message signal
184 */
185 void SUIT_Desktop::emitMessage( const QString& theMessage )
186 {
187   emit message( theMessage );
188 }