Back to index

salome-gui  6.5.0
STD_SDIDesktop.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "STD_SDIDesktop.h"
00024 
00025 #include <SUIT_ViewWindow.h>
00026 
00027 #include <QFrame>
00028 #include <QVBoxLayout>
00029 
00031 STD_SDIDesktop::STD_SDIDesktop()
00032 : SUIT_Desktop()
00033 {
00034   myMainWidget = new QFrame( this );
00035   myMainWidget->setFrameStyle( QFrame::Panel | QFrame::Sunken );
00036  
00037   QVBoxLayout* main = new QVBoxLayout( myMainWidget );
00038   main->setMargin( 0 );
00039 
00040   setCentralWidget( myMainWidget );
00041 }
00042 
00044 STD_SDIDesktop::~STD_SDIDesktop()
00045 {
00046 }
00047 
00049 SUIT_ViewWindow* STD_SDIDesktop::activeWindow() const
00050 {
00051   const QObjectList& lst = myMainWidget->children();
00052   QList<SUIT_ViewWindow*> winList;
00053   for ( QObjectList::const_iterator it = lst.begin(); it != lst.end(); ++it )
00054   {
00055     SUIT_ViewWindow* vw = ::qobject_cast<SUIT_ViewWindow*>( *it );
00056     if ( vw )
00057       winList.append( vw );
00058   }
00059 
00060   SUIT_ViewWindow* win = 0;
00061   for ( QList<SUIT_ViewWindow*>::iterator itr = winList.begin(); itr != winList.end() && !win; ++itr )
00062   {
00063     if ( (*itr)->isActiveWindow() )
00064       win = *itr;
00065   }
00066 
00067   if ( !win && !winList.isEmpty() )
00068     win = winList.first();
00069 
00070   return win;
00071 }
00072 
00074 QList<SUIT_ViewWindow*> STD_SDIDesktop::windows() const
00075 {
00076   QList<SUIT_ViewWindow*> winList;
00077   winList.append( activeWindow() );
00078   return winList;
00079 }
00080 
00082 void STD_SDIDesktop::addWindow( QWidget* w )
00083 {
00084   if ( !w || !centralWidget() || !centralWidget()->layout() )
00085     return;
00086 
00087   w->setParent( centralWidget() );
00088   centralWidget()->layout()->addWidget( w );
00089 }