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