Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / STD / STD_SDIDesktop.cxx
1 //  Copyright (C) 2007-2008  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.
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 #include "STD_SDIDesktop.h"
23
24 #include <SUIT_ViewWindow.h>
25
26 #include <QFrame>
27 #include <QVBoxLayout>
28
29 /*!Constructor. Create instance of QVBox*/
30 STD_SDIDesktop::STD_SDIDesktop()
31 : SUIT_Desktop()
32 {
33   myMainWidget = new QFrame( this );
34   myMainWidget->setFrameStyle( QFrame::Panel | QFrame::Sunken );
35  
36   QVBoxLayout* main = new QVBoxLayout( myMainWidget );
37   main->setMargin( 0 );
38
39   setCentralWidget( myMainWidget );
40 }
41
42 /*!Destructor.*/
43 STD_SDIDesktop::~STD_SDIDesktop()
44 {
45 }
46
47 /*!\retval SUIT_ViewWindow - return const active window.*/
48 SUIT_ViewWindow* STD_SDIDesktop::activeWindow() const
49 {
50   const QObjectList& lst = myMainWidget->children();
51   QList<SUIT_ViewWindow*> winList;
52   for ( QObjectList::const_iterator it = lst.begin(); it != lst.end(); ++it )
53   {
54     SUIT_ViewWindow* vw = ::qobject_cast<SUIT_ViewWindow*>( *it );
55     if ( vw )
56       winList.append( vw );
57   }
58
59   SUIT_ViewWindow* win = 0;
60   for ( QList<SUIT_ViewWindow*>::iterator itr = winList.begin(); itr != winList.end() && !win; ++itr )
61   {
62     if ( (*itr)->isActiveWindow() )
63       win = *itr;
64   }
65
66   if ( !win && !winList.isEmpty() )
67     win = winList.first();
68
69   return win;
70 }
71
72 /*!\retval QPtrList<SUIT_ViewWindow> - return const active window list.*/
73 QList<SUIT_ViewWindow*> STD_SDIDesktop::windows() const
74 {
75   QList<SUIT_ViewWindow*> winList;
76   winList.append( activeWindow() );
77   return winList;
78 }
79
80 /*! add new widget into desktop.*/
81 void STD_SDIDesktop::addWindow( QWidget* w )
82 {
83   if ( !w || !centralWidget() || !centralWidget()->layout() )
84     return;
85
86   w->setParent( centralWidget() );
87   centralWidget()->layout()->addWidget( w );
88 }