Salome HOME
Updated copyright comment
[modules/gui.git] / src / SUIT / SUIT_Desktop.cxx
1 // Copyright (C) 2007-2024  CEA, EDF, 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     // The following line is a workaround to avoid showing view window as a top-level window
113     // before re-parenting it to workstack (issue #23467).
114     // See SUIT_ViewWindow::setVisible() and SUIT_Desktop::customEvent().
115     e->child()->setProperty("blockShow", true );
116     QApplication::postEvent( this, new ReparentEvent( QEvent::Type( Reparent ), e->child() ) );
117   }
118   else {
119     QtxMainWindow::childEvent( e );
120   }
121 }
122
123 void SUIT_Desktop::customEvent( QEvent* e )
124 {
125   if ( (int)e->type() != Reparent )
126     return;
127
128   ReparentEvent* re = (ReparentEvent*)e;
129   SUIT_ViewWindow* wid = ::qobject_cast<SUIT_ViewWindow*>( re->object() );
130   if ( wid )
131   {
132     bool invis = wid->testAttribute( Qt::WA_WState_ExplicitShowHide ) &&
133                  wid->testAttribute( Qt::WA_WState_Hidden );
134
135     // The following line is a workaround to avoid showing view window as a top-level window
136     // before re-parenting it to workstack (issue #23467).
137     // See SUIT_ViewWindow::setVisible() and SUIT_Desktop::childEvent().
138     wid->setProperty("blockShow", false);
139     addWindow( wid );
140     wid->setVisible( !invis );
141   }
142 }
143
144 /*!
145   Gets menu manager.
146 */
147 QtxActionMenuMgr* SUIT_Desktop::menuMgr() const
148 {
149   return myMenuMgr;
150 }
151
152 /*!
153   Gets tool manager.
154 */
155 QtxActionToolMgr* SUIT_Desktop::toolMgr() const
156 {
157   return myToolMgr;
158 }
159
160 /*!
161   Gets logo manager.
162 */
163 QtxLogoMgr* SUIT_Desktop::logoMgr() const
164 {
165   return myLogoMgr;
166 }
167
168 /*!
169   Returns the count of the existed logos.
170 */
171 int SUIT_Desktop::logoCount() const
172 {
173   return 0;
174
175   if ( !myLogoMgr )
176     return 0;
177   else
178     return myLogoMgr->count();
179 }
180
181 /*!
182   Adds new logo to the menu bar area
183 */
184 void SUIT_Desktop::logoInsert( const QString& logoID, QMovie* logo, const int idx )
185 {
186   if ( myLogoMgr )
187     myLogoMgr->insert( logoID, logo, idx );
188 }
189
190 /*!
191   Adds new logo to the menu bar area
192 */
193 void SUIT_Desktop::logoInsert( const QString& logoID, const QPixmap& logo, const int idx )
194 {
195   if ( myLogoMgr )
196     myLogoMgr->insert( logoID, logo, idx );
197 }
198
199 /*!
200   Removes a logo
201 */
202 void SUIT_Desktop::logoRemove( const QString& logoID )
203 {
204   if ( myLogoMgr )
205     myLogoMgr->remove( logoID );
206 }
207
208 /*!
209   Removes all logos 
210 */
211 void SUIT_Desktop::logoClear()
212 {
213   if ( myLogoMgr )
214     myLogoMgr->clear();
215 }
216
217 /*!
218   Emits activated signal
219 */
220 void SUIT_Desktop::emitActivated()
221 {
222   emit activated();
223 }
224
225 /*!
226   Emits message signal
227 */
228 void SUIT_Desktop::emitMessage( const QString& theMessage )
229 {
230   emit message( theMessage );
231 }
232
233 /*!
234   Activate window (default implementation just sets focus to the window.
235 */
236 void SUIT_Desktop::setActiveWindow(SUIT_ViewWindow* wnd)
237 {
238   if (wnd) wnd->setFocus();
239 }