1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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
23 #include "STD_TabDesktop.h"
25 #include <SUIT_Session.h>
26 #include <SUIT_ViewManager.h>
27 #include <SUIT_ViewWindow.h>
28 #include <SUIT_ResourceMgr.h>
30 #include <QtxWorkstack.h>
31 #include <QtxActionMenuMgr.h>
32 #include <QtxWorkstackAction.h>
35 #include <QVBoxLayout>
39 /*!Constructor.Create new instances of QVBox and QtxWorkstack.*/
40 STD_TabDesktop::STD_TabDesktop()
43 myWorkstackAction( 0 )
45 QFrame* base = new QFrame( this );
46 base->setFrameStyle( QFrame::Panel | QFrame::Sunken );
48 QVBoxLayout* main = new QVBoxLayout( base );
51 setCentralWidget( base );
53 myWorkstack = new QtxWorkstack( base );
54 main->addWidget( myWorkstack );
55 // setting Expanding size policy for central workstack. If there are several widgets
56 // in central area of Desktop, other widgets will be added below the workstack (CATHARE, TRIPOLI modules).
57 // But the workstack must occupy as much space as possible -- set Expanding for it.
58 myWorkstack->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
60 myWorkstack->setAccel( QtxWorkstack::SplitVertical, Qt::ALT + Qt::SHIFT + Qt::Key_V );
61 myWorkstack->setAccel( QtxWorkstack::SplitHorizontal, Qt::ALT + Qt::SHIFT + Qt::Key_H );
62 //myWorkstack->setAccel( QtxWorkstack::Close, Qt::CTRL + Qt::Key_F4 );
64 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
66 myWorkstack->setIcon( QtxWorkstack::SplitVertical,
67 resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_VSPLIT" ) ) );
68 myWorkstack->setIcon( QtxWorkstack::SplitHorizontal,
69 resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_HSPLIT" ) ) );
70 myWorkstack->setIcon( QtxWorkstack::Close,
71 resMgr->loadPixmap( "STD", tr( "ICON_FILE_CLOSE" ) ));
74 connect( myWorkstack, SIGNAL( windowActivated( QWidget* ) ),
75 this, SLOT( onWindowActivated( QWidget* ) ) );
83 STD_TabDesktop::~STD_TabDesktop()
88 \retval SUIT_ViewWindow - return const active window.
90 SUIT_ViewWindow* STD_TabDesktop::activeWindow() const
92 SUIT_ViewWindow* wnd = 0;
94 QWidget* wid = myWorkstack->activeWindow();
95 if ( wid && wid->inherits( "SUIT_ViewWindow" ) )
96 wnd = (SUIT_ViewWindow*)wid;
103 \param wnd - view window
105 void STD_TabDesktop::setActiveWindow(SUIT_ViewWindow* wnd)
108 myWorkstack->setActiveWindow(wnd);
114 \retval QPtrList<SUIT_ViewWindow> - return const active window list.
116 QList<SUIT_ViewWindow*> STD_TabDesktop::windows() const
118 QList<SUIT_ViewWindow*> winList;
120 QWidgetList children = myWorkstack->windowList();
121 for ( QWidgetList::iterator it = children.begin(); it != children.end(); ++it )
123 if ( (*it)->inherits( "SUIT_ViewWindow" ) )
124 winList.append( (SUIT_ViewWindow*)*it );
131 Insert new widget into desktop.
133 void STD_TabDesktop::addWindow( QWidget* w )
135 if ( !w || !workstack() )
137 if ( w && w->inherits( "SUIT_ViewWindow" ) )
139 SUIT_ViewWindow* wid = (SUIT_ViewWindow*)w;
140 if ( wid->getViewManager()->getDetached() )
144 workstack()->addWindow( w );
148 Call method perform for operation \a type.
150 void STD_TabDesktop::windowOperation( const int type )
152 myWorkstackAction->perform( operationFlag( type ) );
156 Sets window operations by \a first ... parameters.
158 void STD_TabDesktop::setWindowOperations( const int first, ... )
161 va_start( ints, first );
168 typeList.append( cur );
169 cur = va_arg( ints, int );
172 setWindowOperations( typeList );
176 Sets window operations by variable \a opList - operation list.
178 void STD_TabDesktop::setWindowOperations( const QList<int>& opList )
182 for ( QList<int>::const_iterator it = opList.begin(); it != opList.end(); ++it )
183 flags = flags | operationFlag( *it );
185 // myWorkstackAction->setItems( flags );
189 \retval QtxWorkstack pointer - Qt work stack.
191 QtxWorkstack* STD_TabDesktop::workstack() const
197 Emit window activated.
199 void STD_TabDesktop::onWindowActivated( QWidget* w )
201 if ( w && w->inherits( "SUIT_ViewWindow" ) )
202 emit windowActivated( (SUIT_ViewWindow*)w );
206 Create actions for window.
208 void STD_TabDesktop::createActions()
210 if ( myWorkstackAction )
213 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
217 myWorkstackAction = new QtxWorkstackAction( workstack(), this );
219 myWorkstackAction->setMenuActions( QtxWorkstackAction::Split | QtxWorkstackAction::Windows );
222 myWorkstackAction->setIcon( QtxWorkstackAction::SplitHorizontal,
223 resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_HSPLIT" ) ) );
224 myWorkstackAction->setText( QtxWorkstackAction::SplitHorizontal, tr( "MEN_DESK_WINDOW_HSPLIT" ) );
225 myWorkstackAction->setStatusTip( QtxWorkstackAction::SplitHorizontal, tr( "PRP_DESK_WINDOW_HSPLIT" ) );
226 myWorkstackAction->setAccel( QtxWorkstackAction::SplitHorizontal, Qt::ALT + Qt::SHIFT + Qt::Key_H );
229 myWorkstackAction->setIcon( QtxWorkstackAction::SplitVertical,
230 resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_VSPLIT" ) ) );
231 myWorkstackAction->setText( QtxWorkstackAction::SplitVertical, tr( "MEN_DESK_WINDOW_VSPLIT" ) );
232 myWorkstackAction->setStatusTip( QtxWorkstackAction::SplitVertical, tr( "PRP_DESK_WINDOW_VSPLIT" ) );
233 myWorkstackAction->setAccel( QtxWorkstackAction::SplitVertical, Qt::ALT + Qt::SHIFT + Qt::Key_V );
235 QAction* anArrangeViewsAction = myWorkstackAction->getArrangeViewsAction();
236 if( anArrangeViewsAction )
237 connect( anArrangeViewsAction, SIGNAL( triggered() ), this, SLOT( onArrangeViews() ) );
239 QtxActionMenuMgr* mMgr = menuMgr();
243 int winMenuId = mMgr->insert( tr( "MEN_DESK_WINDOW" ), -1, 100 );
244 mMgr->insert( anArrangeViewsAction, winMenuId, -1 );
245 mMgr->insert( myWorkstackAction, winMenuId, -1 );
246 mMgr->insert( QtxActionMenuMgr::separator(), winMenuId, -1 );
250 Emit Arrange Views menu activated.
252 void STD_TabDesktop::onArrangeViews()
254 QtxSplitDlg ArrangeViewsDlg( this, workstack(), ArrangeViews );
255 ArrangeViewsDlg.exec();
259 Convert STD_TabDesktop enumerations to QtxWorkstackAction
261 int STD_TabDesktop::operationFlag( const int type ) const
267 res = QtxWorkstackAction::SplitVertical;
269 case SplitHorizontal:
270 res = QtxWorkstackAction::SplitHorizontal;