Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / SUIT / SUIT_Desktop.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 #include "SUIT_Desktop.h"
23
24 #include "SUIT_ViewWindow.h"
25
26 #include <QtxLogoMgr.h>
27 #include <QtxActionMenuMgr.h>
28 #include <QtxActionToolMgr.h>
29
30 #include <QPointer>
31 #include <QCloseEvent>
32 #include <QApplication>
33
34 /*!\class SUIT_Desktop
35  * Provide desktop management:\n
36  * \li menu manager
37  * \li tool manager
38  * \li windows
39  */
40
41 class SUIT_Desktop::ReparentEvent : public QEvent
42 {
43 public:
44   ReparentEvent( Type t, QObject* obj ) : QEvent( t ), myObj( obj ) {};
45
46   QObject* object() const { return myObj; }
47
48 private:
49   QPointer<QObject> myObj;
50 };
51
52 /*!
53   Constructor.
54 */
55 SUIT_Desktop::SUIT_Desktop()
56 : QtxMainWindow()
57 {
58   myMenuMgr = new QtxActionMenuMgr( this );
59   myToolMgr = new QtxActionToolMgr( this );
60   myLogoMgr = new QtxLogoMgr( menuBar() );
61 }
62
63 /*!
64   Destructor.
65 */
66 SUIT_Desktop::~SUIT_Desktop()
67 {
68 }
69
70 /*!
71   Emit on event \a e.
72 */
73 bool SUIT_Desktop::event( QEvent* e )
74 {
75   if ( !e )
76     return false;
77
78   switch ( e->type() )
79   {
80   case QEvent::WindowActivate:
81     emit activated();
82     break;
83   case QEvent::WindowDeactivate:
84     emit deactivated();
85     break;
86   default:
87     break;
88   }
89
90   return QMainWindow::event( e );
91 }
92
93 /*!
94   Close event \a e.
95 */
96 void SUIT_Desktop::closeEvent( QCloseEvent* e )
97 {
98   emit closing( this, e );
99   e->ignore();
100 }
101
102 /*!
103   Child event.
104 */
105 void SUIT_Desktop::childEvent( QChildEvent* e )
106 {
107   if ( e->type() == QEvent::ChildAdded && e->child()->isWidgetType() )
108     QApplication::postEvent( this, new ReparentEvent( QEvent::Type( Reparent ), e->child() ) );
109   else
110     QtxMainWindow::childEvent( e );
111 }
112
113 void SUIT_Desktop::customEvent( QEvent* e )
114 {
115   if ( (int)e->type() != Reparent )
116     return;
117
118   ReparentEvent* re = (ReparentEvent*)e;
119   SUIT_ViewWindow* wid = ::qobject_cast<SUIT_ViewWindow*>( re->object() );
120   if ( wid )
121   {
122     bool invis = wid->testAttribute( Qt::WA_WState_ExplicitShowHide ) &&
123                  wid->testAttribute( Qt::WA_WState_Hidden );
124
125     addWindow( wid );
126     wid->setShown( !invis );
127   }
128 }
129
130 /*!
131   Gets menu manager.
132 */
133 QtxActionMenuMgr* SUIT_Desktop::menuMgr() const
134 {
135   return myMenuMgr;
136 }
137
138 /*!
139   Gets tool manager.
140 */
141 QtxActionToolMgr* SUIT_Desktop::toolMgr() const
142 {
143   return myToolMgr;
144 }
145
146 /*!
147   Gets logo manager.
148 */
149 QtxLogoMgr* SUIT_Desktop::logoMgr() const
150 {
151   return myLogoMgr;
152 }
153
154 /*!
155   Returns the count of the existed logos.
156 */
157 int SUIT_Desktop::logoCount() const
158 {
159   return 0;
160
161   if ( !myLogoMgr )
162     return 0;
163   else
164     return myLogoMgr->count();
165 }
166
167 /*!
168   Adds new logo to the menu bar area
169 */
170 void SUIT_Desktop::logoInsert( const QString& logoID, QMovie* logo, const int idx )
171 {
172   if ( myLogoMgr )
173     myLogoMgr->insert( logoID, logo, idx );
174 }
175
176 /*!
177   Adds new logo to the menu bar area
178 */
179 void SUIT_Desktop::logoInsert( const QString& logoID, const QPixmap& logo, const int idx )
180 {
181   if ( myLogoMgr )
182     myLogoMgr->insert( logoID, logo, idx );
183 }
184
185 /*!
186   Removes a logo
187 */
188 void SUIT_Desktop::logoRemove( const QString& logoID )
189 {
190   if ( myLogoMgr )
191     myLogoMgr->remove( logoID );
192 }
193
194 /*!
195   Removes all logos 
196 */
197 void SUIT_Desktop::logoClear()
198 {
199   if ( myLogoMgr )
200     myLogoMgr->clear();
201 }
202
203 /*!
204   Emits activated signal
205 */
206 void SUIT_Desktop::emitActivated()
207 {
208   emit activated();
209 }
210
211 /*!
212   Emits message signal
213 */
214 void SUIT_Desktop::emitMessage( const QString& theMessage )
215 {
216   emit message( theMessage );
217 }