Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/gui.git] / src / STD / STD_MDIDesktop.cxx
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #include "STD_MDIDesktop.h"
20
21 #include <SUIT_Session.h>
22 #include <SUIT_ViewWindow.h>
23 #include <SUIT_ResourceMgr.h>
24
25 #include <QtxAction.h>
26 #include <QtxActionMenuMgr.h>
27 #include <QtxWorkspaceAction.h>
28
29 #include <qvbox.h>
30 #include <qmenubar.h>
31 #include <qworkspace.h>
32 #include <qobjectlist.h>
33
34 #include <stdarg.h>
35
36 /*!Constructor.*/
37 STD_MDIDesktop::STD_MDIDesktop()
38 : SUIT_Desktop(),
39 myWorkspace( 0 ),
40 myWorkspaceAction( 0 )
41 {
42   QVBox* base = new QVBox( this );
43   base->setFrameStyle( QFrame::Panel | QFrame::Sunken );
44
45   setCentralWidget( base );
46
47   myWorkspace = new QWorkspace( base );
48
49   connect( myWorkspace, SIGNAL( windowActivated( QWidget* ) ),
50            this, SLOT( onWindowActivated( QWidget* ) ) );
51
52   createActions();
53 }
54
55 /*!destructor.*/
56 STD_MDIDesktop::~STD_MDIDesktop()
57 {
58 }
59
60 /*!\retval SUIT_ViewWindow - return const active window.*/
61 SUIT_ViewWindow* STD_MDIDesktop::activeWindow() const
62 {
63   SUIT_ViewWindow* wnd = 0;
64
65   QWidget* wid = myWorkspace->activeWindow();
66   if ( wid && wid->inherits( "SUIT_ViewWindow" ) )
67     wnd = (SUIT_ViewWindow*)wid;
68
69   return wnd;
70 }
71
72 /*!\retval QPtrList<SUIT_ViewWindow> - return const active window list.*/
73 QPtrList<SUIT_ViewWindow> STD_MDIDesktop::windows() const
74 {
75   QPtrList<SUIT_ViewWindow> winList;
76
77   QWidgetList children = myWorkspace->windowList();
78   for ( QWidgetListIt it( children ); it.current(); ++it )
79   {
80     if ( it.current()->inherits( "SUIT_ViewWindow" ) )
81       winList.append( (SUIT_ViewWindow*)it.current() );
82   }
83
84   return winList;
85 }
86
87 /*!\retval QWidget - pointer to work space.*/
88 QWidget* STD_MDIDesktop::parentArea() const
89 {
90   return workspace();
91 }
92
93 /*!Call method perform for operation \a type.*/
94 void STD_MDIDesktop::windowOperation( const int type )
95 {
96   myWorkspaceAction->perform( operationFlag( type ) );
97 }
98
99 /*!Sets window operations by \a first ... parameters.*/
100 void STD_MDIDesktop::setWindowOperations( const int first, ... )
101 {
102   va_list ints;
103         va_start( ints, first );
104
105         QValueList<int> typeList;
106
107         int cur = first;
108         while ( cur )
109         {
110           typeList.append( cur );
111                 cur = va_arg( ints, int );
112   }
113
114         setWindowOperations( typeList );
115 }
116
117 /*!Sets window operations by variable \a opList - operation list.*/
118 void STD_MDIDesktop::setWindowOperations( const QValueList<int>& opList )
119 {
120   int flags = 0;
121
122   for ( QValueList<int>::const_iterator it = opList.begin(); it != opList.end(); ++it )
123     flags = flags | operationFlag( *it );
124
125   myWorkspaceAction->setItems( flags );
126 }
127
128 /*!\retval QWorkspace pointer - work space.*/
129 QWorkspace* STD_MDIDesktop::workspace() const
130 {
131   return myWorkspace;
132 }
133
134 /*!Emit window activated.*/
135 void STD_MDIDesktop::onWindowActivated( QWidget* w )
136 {
137   if ( w && w->inherits( "SUIT_ViewWindow" ) )
138     emit windowActivated( (SUIT_ViewWindow*)w );
139 }
140
141 /*!Create actions: cascade, Tile, Tile Horizontal, Tile Vertical*/
142 void STD_MDIDesktop::createActions()
143 {
144   if ( myWorkspaceAction )
145     return;
146
147   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
148   if ( !resMgr )
149     return;
150
151   myWorkspaceAction = new QtxWorkspaceAction( workspace(), this );
152
153   myWorkspaceAction->setItems( QtxWorkspaceAction::Cascade | QtxWorkspaceAction::Tile |
154                                QtxWorkspaceAction::HTile | QtxWorkspaceAction::VTile |
155                                QtxWorkspaceAction::Windows );
156
157   // Cascade
158   myWorkspaceAction->setIconSet( QtxWorkspaceAction::Cascade,
159                                  resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_CASCADE" ) ) );
160   myWorkspaceAction->setMenuText( QtxWorkspaceAction::Cascade, tr( "MEN_DESK_WINDOW_CASCADE" ) );
161   myWorkspaceAction->setStatusTip( QtxWorkspaceAction::Cascade, tr( "PRP_DESK_WINDOW_CASCADE" ) );
162
163   // Tile
164   myWorkspaceAction->setIconSet( QtxWorkspaceAction::Tile,
165                                  resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_TILE" ) ) );
166   myWorkspaceAction->setMenuText( QtxWorkspaceAction::Tile, tr( "MEN_DESK_WINDOW_TILE" ) );
167   myWorkspaceAction->setStatusTip( QtxWorkspaceAction::Tile, tr( "PRP_DESK_WINDOW_TILE" ) );
168
169   // Tile Horizontal
170   myWorkspaceAction->setIconSet( QtxWorkspaceAction::HTile,
171                                  resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_HTILE" ) ) );
172   myWorkspaceAction->setMenuText( QtxWorkspaceAction::HTile, tr( "MEN_DESK_WINDOW_HTILE" ) );
173   myWorkspaceAction->setStatusTip( QtxWorkspaceAction::HTile, tr( "PRP_DESK_WINDOW_HTILE" ) );
174
175   // Tile Vertical
176   myWorkspaceAction->setIconSet( QtxWorkspaceAction::VTile,
177                                  resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_VTILE" ) ) );
178   myWorkspaceAction->setMenuText( QtxWorkspaceAction::VTile, tr( "MEN_DESK_WINDOW_VTILE" ) );
179   myWorkspaceAction->setStatusTip( QtxWorkspaceAction::VTile, tr( "PRP_DESK_WINDOW_VTILE" ) );
180
181
182   QtxActionMenuMgr* mMgr = menuMgr();
183   if ( !mMgr )
184     return;
185
186   int winMenuId = mMgr->insert( tr( "MEN_DESK_WINDOW" ), -1, 100, MenuWindowId );
187   mMgr->insert( myWorkspaceAction, winMenuId, -1 );
188   mMgr->insert( QtxActionMenuMgr::separator(), winMenuId, -1 );
189 }
190
191 /*!Convert STD_MDIDesktop enumerations to QtxWorkspaceAction.*/
192 int STD_MDIDesktop::operationFlag( const int type ) const
193 {
194   int res = 0;
195   switch ( type )
196   {
197   case Cascade:
198     res = QtxWorkspaceAction::Cascade;
199     break;
200   case Tile:
201     res = QtxWorkspaceAction::Tile;
202     break;
203   case HTile:
204     res = QtxWorkspaceAction::HTile;
205     break;
206   case VTile:
207     res = QtxWorkspaceAction::VTile;
208     break;
209   }
210   return res;
211 }