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_MDIDesktop.h"
24 #include <SUIT_Session.h>
25 #include <SUIT_ViewWindow.h>
26 #include <SUIT_ResourceMgr.h>
28 #include <QtxWorkspace.h>
29 #include <QtxActionMenuMgr.h>
30 #include <QtxWorkspaceAction.h>
33 #include <QVBoxLayout>
40 STD_MDIDesktop::STD_MDIDesktop()
43 myWorkspaceAction( 0 )
45 QFrame* base = new QFrame( this );
46 QVBoxLayout* main = new QVBoxLayout( base );
48 base->setFrameStyle( QFrame::Panel | QFrame::Sunken );
50 setCentralWidget( base );
52 myWorkspace = new QtxWorkspace( base );
53 main->addWidget( myWorkspace );
55 connect( myWorkspace, SIGNAL( windowActivated( QWidget* ) ),
56 this, SLOT( onWindowActivated( QWidget* ) ) );
64 STD_MDIDesktop::~STD_MDIDesktop()
69 \retval SUIT_ViewWindow - return const active window.
71 SUIT_ViewWindow* STD_MDIDesktop::activeWindow() const
73 SUIT_ViewWindow* wnd = 0;
75 QWidget* wid = myWorkspace->activeWindow();
76 if ( wid && wid->inherits( "SUIT_ViewWindow" ) )
77 wnd = (SUIT_ViewWindow*)wid;
83 \retval QList<SUIT_ViewWindow> - return const active window list.
85 QList<SUIT_ViewWindow*> STD_MDIDesktop::windows() const
87 QList<SUIT_ViewWindow*> winList;
89 QWidgetList children = myWorkspace->windowList();
90 for ( QWidgetList::iterator it = children.begin(); it != children.end(); ++it )
92 SUIT_ViewWindow* vw = ::qobject_cast<SUIT_ViewWindow*>( *it );
101 Add the new widget into desktop.
103 void STD_MDIDesktop::addWindow( QWidget* w )
105 if ( !w || !workspace() )
108 workspace()->addWindow( w );
111 /*!Call method perform for operation \a type.*/
112 void STD_MDIDesktop::windowOperation( const int type )
114 myWorkspaceAction->perform( operationFlag( type ) );
117 /*!Sets window operations by \a first ... parameters.*/
118 void STD_MDIDesktop::setWindowOperations( const int first, ... )
121 va_start( ints, first );
128 typeList.append( cur );
129 cur = va_arg( ints, int );
132 setWindowOperations( typeList );
135 /*!Sets window operations by variable \a opList - operation list.*/
136 void STD_MDIDesktop::setWindowOperations( const QList<int>& opList )
140 for ( QList<int>::const_iterator it = opList.begin(); it != opList.end(); ++it )
141 flags = flags | operationFlag( *it );
143 myWorkspaceAction->setMenuActions( flags );
147 \retval QtxWorkspace pointer - work space.
149 QtxWorkspace* STD_MDIDesktop::workspace() const
155 Emit window activated.
157 void STD_MDIDesktop::onWindowActivated( QWidget* w )
159 if ( w && w->inherits( "SUIT_ViewWindow" ) )
160 emit windowActivated( (SUIT_ViewWindow*)w );
164 Create actions: cascade, Tile, Tile Horizontal, Tile Vertical
166 void STD_MDIDesktop::createActions()
168 if ( myWorkspaceAction )
171 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
175 myWorkspaceAction = new QtxWorkspaceAction( workspace(), this );
177 myWorkspaceAction->setMenuActions( QtxWorkspaceAction::Cascade | QtxWorkspaceAction::Tile |
178 QtxWorkspaceAction::HTile | QtxWorkspaceAction::VTile |
179 QtxWorkspaceAction::Windows );
182 myWorkspaceAction->setIcon( QtxWorkspaceAction::Cascade,
183 resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_CASCADE" ) ) );
184 myWorkspaceAction->setText( QtxWorkspaceAction::Cascade, tr( "MEN_DESK_WINDOW_CASCADE" ) );
185 myWorkspaceAction->setStatusTip( QtxWorkspaceAction::Cascade, tr( "PRP_DESK_WINDOW_CASCADE" ) );
188 myWorkspaceAction->setIcon( QtxWorkspaceAction::Tile,
189 resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_TILE" ) ) );
190 myWorkspaceAction->setText( QtxWorkspaceAction::Tile, tr( "MEN_DESK_WINDOW_TILE" ) );
191 myWorkspaceAction->setStatusTip( QtxWorkspaceAction::Tile, tr( "PRP_DESK_WINDOW_TILE" ) );
194 myWorkspaceAction->setIcon( QtxWorkspaceAction::HTile,
195 resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_HTILE" ) ) );
196 myWorkspaceAction->setText( QtxWorkspaceAction::HTile, tr( "MEN_DESK_WINDOW_HTILE" ) );
197 myWorkspaceAction->setStatusTip( QtxWorkspaceAction::HTile, tr( "PRP_DESK_WINDOW_HTILE" ) );
200 myWorkspaceAction->setIcon( QtxWorkspaceAction::VTile,
201 resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_VTILE" ) ) );
202 myWorkspaceAction->setText( QtxWorkspaceAction::VTile, tr( "MEN_DESK_WINDOW_VTILE" ) );
203 myWorkspaceAction->setStatusTip( QtxWorkspaceAction::VTile, tr( "PRP_DESK_WINDOW_VTILE" ) );
205 QtxActionMenuMgr* mMgr = menuMgr();
209 int winMenuId = mMgr->insert( tr( "MEN_DESK_WINDOW" ), -1, 100 );
210 mMgr->insert( myWorkspaceAction, winMenuId, -1 );
211 mMgr->insert( QtxActionMenuMgr::separator(), winMenuId, -1 );
214 /*!Convert STD_MDIDesktop enumerations to QtxWorkspaceAction.*/
215 int STD_MDIDesktop::operationFlag( const int type ) const
221 res = QtxWorkspaceAction::Cascade;
224 res = QtxWorkspaceAction::Tile;
227 res = QtxWorkspaceAction::HTile;
230 res = QtxWorkspaceAction::VTile;