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