Salome HOME
updated copyright message
[modules/gui.git] / src / SUIT / SUIT_Desktop.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 6c6bcb3..73a0100
@@ -1,30 +1,37 @@
-// Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
-// 
+// Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either 
-// version 2.1 of the License.
-// 
-// This library is distributed in the hope that it will be useful 
-// but WITHOUT ANY WARRANTY; without even the implied warranty of 
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 // Lesser General Public License for more details.
 //
-// You should have received a copy of the GNU Lesser General Public  
-// License along with this library; if not, write to the Free Software 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 #include "SUIT_Desktop.h"
 
-#include "SUIT_Tools.h"
 #include "SUIT_ViewWindow.h"
 
 #include <QtxLogoMgr.h>
 #include <QtxActionMenuMgr.h>
 #include <QtxActionToolMgr.h>
 
+#include <QPointer>
+#include <QCloseEvent>
+#include <QApplication>
+
 /*!\class SUIT_Desktop
  * Provide desktop management:\n
  * \li menu manager
  * \li windows
  */
 
+class SUIT_Desktop::ReparentEvent : public QEvent
+{
+public:
+  ReparentEvent( Type t, QObject* obj ) : QEvent( t ), myObj( obj ) {};
+
+  QObject* object() const { return myObj; }
+
+private:
+  QPointer<QObject> myObj;
+};
+
 /*!
   Constructor.
 */
@@ -66,9 +84,14 @@ bool SUIT_Desktop::event( QEvent* e )
   case QEvent::WindowDeactivate:
     emit deactivated();
     break;
+ /*case QEvent::Move:
+    emit moved();
+    break;*/
+  default:
+    break;
   }
 
-  return QMainWindow::event( e );
+  return QtxMainWindow::event( e );
 }
 
 /*!
@@ -85,16 +108,37 @@ void SUIT_Desktop::closeEvent( QCloseEvent* e )
 */
 void SUIT_Desktop::childEvent( QChildEvent* e )
 {
-  if ( e->type() == QEvent::ChildInserted && parentArea() &&
-       e->child()->isWidgetType() && e->child()->inherits( "SUIT_ViewWindow" ) )
-  {
-    QWidget* wid = (QWidget*)e->child();
-    bool vis = wid->isVisibleTo( wid->parentWidget() );
-    wid->reparent( parentArea(), QPoint( 0, 0 ), vis );
-    wid->setShown( vis );
+  if ( e->type() == QEvent::ChildAdded && e->child()->isWidgetType() ) {
+    // The following line is a workaround to avoid showing view window as a top-level window
+    // before re-parenting it to workstack (issue #23467).
+    // See SUIT_ViewWindow::setVisible() and SUIT_Desktop::customEvent().
+    e->child()->setProperty("blockShow", true );
+    QApplication::postEvent( this, new ReparentEvent( QEvent::Type( Reparent ), e->child() ) );
   }
-  else
+  else {
     QtxMainWindow::childEvent( e );
+  }
+}
+
+void SUIT_Desktop::customEvent( QEvent* e )
+{
+  if ( (int)e->type() != Reparent )
+    return;
+
+  ReparentEvent* re = (ReparentEvent*)e;
+  SUIT_ViewWindow* wid = ::qobject_cast<SUIT_ViewWindow*>( re->object() );
+  if ( wid )
+  {
+    bool invis = wid->testAttribute( Qt::WA_WState_ExplicitShowHide ) &&
+                 wid->testAttribute( Qt::WA_WState_Hidden );
+
+    // The following line is a workaround to avoid showing view window as a top-level window
+    // before re-parenting it to workstack (issue #23467).
+    // See SUIT_ViewWindow::setVisible() and SUIT_Desktop::childEvent().
+    wid->setProperty("blockShow", false);
+    addWindow( wid );
+    wid->setVisible( !invis );
+  }
 }
 
 /*!
@@ -113,11 +157,21 @@ QtxActionToolMgr* SUIT_Desktop::toolMgr() const
   return myToolMgr;
 }
 
+/*!
+  Gets logo manager.
+*/
+QtxLogoMgr* SUIT_Desktop::logoMgr() const
+{
+  return myLogoMgr;
+}
+
 /*!
   Returns the count of the existed logos.
 */
 int SUIT_Desktop::logoCount() const
 {
+  return 0;
+
   if ( !myLogoMgr )
     return 0;
   else
@@ -125,23 +179,12 @@ int SUIT_Desktop::logoCount() const
 }
 
 /*!
-  Adds new logo to the menu bar area.
-  Obsolete. Not should be used.
-  Use SUIT_Desktop::logoInsert();
-*/
-void SUIT_Desktop::addLogo( const QString& id, const QPixmap& pix )
-{
-  logoInsert( id, pix );
-}
-
-/*!
-  Removes a logo.
-  Obsolete. Not should be used.
-  Use SUIT_Desktop::logoRemove();
+  Adds new logo to the menu bar area
 */
-void SUIT_Desktop::removeLogo( const QString& id )
+void SUIT_Desktop::logoInsert( const QString& logoID, QMovie* logo, const int idx )
 {
-  logoRemove( id );
+  if ( myLogoMgr )
+    myLogoMgr->insert( logoID, logo, idx );
 }
 
 /*!
@@ -171,4 +214,26 @@ void SUIT_Desktop::logoClear()
     myLogoMgr->clear();
 }
 
+/*!
+  Emits activated signal
+*/
+void SUIT_Desktop::emitActivated()
+{
+  emit activated();
+}
 
+/*!
+  Emits message signal
+*/
+void SUIT_Desktop::emitMessage( const QString& theMessage )
+{
+  emit message( theMessage );
+}
+
+/*!
+  Activate window (default implementation just sets focus to the window.
+*/
+void SUIT_Desktop::setActiveWindow(SUIT_ViewWindow* wnd)
+{
+  if (wnd) wnd->setFocus();
+}