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