1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
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.
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.
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
17 // See http://www.salome-platform.org/
19 #include "STD_TabDesktop.h"
21 #include <SUIT_Session.h>
22 #include <SUIT_ViewWindow.h>
23 #include <SUIT_ResourceMgr.h>
25 #include <QtxAction.h>
26 #include <QtxWorkstack.h>
27 #include <QtxActionMenuMgr.h>
28 #include <QtxWorkstackAction.h>
32 #include <qworkspace.h>
33 #include <qobjectlist.h>
37 /*!Constructor.Create new instances of QVBox and QtxWorkstack.*/
38 STD_TabDesktop::STD_TabDesktop()
41 myWorkstackAction( 0 )
43 QVBox* base = new QVBox( this );
44 base->setFrameStyle( QFrame::Panel | QFrame::Sunken );
46 setCentralWidget( base );
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, TIRPOLI modules).
51 // But the workstack must occupy as much space as possible -- set Expanding for it.
52 myWorkstack->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
54 myWorkstack->setAccel(QtxWorkstack::SplitVertical, SHIFT + Key_V);
55 myWorkstack->setAccel(QtxWorkstack::SplitHorizontal, SHIFT + Key_H);
56 myWorkstack->setAccel(QtxWorkstack::Close, SHIFT + Key_C);
58 connect( myWorkstack, SIGNAL( windowActivated( QWidget* ) ),
59 this, SLOT( onWindowActivated( QWidget* ) ) );
65 STD_TabDesktop::~STD_TabDesktop()
69 /*!\retval SUIT_ViewWindow - return const active window.*/
70 SUIT_ViewWindow* STD_TabDesktop::activeWindow() const
72 SUIT_ViewWindow* wnd = 0;
74 QWidget* wid = myWorkstack->activeWindow();
75 if ( wid && wid->inherits( "SUIT_ViewWindow" ) )
76 wnd = (SUIT_ViewWindow*)wid;
81 /*!\retval QPtrList<SUIT_ViewWindow> - return const active window list.*/
82 QPtrList<SUIT_ViewWindow> STD_TabDesktop::windows() const
84 QPtrList<SUIT_ViewWindow> winList;
86 QWidgetList children = myWorkstack->windowList();
87 for ( QWidgetListIt it( children ); it.current(); ++it )
89 if ( it.current()->inherits( "SUIT_ViewWindow" ) )
90 winList.append( (SUIT_ViewWindow*)it.current() );
96 /*!\retval QWidget pointer - QT work stack.*/
97 QWidget* STD_TabDesktop::parentArea() const
102 /*!Call method perform for operation \a type.*/
103 void STD_TabDesktop::windowOperation( const int type )
105 myWorkstackAction->perform( operationFlag( type ) );
108 /*!Sets window operations by \a first ... parameters.*/
109 void STD_TabDesktop::setWindowOperations( const int first, ... )
112 va_start( ints, first );
114 QValueList<int> typeList;
119 typeList.append( cur );
120 cur = va_arg( ints, int );
123 setWindowOperations( typeList );
126 /*!Sets window operations by variable \a opList - operation list.*/
127 void STD_TabDesktop::setWindowOperations( const QValueList<int>& opList )
131 for ( QValueList<int>::const_iterator it = opList.begin(); it != opList.end(); ++it )
132 flags = flags | operationFlag( *it );
134 myWorkstackAction->setItems( flags );
137 /*!\retval QtxWorkstack pointer - QT work stack.*/
138 QtxWorkstack* STD_TabDesktop::workstack() const
143 /*!Emit window activated.*/
144 void STD_TabDesktop::onWindowActivated( QWidget* w )
146 if ( w && w->inherits( "SUIT_ViewWindow" ) )
147 emit windowActivated( (SUIT_ViewWindow*)w );
150 /*!Create actions for window.*/
151 void STD_TabDesktop::createActions()
153 if ( myWorkstackAction )
156 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
160 myWorkstackAction = new QtxWorkstackAction( workstack(), this );
162 myWorkstackAction->setItems( QtxWorkstackAction::Split | QtxWorkstackAction::Windows );
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" ) );
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" ) );
176 QtxActionMenuMgr* mMgr = menuMgr();
180 int winMenuId = mMgr->insert( tr( "MEN_DESK_WINDOW" ), -1, 100 );
181 mMgr->insert( myWorkstackAction, winMenuId, -1 );
182 mMgr->insert( QtxActionMenuMgr::separator(), winMenuId, -1 );
185 /*!Convert STD_TabDesktop enumerations to QtxWorkstackAction*/
186 int STD_TabDesktop::operationFlag( const int type ) const
192 res = QtxWorkstackAction::VSplit;
195 res = QtxWorkstackAction::HSplit;