Salome HOME
no message
[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
32   myWorkstack->setAccel(QtxWorkstack::SplitVertical,   SHIFT + Key_V);
33   myWorkstack->setAccel(QtxWorkstack::SplitHorizontal, SHIFT + Key_H);
34   myWorkstack->setAccel(QtxWorkstack::Close,           SHIFT + Key_C);
35
36   connect( myWorkstack, SIGNAL( windowActivated( QWidget* ) ),
37            this, SLOT( onWindowActivated( QWidget* ) ) );
38
39   createActions();
40 }
41
42 /*!Destructor.*/
43 STD_TabDesktop::~STD_TabDesktop()
44 {
45 }
46
47 /*!\retval SUIT_ViewWindow - return const active window.*/
48 SUIT_ViewWindow* STD_TabDesktop::activeWindow() const
49 {
50   SUIT_ViewWindow* wnd = 0;
51
52   QWidget* wid = myWorkstack->activeWindow();
53   if ( wid && wid->inherits( "SUIT_ViewWindow" ) )
54     wnd = (SUIT_ViewWindow*)wid;
55
56   return wnd;
57 }
58
59 /*!\retval QPtrList<SUIT_ViewWindow> - return const active window list.*/
60 QPtrList<SUIT_ViewWindow> STD_TabDesktop::windows() const
61 {
62   QPtrList<SUIT_ViewWindow> winList;
63
64   QWidgetList children = myWorkstack->windowList();
65   for ( QWidgetListIt it( children ); it.current(); ++it )
66   {
67     if ( it.current()->inherits( "SUIT_ViewWindow" ) )
68       winList.append( (SUIT_ViewWindow*)it.current() );
69   }
70
71   return winList;
72 }
73
74 /*!\retval QWidget pointer - QT work stack.*/
75 QWidget* STD_TabDesktop::parentArea() const
76 {
77   return workstack();
78 }
79
80 /*!Call method perform for operation \a type.*/
81 void STD_TabDesktop::windowOperation( const int type )
82 {
83   myWorkstackAction->perform( operationFlag( type ) );
84 }
85
86 /*!Sets window operations by \a first ... parameters.*/
87 void STD_TabDesktop::setWindowOperations( const int first, ... )
88 {
89   va_list ints;
90         va_start( ints, first );
91
92         QValueList<int> typeList;
93
94         int cur = first;
95         while ( cur )
96         {
97           typeList.append( cur );
98                 cur = va_arg( ints, int );
99   }
100
101         setWindowOperations( typeList );
102 }
103
104 /*!Sets window operations by variable \a opList - operation list.*/
105 void STD_TabDesktop::setWindowOperations( const QValueList<int>& opList )
106 {
107   int flags = 0;
108
109   for ( QValueList<int>::const_iterator it = opList.begin(); it != opList.end(); ++it )
110     flags = flags | operationFlag( *it );
111
112   myWorkstackAction->setItems( flags );
113 }
114
115 /*!\retval QtxWorkstack pointer - QT work stack.*/
116 QtxWorkstack* STD_TabDesktop::workstack() const
117 {
118   return myWorkstack;
119 }
120
121 /*!Emit window activated.*/
122 void STD_TabDesktop::onWindowActivated( QWidget* w )
123 {
124   if ( w && w->inherits( "SUIT_ViewWindow" ) )
125     emit windowActivated( (SUIT_ViewWindow*)w );
126 }
127
128 /*!Create actions for window.*/
129 void STD_TabDesktop::createActions()
130 {
131   if ( myWorkstackAction )
132     return;
133
134   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
135   if ( !resMgr )
136     return;
137
138   myWorkstackAction = new QtxWorkstackAction( workstack(), this );
139
140   myWorkstackAction->setItems( QtxWorkstackAction::Split | QtxWorkstackAction::Windows );
141
142   // Split Horizontal
143   myWorkstackAction->setIconSet( QtxWorkstackAction::HSplit,
144                                  resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_HSPLIT" ) ) );
145   myWorkstackAction->setMenuText( QtxWorkstackAction::HSplit, tr( "MEN_DESK_WINDOW_HSPLIT" ) );
146   myWorkstackAction->setStatusTip( QtxWorkstackAction::HSplit, tr( "PRP_DESK_WINDOW_HSPLIT" ) );
147
148   // Split Vertical
149   myWorkstackAction->setIconSet( QtxWorkstackAction::VSplit,
150                                  resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_VSPLIT" ) ) );
151   myWorkstackAction->setMenuText( QtxWorkstackAction::VSplit, tr( "MEN_DESK_WINDOW_VSPLIT" ) );
152   myWorkstackAction->setStatusTip( QtxWorkstackAction::VSplit, tr( "PRP_DESK_WINDOW_VSPLIT" ) );
153
154   QtxActionMenuMgr* mMgr = menuMgr();
155   if ( !mMgr )
156     return;
157
158   int winMenuId = mMgr->insert( tr( "MEN_DESK_WINDOW" ), -1, 100 );
159   mMgr->insert( myWorkstackAction, winMenuId, -1 );
160   mMgr->insert( QtxActionMenuMgr::separator(), winMenuId, -1 );
161 }
162
163 /*!Convert STD_TabDesktop enumerations to QtxWorkstackAction*/
164 int STD_TabDesktop::operationFlag( const int type ) const
165 {
166   int res = 0;
167   switch ( type )
168   {
169   case VSplit:
170     res = QtxWorkstackAction::VSplit;
171     break;
172   case HSplit:
173     res = QtxWorkstackAction::HSplit;
174     break;
175   }
176   return res;
177 }