+// Copyright (C) 2007-2016 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, 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
+// 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 <qtoolbar.h>
-#include <qmenubar.h>
-#include <qdockarea.h>
-#include <qstatusbar.h>
-#include <qapplication.h>
-#include <qhbox.h>
-#include <qlabel.h>
-#include <qstyle.h>
-
-/*!
- Class: SUIT_Desktop::LogoMgr
- Level: Internal
-*/
-
-class SUIT_Desktop::LogoMgr : public QObject
-{
-public:
- LogoMgr( QMenuBar* );
- virtual ~LogoMgr();
-
- int count() const;
-
- void insert( const QString&, const QPixmap&, const int = -1 );
- void remove( const QString& );
- void clear();
-
- QMenuBar* menuBar() const;
-
-private:
- void generate();
- int find( const QString& ) const;
-
-private:
- typedef struct { QString id; QPixmap pix; } LogoInfo;
- typedef QValueList<LogoInfo> LogoList;
-
-private:
- int myId;
- QMenuBar* myMenus;
- LogoList myLogos;
-};
-
-SUIT_Desktop::LogoMgr::LogoMgr( QMenuBar* mb )
-: QObject( mb ),
-myMenus( mb ),
-myId( 0 )
-{
-}
-
-SUIT_Desktop::LogoMgr::~LogoMgr()
-{
-}
-
-QMenuBar* SUIT_Desktop::LogoMgr::menuBar() const
-{
- return myMenus;
-}
-
-int SUIT_Desktop::LogoMgr::count() const
-{
- return myLogos.count();
-}
-
-void SUIT_Desktop::LogoMgr::insert( const QString& id, const QPixmap& pix, const int index )
-{
- if ( pix.isNull() )
- return;
-
- LogoInfo* inf = 0;
-
- int idx = find( id );
- if ( idx < 0 )
- {
- idx = index < (int)myLogos.count() ? index : -1;
- if ( idx < 0 )
- inf = &( *myLogos.append( LogoInfo() ) );
- else
- inf = &( *myLogos.insert( myLogos.at( idx ), LogoInfo() ) );
- }
- else
- inf = &( *myLogos.at( idx ) );
-
-
- inf->id = id;
- inf->pix = pix;
-
- generate();
-}
-
-void SUIT_Desktop::LogoMgr::remove( const QString& id )
-{
- int idx = find( id );
- if ( idx < 0 )
- return;
-
- myLogos.remove( myLogos.at( idx ) );
-
- generate();
-}
-
-void SUIT_Desktop::LogoMgr::clear()
-{
- myLogos.clear();
- generate();
-}
-
-void SUIT_Desktop::LogoMgr::generate()
-{
- if ( !menuBar() )
- return;
-
- if ( myId )
- menuBar()->removeItem( myId );
-
- myId = 0;
-
- if ( myLogos.isEmpty() )
- return;
-
- class LogoBox : public QHBox
- {
- public:
- LogoBox( QWidget* parent = 0, const char* name = 0, WFlags f = 0 ) : QHBox( parent, name, f ) {};
-
- void addSpacing( int spacing )
- {
- QApplication::sendPostedEvents( this, QEvent::ChildInserted );
- ((QHBoxLayout*)layout())->addSpacing( spacing );
- }
-
- protected:
- void drawContents( QPainter* p )
- {
- if ( parentWidget()->inherits( "QMenuBar" ) )
- style().drawControl( QStyle::CE_MenuBarEmptyArea, p, this, contentsRect(), colorGroup() );
- else
- QHBox::drawContents( p );
- }
- };
-
- LogoBox* cnt = new LogoBox( menuBar() );
- cnt->setSpacing( 2 );
-
- for ( LogoList::const_iterator it = myLogos.begin(); it != myLogos.end(); ++it )
- {
- QLabel* logoLab = new QLabel( cnt );
- logoLab->setPixmap( (*it).pix );
- logoLab->setScaledContents( false );
- logoLab->setAlignment( QLabel::AlignCenter );
- }
- QApplication::sendPostedEvents( cnt, QEvent::ChildInserted );
- cnt->addSpacing( 2 );
-
- myId = menuBar()->insertItem( cnt );
-
- QApplication::sendPostedEvents( menuBar()->parentWidget(), QEvent::LayoutHint );
- QApplication::postEvent( menuBar()->parentWidget(), new QEvent( QEvent::LayoutHint ) );
-}
-
-int SUIT_Desktop::LogoMgr::find( const QString& id ) const
-{
- int idx = -1;
- for ( uint i = 0; i < myLogos.count() && idx < 0; i++ )
- {
- if ( (*myLogos.at( i ) ).id == id )
- idx = i;
- }
- return idx;
-}
+#include <QPointer>
+#include <QCloseEvent>
+#include <QApplication>
/*!\class SUIT_Desktop
* Provide desktop management:\n
* \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.
{
myMenuMgr = new QtxActionMenuMgr( this );
myToolMgr = new QtxActionToolMgr( this );
- myLogoMgr = new LogoMgr( menuBar() );
+ myLogoMgr = new QtxLogoMgr( menuBar() );
}
/*!
case QEvent::WindowDeactivate:
emit deactivated();
break;
+ /*case QEvent::Move:
+ emit moved();
+ break;*/
+ default:
+ break;
}
- return QMainWindow::event( e );
+ return QtxMainWindow::event( 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() )
+ QApplication::postEvent( this, new ReparentEvent( QEvent::Type( Reparent ), e->child() ) );
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 );
+
+ addWindow( wid );
+ wid->setVisible( !invis );
+ }
+}
+
/*!
Gets menu manager.
*/
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
}
/*!
- 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 );
}
/*!
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();
+}