1 // Copyright (C) 2007-2013 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
23 #include "STD_TabDesktop.h"
25 #include <SUIT_Session.h>
26 #include <SUIT_ViewWindow.h>
27 #include <SUIT_ResourceMgr.h>
29 #include <QtxWorkstack.h>
30 #include <QtxActionMenuMgr.h>
31 #include <QtxWorkstackAction.h>
34 #include <QVBoxLayout>
38 /*!Constructor.Create new instances of QVBox and QtxWorkstack.*/
39 STD_TabDesktop::STD_TabDesktop()
42 myWorkstackAction( 0 )
44 QFrame* base = new QFrame( this );
45 base->setFrameStyle( QFrame::Panel | QFrame::Sunken );
47 QVBoxLayout* main = new QVBoxLayout( base );
50 setCentralWidget( base );
52 myWorkstack = new QtxWorkstack( base );
53 main->addWidget( myWorkstack );
54 // setting Expanding size policy for central workstack. If there are several widgets
55 // in central area of Desktop, other widgets will be added below the workstack (CATHARE, TRIPOLI modules).
56 // But the workstack must occupy as much space as possible -- set Expanding for it.
57 myWorkstack->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
59 myWorkstack->setAccel( QtxWorkstack::SplitVertical, Qt::ALT + Qt::SHIFT + Qt::Key_V );
60 myWorkstack->setAccel( QtxWorkstack::SplitHorizontal, Qt::ALT + Qt::SHIFT + Qt::Key_H );
61 //myWorkstack->setAccel( QtxWorkstack::Close, Qt::CTRL + Qt::Key_F4 );
63 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
65 myWorkstack->setIcon( QtxWorkstack::SplitVertical,
66 resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_VSPLIT" ) ) );
67 myWorkstack->setIcon( QtxWorkstack::SplitHorizontal,
68 resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_HSPLIT" ) ) );
69 myWorkstack->setIcon( QtxWorkstack::Close,
70 resMgr->loadPixmap( "STD", tr( "ICON_FILE_CLOSE" ) ));
73 connect( myWorkstack, SIGNAL( windowActivated( QWidget* ) ),
74 this, SLOT( onWindowActivated( QWidget* ) ) );
82 STD_TabDesktop::~STD_TabDesktop()
87 \retval SUIT_ViewWindow - return const active window.
89 SUIT_ViewWindow* STD_TabDesktop::activeWindow() const
91 SUIT_ViewWindow* wnd = 0;
93 QWidget* wid = myWorkstack->activeWindow();
94 if ( wid && wid->inherits( "SUIT_ViewWindow" ) )
95 wnd = (SUIT_ViewWindow*)wid;
101 \retval QPtrList<SUIT_ViewWindow> - return const active window list.
103 QList<SUIT_ViewWindow*> STD_TabDesktop::windows() const
105 QList<SUIT_ViewWindow*> winList;
107 QWidgetList children = myWorkstack->windowList();
108 for ( QWidgetList::iterator it = children.begin(); it != children.end(); ++it )
110 if ( (*it)->inherits( "SUIT_ViewWindow" ) )
111 winList.append( (SUIT_ViewWindow*)*it );
118 Insert new widget into desktop.
120 void STD_TabDesktop::addWindow( QWidget* w )
122 if ( !w || !workstack() )
125 workstack()->addWindow( w );
129 Call method perform for operation \a type.
131 void STD_TabDesktop::windowOperation( const int type )
133 myWorkstackAction->perform( operationFlag( type ) );
137 Sets window operations by \a first ... parameters.
139 void STD_TabDesktop::setWindowOperations( const int first, ... )
142 va_start( ints, first );
149 typeList.append( cur );
150 cur = va_arg( ints, int );
153 setWindowOperations( typeList );
157 Sets window operations by variable \a opList - operation list.
159 void STD_TabDesktop::setWindowOperations( const QList<int>& opList )
163 for ( QList<int>::const_iterator it = opList.begin(); it != opList.end(); ++it )
164 flags = flags | operationFlag( *it );
166 // myWorkstackAction->setItems( flags );
170 \retval QtxWorkstack pointer - Qt work stack.
172 QtxWorkstack* STD_TabDesktop::workstack() const
178 Emit window activated.
180 void STD_TabDesktop::onWindowActivated( QWidget* w )
182 if ( w && w->inherits( "SUIT_ViewWindow" ) )
183 emit windowActivated( (SUIT_ViewWindow*)w );
187 Create actions for window.
189 void STD_TabDesktop::createActions()
191 if ( myWorkstackAction )
194 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
198 myWorkstackAction = new QtxWorkstackAction( workstack(), this );
200 myWorkstackAction->setMenuActions( QtxWorkstackAction::Split | QtxWorkstackAction::Windows );
203 myWorkstackAction->setIcon( QtxWorkstackAction::SplitHorizontal,
204 resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_HSPLIT" ) ) );
205 myWorkstackAction->setText( QtxWorkstackAction::SplitHorizontal, tr( "MEN_DESK_WINDOW_HSPLIT" ) );
206 myWorkstackAction->setStatusTip( QtxWorkstackAction::SplitHorizontal, tr( "PRP_DESK_WINDOW_HSPLIT" ) );
207 myWorkstackAction->setAccel( QtxWorkstackAction::SplitHorizontal, Qt::ALT + Qt::SHIFT + Qt::Key_H );
210 myWorkstackAction->setIcon( QtxWorkstackAction::SplitVertical,
211 resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_VSPLIT" ) ) );
212 myWorkstackAction->setText( QtxWorkstackAction::SplitVertical, tr( "MEN_DESK_WINDOW_VSPLIT" ) );
213 myWorkstackAction->setStatusTip( QtxWorkstackAction::SplitVertical, tr( "PRP_DESK_WINDOW_VSPLIT" ) );
214 myWorkstackAction->setAccel( QtxWorkstackAction::SplitVertical, Qt::ALT + Qt::SHIFT + Qt::Key_V );
216 QAction* anArrangeViewsAction = myWorkstackAction->getArrangeViewsAction();
217 if( anArrangeViewsAction )
218 connect( anArrangeViewsAction, SIGNAL( triggered() ), this, SLOT( onArrangeViews() ) );
220 QtxActionMenuMgr* mMgr = menuMgr();
224 int winMenuId = mMgr->insert( tr( "MEN_DESK_WINDOW" ), -1, 100 );
225 mMgr->insert( anArrangeViewsAction, winMenuId, -1 );
226 mMgr->insert( myWorkstackAction, winMenuId, -1 );
227 mMgr->insert( QtxActionMenuMgr::separator(), winMenuId, -1 );
231 Emit Arrange Views menu activated.
233 void STD_TabDesktop::onArrangeViews()
235 QtxSplitDlg ArrangeViewsDlg( this, workstack(), ArrangeViews );
236 ArrangeViewsDlg.exec();
240 Convert STD_TabDesktop enumerations to QtxWorkstackAction
242 int STD_TabDesktop::operationFlag( const int type ) const
248 res = QtxWorkstackAction::SplitVertical;
250 case SplitHorizontal:
251 res = QtxWorkstackAction::SplitHorizontal;