1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "STD_TabDesktop.h"
24 #include <SUIT_Session.h>
25 #include <SUIT_ViewWindow.h>
26 #include <SUIT_ResourceMgr.h>
28 #include <QtxWorkstack.h>
29 #include <QtxActionMenuMgr.h>
30 #include <QtxWorkstackAction.h>
33 #include <QVBoxLayout>
37 /*!Constructor.Create new instances of QVBox and QtxWorkstack.*/
38 STD_TabDesktop::STD_TabDesktop()
41 myWorkstackAction( 0 )
43 QFrame* base = new QFrame( this );
44 base->setFrameStyle( QFrame::Panel | QFrame::Sunken );
46 QVBoxLayout* main = new QVBoxLayout( base );
49 setCentralWidget( base );
51 myWorkstack = new QtxWorkstack( base );
52 main->addWidget( myWorkstack );
53 // setting Expanding size policy for central workstack. If there are several widgets
54 // in central area of Desktop, other widgets will be added below the workstack (CATHARE, TRIPOLI modules).
55 // But the workstack must occupy as much space as possible -- set Expanding for it.
56 myWorkstack->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
58 myWorkstack->setAccel( QtxWorkstack::SplitVertical, Qt::SHIFT + Qt::Key_V );
59 myWorkstack->setAccel( QtxWorkstack::SplitHorizontal, Qt::SHIFT + Qt::Key_H );
60 myWorkstack->setAccel( QtxWorkstack::Close, Qt::SHIFT + Qt::Key_C );
62 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
64 myWorkstack->setIcon( QtxWorkstack::SplitVertical,
65 resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_VSPLIT" ) ) );
66 myWorkstack->setIcon( QtxWorkstack::SplitHorizontal,
67 resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_HSPLIT" ) ) );
68 myWorkstack->setIcon( QtxWorkstack::Close,
69 resMgr->loadPixmap( "STD", tr( "ICON_FILE_CLOSE" ) ));
72 connect( myWorkstack, SIGNAL( windowActivated( QWidget* ) ),
73 this, SLOT( onWindowActivated( QWidget* ) ) );
81 STD_TabDesktop::~STD_TabDesktop()
86 \retval SUIT_ViewWindow - return const active window.
88 SUIT_ViewWindow* STD_TabDesktop::activeWindow() const
90 SUIT_ViewWindow* wnd = 0;
92 QWidget* wid = myWorkstack->activeWindow();
93 if ( wid && wid->inherits( "SUIT_ViewWindow" ) )
94 wnd = (SUIT_ViewWindow*)wid;
100 \retval QPtrList<SUIT_ViewWindow> - return const active window list.
102 QList<SUIT_ViewWindow*> STD_TabDesktop::windows() const
104 QList<SUIT_ViewWindow*> winList;
106 QWidgetList children = myWorkstack->windowList();
107 for ( QWidgetList::iterator it = children.begin(); it != children.end(); ++it )
109 if ( (*it)->inherits( "SUIT_ViewWindow" ) )
110 winList.append( (SUIT_ViewWindow*)*it );
117 Insert new widget into desktop.
119 void STD_TabDesktop::addWindow( QWidget* w )
121 if ( !w || !workstack() )
124 workstack()->addWindow( w );
128 Call method perform for operation \a type.
130 void STD_TabDesktop::windowOperation( const int type )
132 myWorkstackAction->perform( operationFlag( type ) );
136 Sets window operations by \a first ... parameters.
138 void STD_TabDesktop::setWindowOperations( const int first, ... )
141 va_start( ints, first );
148 typeList.append( cur );
149 cur = va_arg( ints, int );
152 setWindowOperations( typeList );
156 Sets window operations by variable \a opList - operation list.
158 void STD_TabDesktop::setWindowOperations( const QList<int>& opList )
162 for ( QList<int>::const_iterator it = opList.begin(); it != opList.end(); ++it )
163 flags = flags | operationFlag( *it );
165 // myWorkstackAction->setItems( flags );
169 \retval QtxWorkstack pointer - Qt work stack.
171 QtxWorkstack* STD_TabDesktop::workstack() const
177 Emit window activated.
179 void STD_TabDesktop::onWindowActivated( QWidget* w )
181 if ( w && w->inherits( "SUIT_ViewWindow" ) )
182 emit windowActivated( (SUIT_ViewWindow*)w );
186 Create actions for window.
188 void STD_TabDesktop::createActions()
190 if ( myWorkstackAction )
193 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
197 myWorkstackAction = new QtxWorkstackAction( workstack(), this );
199 myWorkstackAction->setMenuActions( QtxWorkstackAction::Split | QtxWorkstackAction::Windows );
202 myWorkstackAction->setIcon( QtxWorkstackAction::SplitHorizontal,
203 resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_HSPLIT" ) ) );
204 myWorkstackAction->setText( QtxWorkstackAction::SplitHorizontal, tr( "MEN_DESK_WINDOW_HSPLIT" ) );
205 myWorkstackAction->setStatusTip( QtxWorkstackAction::SplitHorizontal, tr( "PRP_DESK_WINDOW_HSPLIT" ) );
206 myWorkstackAction->setAccel( QtxWorkstackAction::SplitHorizontal, Qt::SHIFT + Qt::Key_H );
209 myWorkstackAction->setIcon( QtxWorkstackAction::SplitVertical,
210 resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_VSPLIT" ) ) );
211 myWorkstackAction->setText( QtxWorkstackAction::SplitVertical, tr( "MEN_DESK_WINDOW_VSPLIT" ) );
212 myWorkstackAction->setStatusTip( QtxWorkstackAction::SplitVertical, tr( "PRP_DESK_WINDOW_VSPLIT" ) );
213 myWorkstackAction->setAccel( QtxWorkstackAction::SplitVertical, Qt::SHIFT + Qt::Key_V );
215 QtxActionMenuMgr* mMgr = menuMgr();
219 int winMenuId = mMgr->insert( tr( "MEN_DESK_WINDOW" ), -1, 100 );
220 mMgr->insert( myWorkstackAction, winMenuId, -1 );
221 mMgr->insert( QtxActionMenuMgr::separator(), winMenuId, -1 );
225 Convert STD_TabDesktop enumerations to QtxWorkstackAction
227 int STD_TabDesktop::operationFlag( const int type ) const
233 res = QtxWorkstackAction::SplitVertical;
235 case SplitHorizontal:
236 res = QtxWorkstackAction::SplitHorizontal;