Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[modules/gui.git] / src / STD / STD_TabDesktop.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/
18 //
19 #include "STD_TabDesktop.h"
20
21 #include <SUIT_Session.h>
22 #include <SUIT_ViewWindow.h>
23 #include <SUIT_ResourceMgr.h>
24
25 #include <QtxAction.h>
26 #include <QtxWorkstack.h>
27 #include <QtxActionMenuMgr.h>
28 #include <QtxWorkstackAction.h>
29
30 #include <qvbox.h>
31 #include <qmenubar.h>
32 #include <qworkspace.h>
33 #include <qobjectlist.h>
34
35 #include <stdarg.h>
36
37 /*!Constructor.Create new instances of QVBox and QtxWorkstack.*/
38 STD_TabDesktop::STD_TabDesktop()
39 : SUIT_Desktop(),
40 myWorkstack( 0 ),
41 myWorkstackAction( 0 )
42 {
43   QVBox* base = new QVBox( this );
44   base->setFrameStyle( QFrame::Panel | QFrame::Sunken );
45
46   setCentralWidget( base );
47
48   myWorkstack = new QtxWorkstack( base );
49   // setting Expanding size policy for central workstack.  If there are several widgets
50   // in central area of Desktop, other widgets will be added below the workstack (CATHARE, TRIPOLI modules).  
51   // But the workstack must occupy as much space as possible -- set Expanding for it.
52   myWorkstack->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
53
54   myWorkstack->setAccel(QtxWorkstack::SplitVertical,   SHIFT + Key_V);
55   myWorkstack->setAccel(QtxWorkstack::SplitHorizontal, SHIFT + Key_H);
56   myWorkstack->setAccel(QtxWorkstack::Close,           SHIFT + Key_C);
57
58   connect( myWorkstack, SIGNAL( windowActivated( QWidget* ) ),
59            this, SLOT( onWindowActivated( QWidget* ) ) );
60
61   createActions();
62 }
63
64 /*!Destructor.*/
65 STD_TabDesktop::~STD_TabDesktop()
66 {
67 }
68
69 /*!\retval SUIT_ViewWindow - return const active window.*/
70 SUIT_ViewWindow* STD_TabDesktop::activeWindow() const
71 {
72   SUIT_ViewWindow* wnd = 0;
73
74   QWidget* wid = myWorkstack->activeWindow();
75   if ( wid && wid->inherits( "SUIT_ViewWindow" ) )
76     wnd = (SUIT_ViewWindow*)wid;
77
78   return wnd;
79 }
80
81 /*!\retval QPtrList<SUIT_ViewWindow> - return const active window list.*/
82 QPtrList<SUIT_ViewWindow> STD_TabDesktop::windows() const
83 {
84   QPtrList<SUIT_ViewWindow> winList;
85
86   QWidgetList children = myWorkstack->windowList();
87   for ( QWidgetListIt it( children ); it.current(); ++it )
88   {
89     if ( it.current()->inherits( "SUIT_ViewWindow" ) )
90       winList.append( (SUIT_ViewWindow*)it.current() );
91   }
92
93   return winList;
94 }
95
96 /*!\retval QWidget pointer - QT work stack.*/
97 QWidget* STD_TabDesktop::parentArea() const
98 {
99   return workstack();
100 }
101
102 /*!Call method perform for operation \a type.*/
103 void STD_TabDesktop::windowOperation( const int type )
104 {
105   myWorkstackAction->perform( operationFlag( type ) );
106 }
107
108 /*!Sets window operations by \a first ... parameters.*/
109 void STD_TabDesktop::setWindowOperations( const int first, ... )
110 {
111   va_list ints;
112         va_start( ints, first );
113
114         QValueList<int> typeList;
115
116         int cur = first;
117         while ( cur )
118         {
119           typeList.append( cur );
120                 cur = va_arg( ints, int );
121   }
122
123         setWindowOperations( typeList );
124 }
125
126 /*!Sets window operations by variable \a opList - operation list.*/
127 void STD_TabDesktop::setWindowOperations( const QValueList<int>& opList )
128 {
129   int flags = 0;
130
131   for ( QValueList<int>::const_iterator it = opList.begin(); it != opList.end(); ++it )
132     flags = flags | operationFlag( *it );
133
134   myWorkstackAction->setItems( flags );
135 }
136
137 /*!\retval QtxWorkstack pointer - QT work stack.*/
138 QtxWorkstack* STD_TabDesktop::workstack() const
139 {
140   return myWorkstack;
141 }
142
143 /*!Emit window activated.*/
144 void STD_TabDesktop::onWindowActivated( QWidget* w )
145 {
146   if ( w && w->inherits( "SUIT_ViewWindow" ) )
147     emit windowActivated( (SUIT_ViewWindow*)w );
148 }
149
150 /*!Create actions for window.*/
151 void STD_TabDesktop::createActions()
152 {
153   if ( myWorkstackAction )
154     return;
155
156   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
157   if ( !resMgr )
158     return;
159
160   myWorkstackAction = new QtxWorkstackAction( workstack(), this );
161
162   myWorkstackAction->setItems( QtxWorkstackAction::Split | QtxWorkstackAction::Windows );
163
164   // Split Horizontal
165   myWorkstackAction->setIconSet( QtxWorkstackAction::HSplit,
166                                  resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_HSPLIT" ) ) );
167   myWorkstackAction->setMenuText( QtxWorkstackAction::HSplit, tr( "MEN_DESK_WINDOW_HSPLIT" ) );
168   myWorkstackAction->setStatusTip( QtxWorkstackAction::HSplit, tr( "PRP_DESK_WINDOW_HSPLIT" ) );
169
170   // Split Vertical
171   myWorkstackAction->setIconSet( QtxWorkstackAction::VSplit,
172                                  resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_VSPLIT" ) ) );
173   myWorkstackAction->setMenuText( QtxWorkstackAction::VSplit, tr( "MEN_DESK_WINDOW_VSPLIT" ) );
174   myWorkstackAction->setStatusTip( QtxWorkstackAction::VSplit, tr( "PRP_DESK_WINDOW_VSPLIT" ) );
175
176   QtxActionMenuMgr* mMgr = menuMgr();
177   if ( !mMgr )
178     return;
179
180   int winMenuId = mMgr->insert( tr( "MEN_DESK_WINDOW" ), -1, 100, MenuWindowId );
181   mMgr->insert( myWorkstackAction, winMenuId, -1 );
182   mMgr->insert( QtxActionMenuMgr::separator(), winMenuId, -1 );
183 }
184
185 /*!Convert STD_TabDesktop enumerations to QtxWorkstackAction*/
186 int STD_TabDesktop::operationFlag( const int type ) const
187 {
188   int res = 0;
189   switch ( type )
190   {
191   case VSplit:
192     res = QtxWorkstackAction::VSplit;
193     break;
194   case HSplit:
195     res = QtxWorkstackAction::HSplit;
196     break;
197   }
198   return res;
199 }